Skip to content

Commit 954f7cd

Browse files
committed
feat: support frontmatter
1 parent 4dc59cf commit 954f7cd

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

docs/快速上手.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<!--
2+
title: 快速上手
3+
abbrlink: 290a4219
4+
date: 2019-05-12 13:23:44
5+
-->
6+
17
## 快速上手
28

39
**create-react-doc** 非常容易上手。开发者不需要额外安装或配置 webpack 或者 Babel 等工具,它们被内置隐藏在脚手架中,因此开发者可以专心于文档的书写。

packages/crd-seed/component/Menu/MenuItem.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ function MenuItem({
1616
}
1717

1818
const renderMenuItem = () => {
19+
if (selectedKey === '/290a4219') {
20+
debugger
21+
}
1922
return (
2023
<li
2124
className={cx(styles['menu-item'], styles[`menu-${theme}`], {

packages/crd-seed/layout/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ function BasicLayout({
5656
return (
5757
<>
5858
{menus.map((item, index) => {
59+
const { mdconf, routePath } = item || {}
60+
const { abbrlink } = mdconf || {}
61+
const path = abbrlink ? `/${abbrlink}` : routePath
62+
console.log('item123', item)
5963
// item.path carrys .md here.
6064
return item.children && item.children.length > 0 ? (
6165
<SubMenu key={index} keyValue={item.path} title={item.name} icon={<Icon type="folder" size={16} />}>
@@ -65,7 +69,7 @@ function BasicLayout({
6569
<Menu.Item
6670
key={index}
6771
icon={<Icon type="file" size={16} />}
68-
keyValue={item.path}
72+
keyValue={abbrlink ? `/${abbrlink}` : item.path}
6973
title={
7074
item &&
7175
item.type === "directory" &&
@@ -76,8 +80,8 @@ function BasicLayout({
7680
</span>
7781
) : (
7882
<Link
79-
to={ifProd ? `/${repo}${item.routePath}` : item.routePath}
80-
replace={pathname.indexOf(item.routePath) > -1}
83+
to={ifProd ? `/${repo}${path}` : path}
84+
replace={pathname.indexOf(path) > -1}
8185
>
8286
{item && item.mdconf && item.mdconf.title
8387
? item.mdconf.title
@@ -111,6 +115,7 @@ function BasicLayout({
111115
}}
112116
selectedKey={selectedKey}
113117
onSelect={(keyValue) => {
118+
console.log('keyValue', keyValue)
114119
setSelectedKey(keyValue)
115120
}}
116121
defaultOpenKeys={curOpenKeys}
@@ -217,13 +222,16 @@ function BasicLayout({
217222
{/* see https://reacttraining.com/react-router/web/api/Redirect/exact-bool */}
218223
<Redirect exact from={ifAddPrefix ? `/${repo}` : `/`} to={ifAddPrefix ? `/${repo}/README` : `/README`} />
219224
{routeData.map((item) => {
225+
const { path, mdconf, component } = item
226+
const { abbrlink } = mdconf
227+
const enhancePath = abbrlink ? `/${abbrlink}` : path
220228
return (
221229
<Route
222-
key={item.path}
230+
key={enhancePath}
223231
exact
224-
path={ifAddPrefix ? `/${repo}${item.path}` : item.path}
232+
path={ifAddPrefix ? `/${repo}${enhancePath}` : enhancePath}
225233
render={() => {
226-
const Comp = item.component
234+
const Comp = component
227235
return <Comp {...item} />
228236
}}
229237
/>
@@ -255,7 +263,7 @@ function BasicLayout({
255263
<Footer inlineCollapsed={inlineCollapsed} />
256264
</div>
257265
</div>
258-
);
266+
)
259267
}
260268

261269
export default BasicLayout

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ function directoryTree({
7676
item.type = constants.FILE
7777
const contentStr = fs.readFileSync(path).toString()
7878
if (contentStr && !options.prerender) {
79-
const contentMatch = contentStr.match(/^<!--(\s?[^>]*)-->/)
79+
const contentMatch = contentStr.match(/^<!--([^>]*)-->/)
8080
item.relative = item.path.replace(process.cwd(), '')
8181
item.mdconf = contentMatch ? YAML.parse(contentMatch[1]) : {}
82+
console.log('item.mdconf', item.mdconf)
8283
item.isEmpty = contentMatch
8384
? !String.prototype.trim.call(contentStr.replace(contentMatch[0], ''))
8485
: true

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ 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+
126131
config.plugins = config.plugins.concat([
127132
new webpack.DefinePlugin({
128133
env: JSON.stringify('prod'),
@@ -156,10 +161,19 @@ module.exports = function (cmd) {
156161
new PrerenderSPAPlugin({
157162
// Required - The path to the webpack-outputted app to prerender.
158163
staticDir: docsBuildDist,
159-
outputDir: docsConfig.repo ? `${docsBuildDist}/${docsConfig.repo}` : docsBuildDist,
160-
indexPath: docsConfig.repo ? `${docsBuildDist}/${docsConfig.repo}/index.html` : `${docsBuildDist}/index.html`,
164+
outputDir: docsConfig.repo
165+
? `${docsBuildDist}/${docsConfig.repo}`
166+
: docsBuildDist,
167+
indexPath: docsConfig.repo
168+
? `${docsBuildDist}/${docsConfig.repo}/index.html`
169+
: `${docsBuildDist}/index.html`,
161170
// Required - Routes to render.
162-
routes,
171+
// routes,
172+
routes: [
173+
'/README', '/快速上手',
174+
'/hijkl', '/mnopq',
175+
'/404'
176+
],
163177
successCb: async () => {
164178
if (docsConfig.repo) {
165179
// not use fs.move here or it'll throw error in github action

packages/scripts/src/web/Router.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function routeData(data, arrayRoute = [], routePath = '/', article) {
2323
return arrayRoute
2424
}
2525

26-
2726
function menuSourceFormat(data, routePath, article) {
2827
const arr = []
2928
data.forEach((item) => {

0 commit comments

Comments
 (0)