-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #682 from oceanbase/dengfuping-dev
feat(docs): Add spec and blog
- Loading branch information
Showing
25 changed files
with
2,882 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import assert from 'assert'; | ||
import type { HastRoot, UnifiedTransformer } from 'dumi'; | ||
import { unistUtilVisit } from 'dumi'; | ||
|
||
/** | ||
* plugin for modify hast tree when docs compiling | ||
*/ | ||
function rehypeAntd(): UnifiedTransformer<HastRoot> { | ||
return (tree, vFile) => { | ||
const { filename } = vFile.data.frontmatter as any; | ||
|
||
unistUtilVisit.visit(tree, 'element', (node, i, parent) => { | ||
if (node.tagName === 'DumiDemoGrid') { | ||
// replace DumiDemoGrid to DemoWrapper, to implement demo toolbar | ||
node.tagName = 'DemoWrapper'; | ||
} else if (node.tagName === 'ResourceCards') { | ||
const propNames = ['title', 'cover', 'description', 'src', 'official']; | ||
const contentNode = node.children[0]; | ||
|
||
assert( | ||
contentNode.type === 'text', | ||
`ResourceCards content must be plain text!\nat ${filename}` | ||
); | ||
|
||
// clear children | ||
node.children = []; | ||
|
||
// generate JSX props | ||
(node as any).JSXAttributes = [ | ||
{ | ||
type: 'JSXAttribute', | ||
name: 'resources', | ||
value: JSON.stringify( | ||
contentNode.value | ||
.trim() | ||
.split('\n') | ||
.reduce<any>((acc, cur) => { | ||
// match text from ` - 桌面组件 Sketch 模板包` | ||
const [, isProp, val] = cur.match(/(\s+)?-\s(.+)/)!; | ||
|
||
if (!isProp) { | ||
// create items when match title | ||
acc.push({ [propNames[0]]: val }); | ||
} else { | ||
// add props when match others | ||
const prev = acc[acc.length - 1]; | ||
|
||
prev[propNames[Object.keys(prev).length]] = val; | ||
} | ||
|
||
return acc; | ||
}, []) | ||
), | ||
}, | ||
]; | ||
} else if ( | ||
node.type === 'element' && | ||
node.tagName === 'Table' && | ||
(/^packages\/design/.test(filename) || | ||
/^packages\/ui/.test(filename) || | ||
/^packages\/charts/.test(filename)) | ||
) { | ||
if (!node.properties) return; | ||
node.properties.className ??= []; | ||
(node.properties.className as string[]).push('component-api-table'); | ||
} | ||
// else if (node.type === 'element' && (node.tagName === 'Link' || node.tagName === 'a')) { | ||
// const { tagName } = node; | ||
// node.properties!.sourceType = tagName; | ||
// node.tagName = 'LocaleLink'; | ||
// } | ||
// else if (node.type === 'element' && node.tagName === 'video') { | ||
// node.tagName = 'VideoPlayer'; | ||
// } | ||
else if (node.tagName === 'SourceCode') { | ||
const { lang } = node.properties!; | ||
|
||
if (typeof lang === 'string' && lang.startsWith('sandpack')) { | ||
const code = (node.children[0] as any).value as string; | ||
const configRegx = /^const sandpackConfig = ([\S\s]*?});/; | ||
const [configString] = code.match(configRegx) || []; | ||
/* biome-ignore lint/security/noGlobalEval: used in documentation */ /* eslint-disable-next-line no-eval */ | ||
const config = configString && eval(`(${configString.replace(configRegx, '$1')})`); | ||
Object.keys(config || {}).forEach(key => { | ||
if (typeof config[key] === 'object') { | ||
config[key] = JSON.stringify(config[key]); | ||
} | ||
}); | ||
|
||
parent!.children.splice(i!, 1, { | ||
type: 'element', | ||
tagName: 'Sandpack', | ||
properties: { | ||
...config, | ||
}, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: code.replace(configRegx, '').trim(), | ||
}, | ||
], | ||
}); | ||
} | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
export default rehypeAntd; |
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,15 @@ | ||
import { unistUtilVisit } from 'dumi'; | ||
import type { UnifiedTransformer } from 'dumi'; | ||
|
||
function remarkMeta(): UnifiedTransformer<any> { | ||
return (tree, vFile) => { | ||
// read frontmatter | ||
unistUtilVisit.visit(tree, 'yaml', (node) => { | ||
if (!/(^|[\n\r])description:/.test(node.value)) { | ||
(vFile.data.frontmatter as any).__autoDescription = true; | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
export default remarkMeta; |
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,25 @@ | ||
import React from 'react'; | ||
import { css } from '@emotion/react'; | ||
import useSiteToken from '../../hooks/useSiteToken'; | ||
|
||
export interface CautionProps { | ||
title: React.ReactNode; | ||
filename?: string; | ||
} | ||
|
||
const useStyle = () => { | ||
const { token } = useSiteToken(); | ||
|
||
return { | ||
do: css` | ||
font-size: 20px; | ||
color: ${token.colorWarningText}; | ||
`, | ||
}; | ||
}; | ||
|
||
export default function Caution({}: CautionProps) { | ||
const styles = useStyle(); | ||
|
||
return <span css={styles.do}>Caution</span>; | ||
} |
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,25 @@ | ||
import React from 'react'; | ||
import { css } from '@emotion/react'; | ||
import useSiteToken from '../../hooks/useSiteToken'; | ||
|
||
export interface DoProps { | ||
title: React.ReactNode; | ||
filename?: string; | ||
} | ||
|
||
const useStyle = () => { | ||
const { token } = useSiteToken(); | ||
|
||
return { | ||
do: css` | ||
font-size: 20px; | ||
color: ${token.colorSuccessText}; | ||
`, | ||
}; | ||
}; | ||
|
||
export default function Do({}: DoProps) { | ||
const styles = useStyle(); | ||
|
||
return <span css={styles.do}>Do</span>; | ||
} |
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,25 @@ | ||
import React from 'react'; | ||
import { css } from '@emotion/react'; | ||
import useSiteToken from '../../hooks/useSiteToken'; | ||
|
||
export interface DonotProps { | ||
title: React.ReactNode; | ||
filename?: string; | ||
} | ||
|
||
const useStyle = () => { | ||
const { token } = useSiteToken(); | ||
|
||
return { | ||
do: css` | ||
font-size: 20px; | ||
color: ${token.colorErrorText}; | ||
`, | ||
}; | ||
}; | ||
|
||
export default function Do({}: DonotProps) { | ||
const styles = useStyle(); | ||
|
||
return <span css={styles.do}>Don't</span>; | ||
} |
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
Oops, something went wrong.