Skip to content

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/@vuepress/plugin-sitemap/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__tests__
__mocks__
.temp
23 changes: 23 additions & 0 deletions packages/@vuepress/plugin-sitemap/README.md
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
Copy link
Member

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.

38 changes: 38 additions & 0 deletions packages/@vuepress/plugin-sitemap/index.js
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) => ({
Copy link
Member

Choose a reason for hiding this comment

The 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using context.pages in build time directly, context.getSiteData() are serialization for client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, I'll check the context.pages

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
)
}
})
30 changes: 30 additions & 0 deletions packages/@vuepress/plugin-sitemap/package.json
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"
}
}
5 changes: 4 additions & 1 deletion packages/docs/docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ module.exports = {
serviceWorker: true,
updatePopup: true
},
'@vuepress/plugin-medium-zoom': true
'@vuepress/plugin-medium-zoom': true,
'@vuepress/plugin-sitemap': {
hostname: 'https://vuepress.vuejs.org'
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@vuepress/plugin-i18n-ui": "^1.0.0-alpha.2",
"@vuepress/plugin-medium-zoom": "^1.0.0-alpha.2",
"@vuepress/plugin-pwa": "^1.0.0-alpha.2",
"@vuepress/plugin-sitemap": "^1.0.0-alpha.2",
"vuepress": "^1.0.0-alpha.2"
}
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8117,6 +8117,14 @@ sisteransi@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce"

sitemap@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-2.0.1.tgz#24f9ae89efeadd80e85e91b7247165497a5e655b"
dependencies:
lodash "^4.17.10"
url-join "^4.0.0"
xmlbuilder "^10.0.0"

slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
Expand Down Expand Up @@ -9533,6 +9541,10 @@ xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"

xmlbuilder@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-10.0.0.tgz#c64e52f8ae097fe5fd46d1c38adaade071ee1b55"

xtend@^4.0.0, xtend@~4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
Expand Down