Skip to content

Commit 0abfe0d

Browse files
committed
feat: support frontmatter
1 parent 0790fb6 commit 0abfe0d

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

packages/scripts/src/conf/getPrerenderRoutes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ const getPrerenderRoutes = (cmd) => {
1414
path,
1515
options: otherProps,
1616
}))
17-
console.log('dirTree12345', dirTree)
1817
const result = getPrerenderRoute(dirTree)
1918
result.push('/404')
20-
// console.log('✅ prerender', result)
2119
return result
2220
}
2321

@@ -28,7 +26,11 @@ function getPrerenderRoute(data) {
2826

2927
function recursive(data, routePath, arr) {
3028
data.forEach((item) => {
31-
const routePropsCurrent = `${routePath}/${item.name}`.replace(/.md$/, '')
29+
const { mdconf } = item || {}
30+
const { abbrlink } = mdconf || {}
31+
const routePropsCurrent = abbrlink
32+
? `/${abbrlink}`
33+
: `${routePath}/${item.name}`.replace(/.md$/, '')
3234
if (item.type === 'directory') {
3335
if (item.children && item.children.length > 0) {
3436
// eslint-disable-next-line no-unused-vars

packages/scripts/src/conf/node-directory-tree.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,9 @@ function directoryTree({
7575
if (options && options.mdconf) {
7676
item.type = constants.FILE
7777
const contentStr = fs.readFileSync(path).toString()
78-
if (contentStr && !options.prerender) {
79-
// todo: when yarn build not run here.
80-
item.test = 'test'
78+
if (contentStr) {
8179
const contentMatch = contentStr.match(/^<!--([^>]*)-->/)
82-
item.relative = item.path.replace(process.cwd(), '')
8380
item.mdconf = contentMatch ? YAML.parse(contentMatch[1]) : {}
84-
console.log('item.mdconf', item.mdconf)
85-
item.isEmpty = contentMatch
86-
? !String.prototype.trim.call(contentStr.replace(contentMatch[0], ''))
87-
: true
88-
const uglifyContent = contentStr.replace(/\s/g, '')
89-
item.content = uglifyContent
9081
try {
9182
// see https://stackoverflow.com/questions/2390199/finding-the-date-time-a-file-was-first-added-to-a-git-repository/2390382#2390382
9283
const result = execSync(`git log --format=%aD ${path} | tail -1`)
@@ -106,6 +97,14 @@ function directoryTree({
10697
}
10798
item.size = stats.size // File size in bytes
10899
item.extension = ext
100+
if (!options.prerender) {
101+
item.relative = item.path.replace(process.cwd(), '')
102+
item.isEmpty = contentMatch
103+
? !String.prototype.trim.call(contentStr.replace(contentMatch[0], ''))
104+
: true
105+
const uglifyContent = contentStr.replace(/\s/g, '')
106+
item.content = uglifyContent
107+
}
109108
}
110109
}
111110
} else if (stats.isDirectory()) {

packages/scripts/src/conf/webpack.config.prod.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = function (cmd) {
126126
console.log('docsConfig.repo', docsConfig.repo,)
127127
console.log('outputDir', docsConfig.repo ? `${docsBuildDist}/${docsConfig.repo}` : docsBuildDist,)
128128
console.log('indexPath', docsConfig.repo ? `${docsBuildDist}/${docsConfig.repo}/index.html` : `${docsBuildDist}/index.html`,)
129-
console.log('routes', routes)
129+
console.log('routes', routes)
130130

131131
config.plugins = config.plugins.concat([
132132
new webpack.DefinePlugin({
@@ -168,12 +168,12 @@ module.exports = function (cmd) {
168168
? `${docsBuildDist}/${docsConfig.repo}/index.html`
169169
: `${docsBuildDist}/index.html`,
170170
// Required - Routes to render.
171-
// routes,
172-
routes: [
173-
'/README', '/快速上手',
174-
'/290a4219', '/9f41fc98',
175-
'/f55182c5'
176-
],
171+
routes,
172+
// routes: [
173+
// '/README', '/快速上手',
174+
// '/290a4219', '/9f41fc98',
175+
// '/f55182c5'
176+
// ],
177177
successCb: async () => {
178178
if (docsConfig.repo) {
179179
// not use fs.move here or it'll throw error in github action

0 commit comments

Comments
 (0)