-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Sitemap Plugin #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sitemap Plugin #887
Changes from 4 commits
b6aff17
6a4a7c5
5b23494
021514b
4ac3aba
f0f1e96
b2fb771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__tests__ | ||
__mocks__ | ||
.temp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# @vuepress/plugin-sitemap | ||
|
||
> Sitemap plugin for vuepress | ||
|
||
## Usage | ||
|
||
1. Enable this plugin: | ||
|
||
```js | ||
// .vuepress/config.js or themedir/index.js | ||
|
||
module.exports = { | ||
plugins: [ | ||
['@vuepress/sitemap', { | ||
hostname: 'https://yours.net.id' | ||
}] | ||
], | ||
} | ||
``` | ||
|
||
|
||
## Options | ||
All the options of https://npm.im/sitemap | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { path, fs, logger } = require('@vuepress/shared-utils') | ||
const { createSitemap } = require('sitemap') | ||
|
||
module.exports = ({ hostname, changefreq = 'daily', cacheTime = 600000, urls = [], ...others }, context) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using multiple line of object deconstruction. |
||
async generated () { | ||
if (!hostname) { | ||
return logger.warn(`\nNot generating sitemap because required 'hostname' option doesn't exist `) | ||
} | ||
|
||
logger.wait('\nGenerating sitemap...') | ||
|
||
const { pages } = context.getSiteData() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait, I'll check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed that context, I just have idea to create feed plugin with that |
||
const _urls = pages.map(i => { | ||
const lastmodISO = i.lastUpdated ? new Date(i.lastUpdated).toISOString() : undefined | ||
|
||
return { | ||
url: i.path, | ||
lastmodISO, | ||
changefreq | ||
} | ||
}) | ||
.concat(urls) | ||
|
||
const sitemap = createSitemap({ | ||
hostname: hostname, | ||
cacheTime: cacheTime, | ||
urls: _urls, | ||
...others | ||
}) | ||
|
||
const sitemapXML = path.resolve(context.outDir, 'sitemap.xml') | ||
|
||
await fs.writeFile( | ||
sitemapXML, | ||
sitemap.toString() | ||
) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@vuepress/plugin-sitemap", | ||
"version": "1.0.0-alpha.2", | ||
"description": "sitemap plugin for vuepress", | ||
"main": "index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuejs/vuepress.git" | ||
}, | ||
"keywords": [ | ||
"documentation", | ||
"vue", | ||
"vuepress", | ||
"vuepress-plugin", | ||
"sitemap", | ||
"generator" | ||
], | ||
"author": "Eko Eryanto <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/vuejs/vuepress/issues" | ||
}, | ||
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-sitemap#readme", | ||
"dependencies": { | ||
"sitemap": "^2.0.1" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line after the header.