Skip to content

Commit d95e3c6

Browse files
committed
docs: update gen changelog add to docs
1 parent 2975314 commit d95e3c6

18 files changed

+1837
-264
lines changed

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

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<script setup lang="ts">
2+
// @ts-expect-error virtual
3+
import changelog from '/virtual-changelog'
4+
import { computed } from 'vue'
5+
import { renderCommitMessage } from '../theme/utils'
6+
import funcUtils from '../../../scripts/funcUtils.json';
7+
8+
const props = defineProps<{ fn: string }>()
9+
const info = computed(() => funcUtils.find(i => i.name === props.fn)) as any;
10+
11+
const allCommits = changelog as any[]
12+
13+
14+
const names = computed(() => [props.fn, ...(info.value?.alias || [])]);
15+
16+
const commits = computed(() => {
17+
const related = allCommits
18+
.filter(c => c.version || c.functions?.some((i: any) => names.value.includes(i)))
19+
20+
return related.filter((i, idx) => {
21+
if (i.version && (!related[idx + 1] || related[idx + 1]?.version))
22+
return false
23+
return true
24+
})
25+
})
26+
</script>
27+
28+
<template>
29+
<em v-if="!commits.length" opacity="70">No recent changes</em>
30+
31+
<div v-if="commits.length" class="grid grid-cols-[30px_auto] gap-1.5 children:my-auto changeLog">
32+
<template v-for="(commit, idx) of commits" :key="commit.hash">
33+
<template v-if="idx === 0 && !commit.version">
34+
<div m="t-1" />
35+
<div m="t-1" />
36+
<div class="m-auto inline-flex bg-gray-400/10 w-7 h-7 rounded-full text-sm opacity-90">
37+
<octicon-git-pull-request-draft-16 m="auto" />
38+
</div>
39+
<div>
40+
<code>Pending for release...</code>
41+
</div>
42+
</template>
43+
<template v-if="commit.version">
44+
<div m="t-1" />
45+
<div m="t-1" />
46+
<div class="m-auto inline-flex justify-center items-center bg-gray-400/10 w-7 h-7 rounded-full text-sm opacity-90">
47+
<svg viewBox="0 0 16 16" width="1.2em" height="1.2em" m="auto" style="display: inline-block;"><path fill="currentColor" d="M14.064 0h.186C15.216 0 16 .784 16 1.75v.186a8.75 8.75 0 0 1-2.564 6.186l-.458.459q-.472.471-.979.904v3.207c0 .608-.315 1.172-.833 1.49l-2.774 1.707a.75.75 0 0 1-1.11-.418l-.954-3.102a1 1 0 0 1-.145-.125L3.754 9.816a1 1 0 0 1-.124-.145L.528 8.717a.75.75 0 0 1-.418-1.11l1.71-2.774A1.75 1.75 0 0 1 3.31 4h3.204q.433-.508.904-.979l.459-.458A8.75 8.75 0 0 1 14.064 0M8.938 3.623h-.002l-.458.458c-.76.76-1.437 1.598-2.02 2.5l-1.5 2.317l2.143 2.143l2.317-1.5c.902-.583 1.74-1.26 2.499-2.02l.459-.458a7.25 7.25 0 0 0 2.123-5.127V1.75a.25.25 0 0 0-.25-.25h-.186a7.25 7.25 0 0 0-5.125 2.123M3.56 14.56c-.732.732-2.334 1.045-3.005 1.148a.23.23 0 0 1-.201-.064a.23.23 0 0 1-.064-.201c.103-.671.416-2.273 1.15-3.003a1.502 1.502 0 1 1 2.12 2.12m6.94-3.935q-.132.09-.266.175l-2.35 1.521l.548 1.783l1.949-1.2a.25.25 0 0 0 .119-.213ZM3.678 8.116L5.2 5.766q.087-.135.176-.266H3.309a.25.25 0 0 0-.213.119l-1.2 1.95ZM12 5a1 1 0 1 1-2 0a1 1 0 0 1 2 0"></path></svg>
48+
</div>
49+
<div>
50+
<a
51+
:href="`https://github.com/agiletech-web-dev/js-utils-es/releases/tag/${commit.version}`"
52+
target="_blank"
53+
>
54+
<code class="!text-primary font-bold">{{ commit.version }}</code>
55+
</a>
56+
<span class="opacity-50 text-xs"> on {{ new Date(commit.date).toLocaleDateString() }}</span>
57+
</div>
58+
</template>
59+
<template v-else>
60+
<svg viewBox="0 0 16 16" width="1.2em" height="1.2em" class="m-auto transform rotate-90 opacity-30" style="display: inline-block;"><path fill="currentColor" d="M11.93 8.5a4.002 4.002 0 0 1-7.86 0H.75a.75.75 0 0 1 0-1.5h3.32a4.002 4.002 0 0 1 7.86 0h3.32a.75.75 0 0 1 0 1.5Zm-1.43-.75a2.5 2.5 0 1 0-5 0a2.5 2.5 0 0 0 5 0"></path></svg>
61+
<div>
62+
<a :href="`https://github.com/agiletech-web-dev/js-utils-es/commit/${commit.hash}`" target="_blank">
63+
<code class="!text-xs !text-$vp-c-text-2 !hover:text-primary">{{ commit.hash.slice(0, 5) }}</code>
64+
</a>
65+
<span text="sm">
66+
-
67+
<span v-html="renderCommitMessage(commit.message.replace(`(${fn})`, ''))" />
68+
</span>
69+
</div>
70+
</template>
71+
</template>
72+
</div>
73+
</template>

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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script setup lang="ts">
2+
// @ts-expect-error missing types
3+
import _contributors from '/virtual-contributors'
4+
import { computed } from 'vue'
5+
6+
import { generateGithubAvatar, generateGithubLink, generateUserName } from '../theme/utils';
7+
8+
const props = defineProps<{ fn: string }>()
9+
10+
const contributors = computed(() => _contributors[props.fn] || [] as any[])
11+
</script>
12+
13+
<template>
14+
<div class="flex flex-wrap gap-4 pt-2">
15+
<em v-if="!contributors.length" opacity="70">No recent changes</em>
16+
17+
<div v-for="c of contributors" :key="c.hash" class="flex gap-2 items-center">
18+
<a :href="generateGithubLink(c.name)" target="_blank" rel="noopener noreferrer" class="flex gap-2 items-center">
19+
<img :src="generateGithubAvatar(c.name, c.hash)" class="w-8 h-8 rounded-full">
20+
{{ generateUserName(c.name) }}
21+
</a>
22+
</div>
23+
</div>
24+
</template>

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Plugin } from 'vite'
2+
3+
const ID = '/virtual-changelog'
4+
5+
export function ChangeLog(data: any[]): Plugin {
6+
return {
7+
name: 'js-utils-changelog',
8+
resolveId(id) {
9+
return id === ID ? ID : null
10+
},
11+
load(id) {
12+
if (id !== ID)
13+
return null
14+
return `export default ${JSON.stringify(data)}`
15+
},
16+
}
17+
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Plugin } from 'vite'
2+
3+
const ID = '/virtual-contributors'
4+
5+
export function Contributors(data: Record<string, any[]>): Plugin {
6+
return {
7+
name: 'vueusjs-utils-contributors',
8+
resolveId(id) {
9+
return id === ID ? ID : null
10+
},
11+
load(id) {
12+
if (id !== ID)
13+
return null
14+
return `export default ${JSON.stringify(data)}`
15+
},
16+
}
17+
}

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,17 @@ export async function getFunctionMarkdown(pkg: string, name: string) {
6565
.map(i => `[${i![0]}](${i![1]})`).join(' • ')
6666

6767
const sourceSection = `## Source\n\n${links}\n`
68+
const ContributorsSection = `
69+
## Contributors
6870
69-
const footer = `\n${sourceSection}`
71+
<Contributors fn="${fileNameTs}" />
72+
`
73+
const changelogSection = `
74+
## Changelog
75+
76+
<Changelog fn="${fileNameTs}" />
77+
`
78+
const footer = `\n${sourceSection}\n${ContributorsSection}\n${changelogSection}\n`
7079

7180
return footer;
7281
}

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

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
import Theme from 'vitepress/theme'
2-
import { NolebaseGitChangelogPlugin } from '@nolebase/vitepress-plugin-git-changelog/client'
32
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
43
import type { EnhanceAppContext } from 'vitepress'
5-
import Layout from './Layout.vue'
64
import 'uno.css'
75
import './style.css'
8-
import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
6+
// import '@nolebase/vitepress-plugin-git-changelog/client/style.css'
97
import '@shikijs/vitepress-twoslash/style.css'
8+
import Contributors from '../components/Contributors.vue'
9+
import Changelog from '../components/Changelog.vue'
10+
import Layout from './Layout.vue'
1011

1112
export default {
1213
...Theme,
1314
Layout,
1415
enhanceApp({ app }: EnhanceAppContext) {
15-
app.use(NolebaseGitChangelogPlugin, {
16-
mapAuthors: [
17-
{
18-
name: 'hunghg255',
19-
username: 'hunghg255',
20-
mapByNameAliases: ['Hung Hoang', 'Hoang Hung'],
21-
mapByEmailAliases: ['[email protected]'],
22-
},
23-
],
24-
numCommitHashLetters: 7,
25-
})
16+
app.component('Contributors', Contributors)
17+
app.component('Changelog', Changelog)
18+
2619
app.use(TwoslashFloatingVue)
2720
},
2821
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,9 @@
185185
.VPHomeHero .VPImage {
186186
border-radius: 16px;
187187
}
188+
189+
.changeLog {
190+
padding: 16px;
191+
border-radius: 12px;
192+
background: var(--vp-c-bg-soft);
193+
}

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

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
export function renderMarkdown(markdownText = '') {
2+
const htmlText = markdownText
3+
.replace(/^### (.*$)/gm, '<h3>$1</h3>')
4+
.replace(/^## (.*$)/gm, '<h2>$1</h2>')
5+
.replace(/^# (.*$)/gm, '<h1>$1</h1>')
6+
.replace(/^> (.*$)/gm, '<blockquote>$1</blockquote>')
7+
.replace(/\*\*(.*)\*\*/g, '<b>$1</b>')
8+
.replace(/\*(.*)\*/g, '<i>$1</i>')
9+
.replace(/!\[(.*?)\]\((.*?)\)/g, '<img alt=\'$1\' src=\'$2\' />')
10+
.replace(/\[(.*?)\]\((.*?)\)/g, '<a href=\'$2\'>$1</a>')
11+
.replace(/`(.*?)`/g, '<code>$1</code>')
12+
.replace(/\n$/gm, '<br />')
13+
14+
return htmlText.trim()
15+
}
16+
17+
export function renderCommitMessage(msg: string) {
18+
return renderMarkdown(msg)
19+
.replace(/#(\d+)/g, '<a href=\'https://github.com/agiletech-web-dev/js-utils-es/issues/$1\'>#$1</a>')
20+
}
21+
22+
const mapAuthors = [
23+
{
24+
nameDipslay: 'Hung Hoang',
25+
username: 'hunghg255',
26+
mapByNameAliases: ['Hung Hoang', 'Hoang Hung'],
27+
mapByEmailAliases: ['[email protected]'],
28+
},
29+
];
30+
31+
export function generateGithubAvatar(nameCommit: string, hash: string) {
32+
const match = mapAuthors.find((author) => {
33+
return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit;
34+
});
35+
36+
if (match) {
37+
return `https://github.com/${match.username}.png`;
38+
}
39+
40+
return `https://gravatar.com/avatar/${hash}?d=retro`;
41+
}
42+
43+
export function generateUserName(nameCommit: string) {
44+
const match = mapAuthors.find((author) => {
45+
return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit;
46+
});
47+
48+
if (match) {
49+
return match.nameDipslay || nameCommit;
50+
}
51+
52+
return nameCommit;
53+
}
54+
55+
export function generateGithubLink(nameCommit: string) {
56+
const match = mapAuthors.find((author) => {
57+
return author.mapByNameAliases.includes(nameCommit) || author.mapByEmailAliases.includes(nameCommit) || author.username === nameCommit;
58+
});
59+
60+
if (match) {
61+
return `https://github.com/${match.username}`;
62+
}
63+
64+
return `https://github.com/${nameCommit}`;
65+
}

Diff for: docs/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"devDependencies": {
1818
"@nolebase/vitepress-plugin-enhanced-mark": "^2.2.1",
1919
"@nolebase/vitepress-plugin-enhanced-readabilities": "^2.2.1",
20-
"@nolebase/vitepress-plugin-git-changelog": "^2.2.2",
2120
"@nolebase/vitepress-plugin-highlight-targeted-heading": "^2.2.1",
2221
"@shikijs/vitepress-twoslash": "^1.10.3",
2322
"@vitejs/plugin-vue-jsx": "^4.0.0",

Diff for: docs/vite.config.ts

+29-33
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
import { defineConfig } from 'vite'
22
import Unocss from 'unocss/vite'
33
import VueJsx from '@vitejs/plugin-vue-jsx'
4-
import {
5-
GitChangelog,
6-
GitChangelogMarkdownSection,
7-
} from '@nolebase/vitepress-plugin-git-changelog/vite'
8-
import { MarkdownTransform } from '.vitepress/plugins/markdownTransform'
4+
import changeLog from '../scripts/changeLog.json';
5+
import contributions from '../scripts/contributions.json';
6+
import { ChangeLog } from './.vitepress/plugins/changelog'
7+
import { Contributors } from './.vitepress/plugins/contributors'
8+
import { MarkdownTransform } from './.vitepress/plugins/markdownTransform'
99

10-
const githubRepo = 'agiletech-web-dev/js-utils-es'
11-
const githubLink: 'https://github.com/agiletech-web-dev/js-utils-es' = `https://github.com/${githubRepo}`
12-
13-
export default defineConfig({
14-
plugins: [
15-
MarkdownTransform(),
16-
VueJsx(),
17-
Unocss(),
18-
GitChangelog({
19-
maxGitLogCount: 2000,
20-
repoURL: () => githubLink,
21-
}),
22-
GitChangelogMarkdownSection(),
23-
],
24-
optimizeDeps: {
25-
include: [
26-
'@nolebase/vitepress-plugin-enhanced-readabilities > @nolebase/ui > @rive-app/canvas',
27-
],
28-
exclude: [
29-
'@nolebase/vitepress-plugin-enhanced-readabilities/client',
30-
'vitepress',
31-
],
32-
},
33-
ssr: {
34-
noExternal: [
35-
'@nolebase/vitepress-plugin-enhanced-readabilities',
36-
'@nolebase/vitepress-plugin-highlight-targeted-heading',
10+
export default defineConfig(async () => {
11+
return {
12+
plugins: [
13+
MarkdownTransform(),
14+
ChangeLog(changeLog),
15+
Contributors(contributions),
16+
VueJsx(),
17+
Unocss(),
3718
],
38-
},
19+
optimizeDeps: {
20+
include: [
21+
'@nolebase/vitepress-plugin-enhanced-readabilities > @nolebase/ui > @rive-app/canvas',
22+
],
23+
exclude: [
24+
'@nolebase/vitepress-plugin-enhanced-readabilities/client',
25+
'vitepress',
26+
],
27+
},
28+
ssr: {
29+
noExternal: [
30+
'@nolebase/vitepress-plugin-enhanced-readabilities',
31+
'@nolebase/vitepress-plugin-highlight-targeted-heading',
32+
],
33+
},
34+
}
3935
})

Diff for: eslint.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default antfu({
77
'style/member-delimiter-style': 'off',
88
'ts/ban-ts-comment': 'off',
99
'test/consistent-test-it': 'off',
10+
'style/eol-last': 'off',
1011
},
1112
});

Diff for: package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,20 @@
203203
"docs:dev": "pnpm run -C ./docs dev",
204204
"docs:preview": "pnpm run -C ./docs preview",
205205
"docs:build": "pnpm run -C ./docs build",
206-
"verify-commit": "verify-commit-msg"
206+
"verify-commit": "verify-commit-msg",
207+
"gen-changelog": "esno ./scripts/genFuncUtils.ts && esno ./scripts/changelog.ts"
207208
},
208209
"devDependencies": {
209210
"@antfu/eslint-config": "^2.22.0",
211+
"@types/md5": "^2.3.5",
210212
"@types/node": "^18.19.33",
211213
"bumpp": "^9.4.1",
212214
"eslint": "^9.7.0",
215+
"esno": "^4.7.0",
216+
"execa": "^9.3.0",
213217
"git-scm-hooks": "^0.0.7",
218+
"globby": "^14.0.2",
219+
"md5": "^2.3.0",
214220
"tsup": "^8.1.0",
215221
"typescript": "^5.4.5",
216222
"verify-commit-msg": "^0.0.10",

0 commit comments

Comments
 (0)