Skip to content

Commit

Permalink
small addition of tags and categories + home page
Browse files Browse the repository at this point in the history
  • Loading branch information
achauvinhameau committed Aug 19, 2017
1 parent a45bedd commit cb5dfeb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ You can configure this plugin in `_config.yml`.
sitemap:
path: sitemap.xml
template: ./sitemap_template.xml
tags: true
categories: true
```
- **path** - Sitemap path. (Default: sitemap.xml)
- **template** - Custom template path. This file will be used to generate sitemap.xml (See [default template](/sitemap.xml))
- **tags** - create tags url in the sitemap template
- **categories** - create categories url in the sitemap template
## Excluding Posts
Expand Down
21 changes: 18 additions & 3 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,25 @@ module.exports = function(locals) {
return b.updated - a.updated;
});

var xml = template(config).render({
// configuration dictionary
var xml_config = {
config: config,
posts: posts
});
posts: posts,
// add the sNow variable for creation of the home page and potential tags/cats
sNow: new Date().toISOString()
};

// add tags array available in the template
if (config.sitemap.tags != false) {
xml_config['tags'] = locals.tags.toArray();
}

// add categories available in the template
if (config.sitemap.categories != false) {
xml_config['categories'] = locals.categories.toArray();
}

var xml = template(config).render(xml_config);

return {
path: config.sitemap.path,
Expand Down
29 changes: 29 additions & 0 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,33 @@
{% endif %}
</url>
{% endfor %}

{# ------------- home page - with now date #}
<url>
<loc>{{ config.url }}</loc>
<lastmod>{{ sNow }}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>

{# ------------- tag pages #}
{% for tag in tags %}
<url>
<loc>{{ tag.permalink }}</loc>
<lastmod>{{ sNow }}</lastmod>
<changefreq>daily</changefreq>
<priority>0.6</priority>
</url>
{% endfor %}

{# ------------- categories pages #}
{% for cat in categories %}
<url>
<loc>{{ cat.permalink }}</loc>
<lastmod>{{ sNow }}</lastmod>
<changefreq>daily</changefreq>
<priority>0.6</priority>
</url>
{% endfor %}

</urlset>

0 comments on commit cb5dfeb

Please sign in to comment.