Skip to content

Commit a1b81ce

Browse files
committed
feat: support attrlink in Front-matter
1 parent 0abfe0d commit a1b81ce

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed

config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ menu: [
1111
docs/更新日志.md,
1212
docs/主题,
1313
docs/站点发布.md,
14-
docs/其它工具.md,
15-
docs/书写组件.md,
14+
docs/Front-matter.md,
1615
docs/数学公式.md,
16+
docs/书写组件.md,
1717
docs/高阶用法.md,
18+
docs/其它工具.md,
1819
]
1920
## set init open menu keys
2021
# menuOpenKeys:

docs/Front-matter.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
abbrlink: 49g6b239
3+
-->
4+
5+
## Front-matter
6+
7+
Front-matter 是文件最上方包裹在 `<!--``-->` 之间的区域,用于指定个别文件的变量,举例来说:
8+
9+
```md
10+
<!--
11+
abbrlink: 290a4219
12+
-->
13+
```
14+
15+
以下是预先定义的参数,您可在模板中使用这些参数值并加以利用。
16+
17+
| 参数 | 描述 | 默认值 |
18+
| :------- | :-------------------------------------------------------------- | :----- |
19+
| abbrlink | 短链。用于指定页面路由展示为指定短链,使用短链有助于 SEO 搜索。 | |

docs/主题/默认主题.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<!--
2-
title: 默认主题
3-
abbrlink: f55182c5
4-
date: 2019-05-12 13:23:44
5-
-->
6-
71
## 默认主题
82

93
create-react-doc 的默认主题为 [crd-seed](https://github.com/MuYunyun/create-react-doc/tree/main/packages/crd-seed)。该主题有以下特性:

docs/更新日志.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
`create-react-doc` 严格遵循 [Semantic Versioning 2.0.0](http://semver.org/lang/zh-CN/) 语义化版本规范。
44

5+
### 1.4.0
6+
7+
`2021-10-08`
8+
9+
- **Feature**
10+
11+
- 🚀 支持展示短链以让文章链接持久化。[issue](https://github.com/MuYunyun/create-react-doc/issues/87)[mr](https://github.com/MuYunyun/create-react-doc/pull/193)
12+
- 🚀 支持在 Front-matter 区域中书写个别文件的变量。
13+
514
### 1.3.5
615

716
`2021-09-24`

packages/crd-seed/layout/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function BasicLayout({
4343

4444
useEffect(() => {
4545
const newPathName = location.pathname
46-
// setSelectedKey(`${newPathName}.md`)
4746
setSelectedKey(newPathName)
4847
}, location)
4948

@@ -115,7 +114,6 @@ function BasicLayout({
115114
}}
116115
selectedKey={selectedKey}
117116
onSelect={(keyValue) => {
118-
console.log('keyValue', keyValue)
119117
setSelectedKey(keyValue)
120118
}}
121119
defaultOpenKeys={curOpenKeys}

packages/scripts/src/conf/getPrerenderRoutes.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ function recursive(data, routePath, arr) {
2828
data.forEach((item) => {
2929
const { mdconf } = item || {}
3030
const { abbrlink } = mdconf || {}
31-
const routePropsCurrent = abbrlink
32-
? `/${abbrlink}`
33-
: `${routePath}/${item.name}`.replace(/.md$/, '')
31+
const composeRouteName = `${routePath}/${item.name}`.replace(/.md$/, '')
32+
3433
if (item.type === 'directory') {
3534
if (item.children && item.children.length > 0) {
3635
// eslint-disable-next-line no-unused-vars
37-
item.children = recursive(item.children, routePropsCurrent, arr)
36+
item.children = recursive(item.children, composeRouteName, arr)
3837
} else {
3938
item.children = []
4039
}
4140
} else if (item.type === 'file') {
42-
arr.push(routePropsCurrent)
41+
const prerenderRouteName = abbrlink
42+
? `/${abbrlink}`
43+
: composeRouteName
44+
arr.push(prerenderRouteName)
4345
}
4446
})
4547
return arr

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ module.exports = function (cmd) {
123123

124124
const routes = getPrerenderRoutes(cmd)
125125

126-
console.log('docsConfig.repo', docsConfig.repo,)
127-
console.log('outputDir', docsConfig.repo ? `${docsBuildDist}/${docsConfig.repo}` : docsBuildDist,)
128-
console.log('indexPath', docsConfig.repo ? `${docsBuildDist}/${docsConfig.repo}/index.html` : `${docsBuildDist}/index.html`,)
129-
console.log('✅ routes', routes)
130-
131126
config.plugins = config.plugins.concat([
132127
new webpack.DefinePlugin({
133128
env: JSON.stringify('prod'),
@@ -169,11 +164,6 @@ module.exports = function (cmd) {
169164
: `${docsBuildDist}/index.html`,
170165
// Required - Routes to render.
171166
routes,
172-
// routes: [
173-
// '/README', '/快速上手',
174-
// '/290a4219', '/9f41fc98',
175-
// '/f55182c5'
176-
// ],
177167
successCb: async () => {
178168
if (docsConfig.repo) {
179169
// not use fs.move here or it'll throw error in github action

0 commit comments

Comments
 (0)