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

Commit

Permalink
fix($core): validate the existence of directory specified by director…
Browse files Browse the repository at this point in the history
…y classifier. (close: #1)
  • Loading branch information
ulivz committed Jun 23, 2019
1 parent 93c6a4e commit d64964d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ lib
.temp
types
src/**/*.js
dist

### Code ###
# Visual Studio Code - https://code.visualstudio.com/
Expand Down
11 changes: 11 additions & 0 deletions examples/blog/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ module.exports = {
lengthPerPage: 2,
},
},
{
id: 'archive',
dirname: '_archive',
path: '/archive/',
// layout: 'IndexArchive', defaults to `Layout.vue`
itemLayout: 'Post',
itemPermalink: '/archive/:year/:month/:day/:slug',
pagination: {
lengthPerPage: 5,
},
},
],
frontmatters: [
{
Expand Down
4 changes: 2 additions & 2 deletions examples/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ async function launch() {
fork(
require.resolve('vuepress/cli.js'),
[
'dev',
process.argv[2],
`${process.cwd()}/examples/${target}`,
'--temp',
`examples/${target}/.temp`,
...process.argv.slice(2),
...process.argv.slice(3),
],
{ stdio: 'inherit' },
)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:components": "mkdir -p lib/client/components && cp -r src/client/components lib/client",
"dev:docs": "vuepress dev docs --temp docs/.temp",
"build:docs": "vuepress build docs --temp docs/.temp",
"example": "node examples/launch.js",
"dev:example": "node examples/launch.js dev",
"build:example": "node examples/launch.js build",
"prepublishOnly": "npm run build && conventional-changelog -p angular -r 2 -i CHANGELOG.md -s"
},
"main": "lib/node/index.js",
Expand Down
21 changes: 20 additions & 1 deletion src/node/handleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fs, path, logger, chalk } from '@vuepress/shared-utils'
import { BlogPluginOptions } from './interface/Options'
import { ExtraPage } from './interface/ExtraPages'
import { PageEnhancer } from './interface/PageEnhancer'
Expand All @@ -23,7 +24,25 @@ export function handleOptions(
options: BlogPluginOptions,
ctx: VuePressContext,
) {
const { directories = [], frontmatters = [] } = options
let { directories = [], frontmatters = [] } = options

/**
* Validate the existence of directory specified by directory classifier.
* Fixed https://github.com/ulivz/vuepress-plugin-blog/issues/1
*/
directories = directories.filter(directory => {
const targetDir = path.join(ctx.sourceDir, directory.dirname)
if (fs.existsSync(targetDir)) {
return true
}

logger.warn(
`[@vuepress/plugin-blog] Invalid directory classifier: ${chalk.cyan(directory.id)}, ` +
`${chalk.gray(targetDir)} doesn't exist!`,
)

return false
})

const pageEnhancers: PageEnhancer[] = []
const frontmatterClassificationPages: FrontmatterClassificationPage[] = []
Expand Down

0 comments on commit d64964d

Please sign in to comment.