Skip to content

Commit

Permalink
Add undocumented option additionalUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoviclefevrehubstairs committed Nov 19, 2020
1 parent 6d30611 commit e609583
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ const seoFriendlySitemap = function(locals) {
render = require('./render')(locals, config),
sitemaps = _.concat(posts.get(), pages.get(), categories.get(), tags.get(), xsl.get())

if (config.sitemap.additionalUrl) {
sitemaps.push(
Promise.resolve({
filename: config.sitemap.additionalUrl.filename,
lastModification: config.sitemap.additionalUrl.lastModification,
isInIndexSitemap: true
})
)
}

return Promise.all(sitemaps)
.filter(common.isDefined)
.then(indexSitemap.get)
Expand Down
1 change: 1 addition & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const render = function(locals, config) {
}

const renderSitemaps = function(sitemap) {
if (!sitemap.template) return
const templateFilePath = path.join(viewPath, sitemap.template)
return Promise.join(sitemap, templateFilePath, common.getFileContent(templateFilePath), getCompiledContent)
}
Expand Down
6 changes: 5 additions & 1 deletion test/allSitemaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ describe('SEO-friendly sitemap generator: All Sitemaps', function() {
it('should generate all sitemap files if posts, pages, categories and tags are defined', function() {
hexo.config.sitemap = {
path: 'sitemap.xml',
beautify: false
beautify: false,
additionalUrl: {
filename: 'web-story-sitemap.xml',
lastModification: moment.utc([2014, 11, 10, 9]).toDate()
}
}

const expectedDirectory = path.join(__dirname, 'expected'),
Expand Down
5 changes: 5 additions & 0 deletions test/expected/full-index-sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
<lastmod>2015-01-01T08:00:00.000Z</lastmod>
</sitemap>

<sitemap>
<loc>http://yoursite.com/web-story-sitemap.xml</loc>
<lastmod>2014-12-10T09:00:00.000Z</lastmod>
</sitemap>

</sitemapindex>
<!-- XML Sitemap generated by Hexo SEO Friendly Sitemap Generator -->
2 changes: 1 addition & 1 deletion test/splittedPostSitemaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('SEO-friendly sitemap generator: All Sitemaps with splitted post sitema
expectedTagSitemap = fs.readFileAsync(expectedTagFilePath, readFileOptions),
checkAssertions = function(result) {
expect(Array.isArray(result)).toBe(true)
console.log('caca', result)

const indexSitemap = _.find(result, { path: 'sitemap.xml' }),
postSitemap = _.find(result, { path: 'post-sitemap-1.xml' }),
pageSitemap = _.find(result, { path: 'page-sitemap.xml' }),
Expand Down

0 comments on commit e609583

Please # to comment.