-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const { eject, version, createApp } = require('@vuepress/core'); | ||
|
||
function changeVuepressDir(app, options) { | ||
if (options.vuepressDir) { | ||
app.vuepressDir = options.vuepressDir; | ||
} | ||
} | ||
|
||
async function dev(options) { | ||
if (process.env.NODE_ENV === undefined) { | ||
process.env.NODE_ENV = 'development'; | ||
} | ||
const app = createApp(options); | ||
// change vuepressDir | ||
changeVuepressDir(app, options); | ||
await app.process(); | ||
return app.dev(); | ||
} | ||
|
||
async function build(options) { | ||
if (process.env.NODE_ENV === undefined) { | ||
process.env.NODE_ENV = 'production'; | ||
} | ||
const app = createApp(options); | ||
// change vuepressDir | ||
changeVuepressDir(app, options); | ||
await app.process(); | ||
return app.build(); | ||
} | ||
|
||
exports.version = version; | ||
exports.createApp = createApp; | ||
exports.dev = dev; | ||
exports.build = build; | ||
exports.eject = eject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// cache | ||
module.exports = (options, ctx) => { | ||
const { fs, _, logger, path } = require('@micro-app/shared-utils'); | ||
|
||
return { | ||
name: 'createCache', | ||
|
||
ready() { | ||
const { pages, siteConfig } = ctx; | ||
|
||
const categories = []; | ||
const tags = []; | ||
pages | ||
.filter(page => !!page.frontmatter) | ||
.filter(page => { | ||
const { title, frontmatter: { home, private: isPrivate } } = page; | ||
return !(home === true || title === undefined || isPrivate === true); | ||
}) | ||
.map(page => ({ ...page, date: new Date(page.frontmatter.date || page.birthTimestamp || '') })) | ||
.sort((a, b) => b.date - a.date) | ||
.map(page => { | ||
const frontmatter = page.frontmatter || {}; | ||
const categories = Array.isArray(frontmatter.categories) ? frontmatter.categories : _.isString(frontmatter.categories) && [ frontmatter.categories ]; | ||
const tags = Array.isArray(frontmatter.tags) ? frontmatter.tags : _.isString(frontmatter.tags) && [ frontmatter.tags ]; | ||
return { | ||
categories: [].concat(categories || []), | ||
tags: [].concat(tags || []), | ||
}; | ||
}) | ||
.forEach(item => { | ||
categories.push(...item.categories); | ||
tags.push(...item.tags); | ||
}); | ||
|
||
const cacheDir = siteConfig.cacheDir; | ||
fs.ensureDirSync(cacheDir); | ||
fs.writeJSONSync( | ||
path.resolve(cacheDir, 'categories.json'), | ||
_.uniq(categories) | ||
); | ||
fs.writeJSONSync( | ||
path.resolve(cacheDir, 'tags.json'), | ||
_.uniq(tags) | ||
); | ||
logger.info('Categories & Tags has been cached!'); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters