Skip to content

Commit 1cba9bc

Browse files
committed
feat: init @vuepress/plugin-blog
1 parent 99cd911 commit 1cba9bc

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__tests__
2+
__mocks__
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @vuepress/plugin-blog
2+
3+
> theme plugin for vuepress
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module.exports = (options, ctx) => ({
2+
extendPageData (pageCtx) {
3+
const {
4+
_frontmatterMeta // result of parseFrontmatter
5+
// type: { data: FrontMatterObject, content: rest content }
6+
7+
// _filePath, // file's absolute path
8+
// _content, // file's raw content string
9+
// key, // file's hash key
10+
// regularPath // current page's default link (follow the file hierarchy)
11+
} = pageCtx
12+
13+
const { data: rawFrontmatter } = _frontmatterMeta
14+
const { layoutComponentMap } = ctx
15+
const { pageEnhancers = [] } = options
16+
const isLayoutExists = name => layoutComponentMap[name] !== undefined
17+
const getLayout = name => isLayoutExists(name) ? name : 'Layout'
18+
19+
const enhancers = [
20+
{
21+
when: ({ regularPath }) => regularPath === '/category/',
22+
frontmatter: { layout: getLayout('Category') }
23+
},
24+
{
25+
when: ({ regularPath }) => regularPath === '/tags/',
26+
frontmatter: { layout: getLayout('Tag') }
27+
},
28+
{
29+
when: ({ regularPath }) => regularPath.startsWith('/_posts/'),
30+
frontmatter: {
31+
layout: getLayout('Post'),
32+
permalink: '/:year/:month/:day/:slug'
33+
}
34+
},
35+
...pageEnhancers
36+
]
37+
38+
enhancers.forEach(({
39+
when,
40+
frontmatter = {}
41+
}) => {
42+
if (when(pageCtx)) {
43+
Object.assign(rawFrontmatter, frontmatter)
44+
}
45+
})
46+
}
47+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@vuepress/plugin-blog",
3+
"version": "1.0.0",
4+
"description": "theme plugin for vuepress",
5+
"main": "index.js",
6+
"publishConfig": {
7+
"access": "public"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/vuejs/vuepress.git"
12+
},
13+
"keywords": [
14+
"documentation",
15+
"vue",
16+
"vuepress",
17+
"generator"
18+
],
19+
"author": "Evan You",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/vuejs/vuepress/issues"
23+
},
24+
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-blog#readme"
25+
}

0 commit comments

Comments
 (0)