Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit d64964d

Browse files
committed
fix($core): validate the existence of directory specified by directory classifier. (close: #1)
1 parent 93c6a4e commit d64964d

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ lib
33
.temp
44
types
55
src/**/*.js
6+
dist
67

78
### Code ###
89
# Visual Studio Code - https://code.visualstudio.com/

Diff for: examples/blog/.vuepress/config.js

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ module.exports = {
1414
lengthPerPage: 2,
1515
},
1616
},
17+
{
18+
id: 'archive',
19+
dirname: '_archive',
20+
path: '/archive/',
21+
// layout: 'IndexArchive', defaults to `Layout.vue`
22+
itemLayout: 'Post',
23+
itemPermalink: '/archive/:year/:month/:day/:slug',
24+
pagination: {
25+
lengthPerPage: 5,
26+
},
27+
},
1728
],
1829
frontmatters: [
1930
{

Diff for: examples/launch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ async function launch() {
3333
fork(
3434
require.resolve('vuepress/cli.js'),
3535
[
36-
'dev',
36+
process.argv[2],
3737
`${process.cwd()}/examples/${target}`,
3838
'--temp',
3939
`examples/${target}/.temp`,
40-
...process.argv.slice(2),
40+
...process.argv.slice(3),
4141
],
4242
{ stdio: 'inherit' },
4343
)

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"build:components": "mkdir -p lib/client/components && cp -r src/client/components lib/client",
1414
"dev:docs": "vuepress dev docs --temp docs/.temp",
1515
"build:docs": "vuepress build docs --temp docs/.temp",
16-
"example": "node examples/launch.js",
16+
"dev:example": "node examples/launch.js dev",
17+
"build:example": "node examples/launch.js build",
1718
"prepublishOnly": "npm run build && conventional-changelog -p angular -r 2 -i CHANGELOG.md -s"
1819
},
1920
"main": "lib/node/index.js",

Diff for: src/node/handleOptions.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fs, path, logger, chalk } from '@vuepress/shared-utils'
12
import { BlogPluginOptions } from './interface/Options'
23
import { ExtraPage } from './interface/ExtraPages'
34
import { PageEnhancer } from './interface/PageEnhancer'
@@ -23,7 +24,25 @@ export function handleOptions(
2324
options: BlogPluginOptions,
2425
ctx: VuePressContext,
2526
) {
26-
const { directories = [], frontmatters = [] } = options
27+
let { directories = [], frontmatters = [] } = options
28+
29+
/**
30+
* Validate the existence of directory specified by directory classifier.
31+
* Fixed https://github.com/ulivz/vuepress-plugin-blog/issues/1
32+
*/
33+
directories = directories.filter(directory => {
34+
const targetDir = path.join(ctx.sourceDir, directory.dirname)
35+
if (fs.existsSync(targetDir)) {
36+
return true
37+
}
38+
39+
logger.warn(
40+
`[@vuepress/plugin-blog] Invalid directory classifier: ${chalk.cyan(directory.id)}, ` +
41+
`${chalk.gray(targetDir)} doesn't exist!`,
42+
)
43+
44+
return false
45+
})
2746

2847
const pageEnhancers: PageEnhancer[] = []
2948
const frontmatterClassificationPages: FrontmatterClassificationPage[] = []

0 commit comments

Comments
 (0)