Skip to content

Commit c40aa21

Browse files
committed
docs: add source
1 parent 6874dab commit c40aa21

File tree

24 files changed

+239
-44
lines changed

24 files changed

+239
-44
lines changed

.markdownlint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"no-inline-html": {
3-
"allowed_elements": ["ul", "li", "div", "img", "a", "br", "script", "Badge", "Home","demo"]
3+
"allowed_elements": ["ul", "li", "div", "img", "a", "br", "script", "Badge", "Home","demo","VPTeamPage","VPTeamPageTitle","VPTeamMembers","VPTeamPageSection"]
44
},
55
"MD013": false,
66
"MD041": false

docs/.vitepress/config/en.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ function siderbarUseRequestPlugin(): DefaultTheme.SidebarItem[] {
1111
items: [
1212
{
1313
text: 'global Fetching',
14-
link: 'useRequest/plugins/fetchsing/',
14+
link: 'useRequest/plugins/fetchsing',
1515
},
1616
{
1717
text: 'broadcastChannel',
18-
link: 'useRequest/plugins/broadcastChannel/',
18+
link: 'useRequest/plugins/broadcastChannel',
1919
}]
2020
}
2121
]
@@ -140,7 +140,7 @@ export const en = defineConfig({
140140
},
141141

142142
editLink: {
143-
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
143+
pattern: 'https://github.com/InhiblabCore/vue-hooks-plus/edit/master/docs/:path',
144144
text: 'Edit this page on GitHub'
145145
},
146146

@@ -191,6 +191,7 @@ export function sidebarHooks(): DefaultTheme.SidebarItem[] {
191191
text: 'State',
192192
items: [
193193
{ text: 'useBoolean', link: 'useBoolean' },
194+
{ text: "useControlledState", link: "useControlledState" },
194195
{ text: 'useImmer', link: 'useImmer' },
195196
{ text: 'useUrlState', link: 'useUrlState' },
196197
{ text: 'useFormatResult', link: 'useFormatResult' },

docs/.vitepress/config/shared.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { search as zhSearch } from './zh'
88

99
import { applyMdPlugin } from '../plugins/applyMdPlugin'
10+
import { applyFooterLinkPlugin } from '../plugins/applyFooterLinkPlugin'
1011

1112

1213
export const shared = defineConfig({
@@ -32,6 +33,7 @@ export const shared = defineConfig({
3233
],
3334
config(md) {
3435
applyMdPlugin(md)
36+
// md.renderer.rules.softbreak
3537
const fence = md.renderer.rules.fence!
3638
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
3739
const { localeIndex = 'root' } = env
@@ -120,6 +122,8 @@ export const shared = defineConfig({
120122
}
121123
},
122124
plugins: [
125+
// @ts-ignore
126+
applyFooterLinkPlugin(),
123127
// @ts-ignore
124128
groupIconVitePlugin({
125129
customIcon: {

docs/.vitepress/config/zh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const zh = defineConfig({
142142
},
143143

144144
editLink: {
145-
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
145+
pattern: 'https://github.com/InhiblabCore/vue-hooks-plus/edit/master/docs/:path',
146146
text: '在 GitHub 上编辑此页面'
147147
},
148148

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { Plugin } from 'vite'
2+
import fs from 'node:fs'
3+
import matter from 'gray-matter'
4+
5+
const langTitleMap = {
6+
en: {
7+
document: 'Document',
8+
demo: 'Demo',
9+
source: 'Source'
10+
},
11+
zh: {
12+
document: '文档',
13+
demo: '示例',
14+
source: '源码'
15+
}
16+
}
17+
18+
export function applyFooterLinkPlugin(): Plugin {
19+
return {
20+
name: 'vitepress-md-frontmatter-append',
21+
enforce: 'pre', // 确保在默认插件前执行
22+
23+
load(id) {
24+
console.log("id", id);
25+
26+
if (!id.endsWith('.md')) return
27+
28+
const rawContent = fs.readFileSync(id, 'utf-8')
29+
30+
const lang = id.includes('/zh/') ? 'zh' : 'en'
31+
const { data: frontmatter } = matter(rawContent)
32+
const mapPath = id.replace(process.cwd() + '/docs', '')
33+
34+
console.log("frontmatter", frontmatter);
35+
36+
if (!frontmatter?.map?.path || frontmatter?.source?.show === false) {
37+
return
38+
}
39+
40+
// document
41+
const isShowDemo = frontmatter?.source?.showDemo ?? true
42+
const documentUrl = `https://github.com/InhiblabCore/vue-hooks-plus/blob/master/docs/${mapPath}`
43+
const document = `[${langTitleMap[lang].document}](${documentUrl})`
44+
45+
// demo
46+
const srcMatches = [...rawContent.matchAll(/<demo[^>]*src="([^"]+)"/g)];
47+
const srcValues = srcMatches.map(match => match[1]);
48+
const isOneDemo = srcValues.length && srcValues.length === 1
49+
const demoUrl = `https://github.com/InhiblabCore/vue-hooks-plus/blob/master/docs/demo/${isOneDemo ? srcValues[0] : srcValues[0]?.split?.('/')[0]}`
50+
const demo = isShowDemo ? `[${langTitleMap[lang].demo}](${demoUrl})` : ''
51+
52+
// source
53+
const isShowSource = frontmatter?.source?.showSource ?? true
54+
const sourceMapPath = frontmatter?.source?.path ? frontmatter.source.path : ''
55+
const sourceUrl = sourceMapPath ? sourceMapPath : frontmatter?.map?.path ? `https://github.com/InhiblabCore/vue-hooks-plus/blob/master/packages/hooks/src${frontmatter.map.path}` : `https://github.com/InhiblabCore/vue-hooks-plus/blob/master/packages`
56+
const source = isShowSource ? `[${langTitleMap[lang].source}](${sourceUrl})` : ''
57+
58+
const appentFooter = `
59+
\n\n## Source
60+
\n\n${source ? `${source} ·` : ""} ${`${document}`} ${demo ? ${demo}` : ""}
61+
`
62+
return {
63+
code: rawContent + appentFooter,
64+
map: null
65+
}
66+
}
67+
}
68+
}

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import { useRequestDevToolsPlugin } from 'vue-hooks-plus'
1010
import { createPinia } from 'pinia'
1111

1212
const store = createPinia()
13-
1413
export default {
1514
...Theme,
16-
enhanceApp({ app, router, siteData }) {
15+
enhanceApp({ app }) {
1716
app.use(store)
1817
app.use(useRequestDevToolsPlugin)
1918
app.component('demo', DemoBlock)

docs/contributors.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
type Contributors = {
3+
name: string
4+
avatar?: string
5+
title: "Creator" | "Core developer" | "Contributor",
6+
desc?: string
7+
org?: string
8+
orgLink?: string
9+
links: {
10+
icon: "github" | "twitter" | "discord",
11+
link: string
12+
}[]
13+
}
14+
export const members: Contributors[] = [
15+
{
16+
avatar: "https://github.com/NelsonYong.png",
17+
name: 'YongGit',
18+
title: 'Creator',
19+
desc: "VueHooks Plus's Author",
20+
org: 'InhiblabCore',
21+
orgLink: "https://github.com/InhiblabCore",
22+
links: [
23+
{ icon: 'github', link: 'https://github.com/NelsonYong' },
24+
{ icon: 'twitter', link: 'https://x.com/Yong_Git' },
25+
{
26+
icon: "discord",
27+
link: "https://discord.com/invite/z5Ve5r9Kwp"
28+
}
29+
]
30+
}, {
31+
avatar: 'https://www.github.com/hongaah.png',
32+
name: 'Hazel Wei',
33+
desc: "Swiftcode's Author",
34+
org: 'InhiblabCore',
35+
orgLink: "https://github.com/InhiblabCore",
36+
title: 'Core developer',
37+
links: [
38+
{ icon: 'github', link: 'https://github.com/hongaah' }
39+
]
40+
},
41+
{
42+
avatar: 'https://www.github.com/XiaoDaiGua-Ray.png',
43+
name: 'XiaoDaiGua Ray',
44+
desc: "Tring be better~",
45+
org: 'InhiblabCore',
46+
orgLink: "https://github.com/InhiblabCore",
47+
title: 'Core developer',
48+
links: [
49+
{ icon: 'github', link: 'https://github.com/XiaoDaiGua-Ray' }
50+
]
51+
},
52+
]

docs/en/hooks/useBoolean.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ path: /useBoolean
88

99
A hook that elegantly manages boolean state.
1010

11+
<!-- [[toc]] -->
12+
1113
## Code demonstration
1214

1315
<demo src="useBoolean/demo.vue"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# useControlledState `^2.3.0`

docs/en/hooks/useDebounceFn.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ const {
3939

4040
| Property | Description | Type | Default |
4141
| --- | --- | --- | --- |
42-
| wait | The number of milliseconds to delay. | `number` | `1000` |
43-
| leading | Specify invoking on the leading edge of the timeout. | `boolean` | `false` |
44-
| trailing | Specify invoking on the trailing edge of the timeout. | `boolean` | `true` |
45-
| maxWait | The maximum time func is allowed to be delayed before it’s invoked. | `number` | - |
42+
| wait | The number of milliseconds to delay. | `number`\|`Ref<number>` | `1000` |
43+
| leading | Specify invoking on the leading edge of the timeout. | `boolean`\|`Ref<boolean>` | `false` |
44+
| trailing | Specify invoking on the trailing edge of the timeout. | `boolean`\|`Ref<boolean>` | `true` |
45+
| maxWait | The maximum time func is allowed to be delayed before it’s invoked. | `number`\|`Ref<number>` | - |
4646

4747
## Result
4848

@@ -51,3 +51,12 @@ const {
5151
| run | Invode and pass parameters to fn. | `(...args: any[]) => any` |
5252
| cancel | Cancel the invocation of currently debounced function. | `() => void` |
5353
| flush | Immediately invoke currently debounced function. | `() => void` |
54+
55+
::: warning Remark
56+
57+
- `options.wait` support dynamic changes.
58+
- `options.leading` support dynamic changes.
59+
- `options.trailing` support dynamic changes.
60+
- `options.maxWait` support dynamic changes.
61+
62+
:::

0 commit comments

Comments
 (0)