Skip to content

Commit 2975314

Browse files
committed
docs: update
1 parent 1a782f5 commit 2975314

File tree

7 files changed

+173
-91
lines changed

7 files changed

+173
-91
lines changed

Diff for: docs/.vitepress/components/StabilityLevel.vue

-27
This file was deleted.

Diff for: docs/.vitepress/components/WarnBadge.vue

-5
This file was deleted.

Diff for: docs/.vitepress/plugins/markdownTransform.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import type { Plugin } from 'vite'
2+
3+
export function replacer(code: string, value: string, key: string, insert: 'head' | 'tail' | 'none' = 'none') {
4+
const START = `<!--${key}_STARTS-->`
5+
const END = `<!--${key}_ENDS-->`
6+
const regex = new RegExp(`${START}[\\s\\S]*?${END}`, 'im')
7+
8+
const target = value ? `${START}\n\n${value.trim()}\n\n${END}` : `${START}${END}`
9+
10+
if (!code.match(regex)) {
11+
if (insert === 'none')
12+
return code
13+
else if (insert === 'head')
14+
return `${target}\n\n${code}`
15+
else
16+
return `${code}\n\n${target}`
17+
}
18+
19+
return code.replace(regex, target)
20+
}
21+
22+
export function MarkdownTransform(): Plugin {
23+
return {
24+
name: 'js-utils-md-transform',
25+
enforce: 'pre',
26+
async transform(code, id) {
27+
if (!id.match(/\.md\b/))
28+
return null
29+
30+
const [pkg, _name, i] = id.split('/').slice(-3);
31+
32+
if (pkg !== 'reference')
33+
return code;
34+
35+
const source = await getFunctionMarkdown(_name, i)
36+
37+
code = replacer(code, source, 'FOOTER', 'tail')
38+
39+
code = code
40+
.replace(/(# \w+)\n/, `$1\n\n<FunctionInfo pkgName="${i.replace('.md', '')}"/>\n`);
41+
42+
return code
43+
},
44+
}
45+
}
46+
47+
const GITHUB_BLOB_URL = 'https://github.com/agiletech-web-dev/js-utils-es/blob/main/src';
48+
const GITHUB_BLOB_DOCS_URL = 'https://github.com/agiletech-web-dev/js-utils-es/blob/main/docs/reference';
49+
// https://github.com/agiletech-web-dev/js-utils-es/blob/main/src/array/chunk.ts
50+
// https://github.com/agiletech-web-dev/js-utils-es/blob/main/docs/reference/array/chunk.md
51+
52+
export async function getFunctionMarkdown(pkg: string, name: string) {
53+
const fileNameTs = name.replace('.md', '.ts');
54+
const fileNameTestCase = name.replace('.md', '.spec.ts');
55+
const URL = `${GITHUB_BLOB_URL}/${pkg}/${fileNameTs}`;
56+
const URL_DOCS = `${GITHUB_BLOB_DOCS_URL}/${pkg}/${name}`;
57+
const URL_TEST_CASE = `${GITHUB_BLOB_URL}/${pkg}/${fileNameTestCase}`;
58+
59+
const links = ([
60+
['Source', URL],
61+
['Docs', URL_DOCS],
62+
['Test Case', URL_TEST_CASE],
63+
])
64+
.filter(i => i)
65+
.map(i => `[${i![0]}](${i![1]})`).join(' • ')
66+
67+
const sourceSection = `## Source\n\n${links}\n`
68+
69+
const footer = `\n${sourceSection}`
70+
71+
return footer;
72+
}

Diff for: docs/.vitepress/theme/index.ts

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import Theme from 'vitepress/theme'
22
import { NolebaseGitChangelogPlugin } from '@nolebase/vitepress-plugin-git-changelog/client'
33
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
44
import type { EnhanceAppContext } from 'vitepress'
5-
import WarnBadge from '../components/WarnBadge.vue'
6-
import StabilityLevel from '../components/StabilityLevel.vue'
75
import Layout from './Layout.vue'
86
import 'uno.css'
97
import './style.css'
@@ -14,8 +12,6 @@ export default {
1412
...Theme,
1513
Layout,
1614
enhanceApp({ app }: EnhanceAppContext) {
17-
app.component('WarnBadge', WarnBadge)
18-
app.component('StabilityLevel', StabilityLevel)
1915
app.use(NolebaseGitChangelogPlugin, {
2016
mapAuthors: [
2117
{

Diff for: docs/.vitepress/theme/style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
--vp-c-brand: #ae3ec9;
5353
--vp-c-brand-light: #da77f2;
5454
--vp-c-brand-lighter: #e599f7;
55-
--vp-c-brand-lightest: ##f3d9fa;
55+
--vp-c-brand-lightest: #f3d9fa;
5656
--vp-c-brand-dark: #9c36b5;
5757
--vp-c-brand-darker: #862e9c;
5858
--vp-c-brand-dimm: rgba(145, 71, 150, 0.08);

Diff for: docs/vite.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {
55
GitChangelog,
66
GitChangelogMarkdownSection,
77
} from '@nolebase/vitepress-plugin-git-changelog/vite'
8+
import { MarkdownTransform } from '.vitepress/plugins/markdownTransform'
89

910
const githubRepo = 'agiletech-web-dev/js-utils-es'
1011
const githubLink: 'https://github.com/agiletech-web-dev/js-utils-es' = `https://github.com/${githubRepo}`
1112

1213
export default defineConfig({
1314
plugins: [
15+
MarkdownTransform(),
1416
VueJsx(),
1517
Unocss(),
1618
GitChangelog({

0 commit comments

Comments
 (0)