mirror of https://gitlab.com/curben/blog
fix(sitemap): use post.lastUpdated
* post.updated = execution time of 'hexo generate' * use moment.format() instead of Date.toISOString() to avoid timezone conversion - Use '[T00:00:00.000Z]' to ignore time, instead of '[T]HH:mm:ss.sss[Z]' - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
This commit is contained in:
parent
fba0d3deab
commit
8717b52283
|
@ -3,10 +3,10 @@
|
|||
{% for post in posts %}
|
||||
<url>
|
||||
<loc>{{ post.permalink | uriencode }}</loc>
|
||||
{% if post.updated %}
|
||||
<lastmod>{{ post.updated.toISOString() }}</lastmod>
|
||||
{% if post.lastUpdated() %}
|
||||
<lastmod>{{ post.lastUpdated() }}</lastmod>
|
||||
{% elif post.date %}
|
||||
<lastmod>{{ post.date.toISOString() }}</lastmod>
|
||||
<lastmod>{{ post.date }}</lastmod>
|
||||
{% endif %}
|
||||
</url>
|
||||
{% endfor %}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const nanomatch = require('nanomatch')
|
||||
const template = require('./template')
|
||||
const moment = require('moment')
|
||||
|
||||
module.exports = function (locals) {
|
||||
const config = this.config
|
||||
|
@ -18,11 +19,16 @@ module.exports = function (locals) {
|
|||
return post.sitemap !== false && !isMatch(post.source, skipRenderList)
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return b.updated - a.updated
|
||||
return b.date - a.date
|
||||
})
|
||||
.map((post) => ({
|
||||
...post,
|
||||
permalink: post.permalink.replace('index.html', '')
|
||||
permalink: post.permalink.replace('index.html', ''),
|
||||
date: moment(post.date).format('YYYY-MM-DD[T00:00:00.000Z]'),
|
||||
lastUpdated: () => {
|
||||
if (post.lastUpdated) return moment(post.lastUpdated).format('YYYY-MM-DD[T00:00:00.000Z]')
|
||||
else return false
|
||||
}
|
||||
}))
|
||||
|
||||
// configuration dictionary
|
||||
|
@ -30,7 +36,7 @@ module.exports = function (locals) {
|
|||
config: config,
|
||||
posts: posts,
|
||||
// add the sNow variable for creation of the home page and potential tags/cats
|
||||
sNow: new Date().toISOString()
|
||||
sNow: moment().format('YYYY-MM-DD[T00:00:00.000Z]')
|
||||
}
|
||||
|
||||
// add tags array available in the template
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
'use strict'
|
||||
/* global hexo */
|
||||
|
||||
/*
|
||||
* Add sitemap.xml
|
||||
* Based on https://github.com/hexojs/hexo-generator-sitemap/pull/26
|
||||
*/
|
||||
|
||||
/* global hexo */
|
||||
'use strict'
|
||||
|
||||
const pathFn = require('path')
|
||||
|
||||
const config = hexo.config.sitemap = Object.assign({
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const pathFn = require('path')
|
||||
const fs = require('fs')
|
||||
let sitemapTmpl = ""
|
||||
let sitemapTmpl = ''
|
||||
|
||||
module.exports = function (config) {
|
||||
if (sitemapTmpl) return sitemapTmpl
|
||||
|
|
Loading…
Reference in New Issue