Skip to content

Commit 2175d58

Browse files
author
gauthier
committed
adding lastModified property to objectfile and add lastMod tag in xml sitemap
1 parent aae4218 commit 2175d58

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

docs/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = {
22
dest: 'vuepress',
33
sitemap: {
4-
domain: 'https://vuepress.vuejs.org'
4+
domain: 'https://vuepress.vuejs.org',
5+
filename: 'test.xml'
56
},
67
locales: {
78
'/': {

docs/config/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ module.exports = {
198198
}
199199
}
200200
```
201+
### sitemap
202+
203+
- Type: `Object`
204+
- Default: `undefined`
205+
206+
Defined sitemap option
201207

202208
## Browser Compatibility
203209

lib/prepare.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ async function resolveOptions (sourceDir) {
157157
const data = {
158158
path: fileToPath(file)
159159
}
160-
160+
const f = await fs.stat(path.resolve(sourceDir, file))
161+
data.lastModified = new Date(f.mtime).toISOString()
161162
// extract yaml frontmatter
162163
const content = await fs.readFile(path.resolve(sourceDir, file), 'utf-8')
163164
const frontmatter = yaml.loadFront(content)

lib/util/sitemap.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ const { fileNameConverter } = require('./index')
22

33
function xmlFormatter (options) {
44
const content = options.siteData.pages.reduce((prev, current) => {
5+
console.log(JSON.stringify(current, null, 2))
56
const filename = fileNameConverter(current.path)
67
const url = options.siteConfig.sitemap.domain + options.siteData.base + filename
7-
return prev + `<url><loc>${url}</loc></url>`
8+
return prev + `<url>
9+
<loc>${url}</loc>
10+
<lastmod>${current.lastModified}</lastmod>
11+
</url>`
812
}, '')
913
return `<?xml version="1.0" encoding="UTF-8"?>
1014
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

0 commit comments

Comments
 (0)