Hexo site sitemap automation with hexo-generator-sitemap
I have been looking for a good solution for automating the process of maintaining my sitemap with my hexo site. As I keep adding more content, and the site continues to grow, having a sitemap is going to just become yet even more important than it is to begin with. I have written a post on sitemaps before a few days ago, but I just cover what they are, and why they are important, and how to put one together manually. In this post I will write about the current solution I am using to automate the process of maintaining a sitemap called hexo-generator-sitemap.
I assume you are node competent, and are using hexo as your static site generator, in which case you just need to know this then.
Yes I saved it as a dependency of my hexo site source project, and as such it will be in my hidden node_modules folder of the hexo site working tree. Once installed I just need to add a few lines to my _config.yml file, and then I am ready to start work on the template xml file.
What to add to the main hexo _config.yml
I just placed this at the bottom of the main _config.yml file that should be at the root level of the hexo working tree.
As you may have guessed yes the sitemap will be called sitemap.xml, and yes it will be at the root namespace of the site build in the public folder when you generate your site. Before doing so you will want a template file the location of which in this example is placed in the root name space of the hexo project.
The template file
Here is the example template given at the github page of the project.
That is all, from now on an up to date sitemap should show up in the public folder every time your site is generated. The only big concern is seeing that the map is properly submitted, or resubmitted each time when updating the site. There is also the problem of reaching a limit if the site grows big enough, but I don’t see myself writing fifty thousand blog posts any time soon, so I think I’m good.
Be sure to check out my other posts on hexo