Ever wondered how to omit the file name part from the URL or how to have folder base navigation while making a micro/static site?
To do this we will have to create a folder name same as the file and then create a index.html or default.html file in it. But it is a boring process to create folder with the same name of the file and then create index file in each folder.
‘grunt-assemble-permalinks‘ is a plugin for Grunt which helps to create folder based navigation, please see below the code which create a folder name from a file’s name and rename the file’s name to index.html
plugins: ['grunt-assemble-permalinks'], // This is the plugin to use for folder structure navigation
Value of Structure in the
permalinks objects do the magic and create a path as we need.
- :year — will get the current year
- :month — will get the current month
- :basename — will get the .hbs file name and create a folder with the name and rename the .hbs file with index and copy it in the folder.
We can add/remove or manipulate the value to get the desired structure and the plugin will work as required.
I have used Grunt Task Manager for this sample but you can use gulp or yeoman as well and use the
grunt-assemble-permalinks plugin to create your own desired permalinks.
Hope this helps!
Do let me know what you think about this article in comment box below.
Originally published at ashishuideveloper.in on December 26, 2017.