Skip to content

Commit

Permalink
Merge pull request #6 from agiletech-web-dev/release
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 authored Jul 16, 2024
2 parents b13ba1c + 2975314 commit 2b84d74
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 91 deletions.
27 changes: 0 additions & 27 deletions docs/.vitepress/components/StabilityLevel.vue

This file was deleted.

5 changes: 0 additions & 5 deletions docs/.vitepress/components/WarnBadge.vue

This file was deleted.

72 changes: 72 additions & 0 deletions docs/.vitepress/plugins/markdownTransform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { Plugin } from 'vite'

export function replacer(code: string, value: string, key: string, insert: 'head' | 'tail' | 'none' = 'none') {
const START = `<!--${key}_STARTS-->`
const END = `<!--${key}_ENDS-->`
const regex = new RegExp(`${START}[\\s\\S]*?${END}`, 'im')

const target = value ? `${START}\n\n${value.trim()}\n\n${END}` : `${START}${END}`

if (!code.match(regex)) {
if (insert === 'none')
return code
else if (insert === 'head')
return `${target}\n\n${code}`
else
return `${code}\n\n${target}`
}

return code.replace(regex, target)
}

export function MarkdownTransform(): Plugin {
return {
name: 'js-utils-md-transform',
enforce: 'pre',
async transform(code, id) {
if (!id.match(/\.md\b/))
return null

const [pkg, _name, i] = id.split('/').slice(-3);

if (pkg !== 'reference')
return code;

const source = await getFunctionMarkdown(_name, i)

code = replacer(code, source, 'FOOTER', 'tail')

code = code
.replace(/(# \w+)\n/, `$1\n\n<FunctionInfo pkgName="${i.replace('.md', '')}"/>\n`);

return code
},
}
}

const GITHUB_BLOB_URL = 'https://github.com/agiletech-web-dev/js-utils-es/blob/main/src';
const GITHUB_BLOB_DOCS_URL = 'https://github.com/agiletech-web-dev/js-utils-es/blob/main/docs/reference';
// https://github.com/agiletech-web-dev/js-utils-es/blob/main/src/array/chunk.ts
// https://github.com/agiletech-web-dev/js-utils-es/blob/main/docs/reference/array/chunk.md

export async function getFunctionMarkdown(pkg: string, name: string) {
const fileNameTs = name.replace('.md', '.ts');
const fileNameTestCase = name.replace('.md', '.spec.ts');
const URL = `${GITHUB_BLOB_URL}/${pkg}/${fileNameTs}`;
const URL_DOCS = `${GITHUB_BLOB_DOCS_URL}/${pkg}/${name}`;
const URL_TEST_CASE = `${GITHUB_BLOB_URL}/${pkg}/${fileNameTestCase}`;

const links = ([
['Source', URL],
['Docs', URL_DOCS],
['Test Case', URL_TEST_CASE],
])
.filter(i => i)
.map(i => `[${i![0]}](${i![1]})`).join(' • ')

const sourceSection = `## Source\n\n${links}\n`

const footer = `\n${sourceSection}`

return footer;
}
4 changes: 0 additions & 4 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Theme from 'vitepress/theme'
import { NolebaseGitChangelogPlugin } from '@nolebase/vitepress-plugin-git-changelog/client'
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import type { EnhanceAppContext } from 'vitepress'
import WarnBadge from '../components/WarnBadge.vue'
import StabilityLevel from '../components/StabilityLevel.vue'
import Layout from './Layout.vue'
import 'uno.css'
import './style.css'
Expand All @@ -14,8 +12,6 @@ export default {
...Theme,
Layout,
enhanceApp({ app }: EnhanceAppContext) {
app.component('WarnBadge', WarnBadge)
app.component('StabilityLevel', StabilityLevel)
app.use(NolebaseGitChangelogPlugin, {
mapAuthors: [
{
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
--vp-c-brand: #ae3ec9;
--vp-c-brand-light: #da77f2;
--vp-c-brand-lighter: #e599f7;
--vp-c-brand-lightest: ##f3d9fa;
--vp-c-brand-lightest: #f3d9fa;
--vp-c-brand-dark: #9c36b5;
--vp-c-brand-darker: #862e9c;
--vp-c-brand-dimm: rgba(145, 71, 150, 0.08);
Expand Down
2 changes: 2 additions & 0 deletions docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
GitChangelog,
GitChangelogMarkdownSection,
} from '@nolebase/vitepress-plugin-git-changelog/vite'
import { MarkdownTransform } from '.vitepress/plugins/markdownTransform'

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

export default defineConfig({
plugins: [
MarkdownTransform(),
VueJsx(),
Unocss(),
GitChangelog({
Expand Down
Loading

0 comments on commit 2b84d74

Please sign in to comment.