diff --git a/meta/packages.ts b/meta/packages.ts index 64d3fb1..8742f1f 100644 --- a/meta/packages.ts +++ b/meta/packages.ts @@ -1,4 +1,4 @@ -import type { PackageManifest } from '@vueyous/metadata'; +import type { PackageManifest } from '@vueyous/metadata' export const packages: PackageManifest[] = [ { @@ -154,4 +154,4 @@ export const packages: PackageManifest[] = [ // ], // iife: false, // }, -]; +] diff --git a/packages/.vitepress/config.ts b/packages/.vitepress/config.ts index ec9f0fe..bc55a26 100644 --- a/packages/.vitepress/config.ts +++ b/packages/.vitepress/config.ts @@ -1,27 +1,27 @@ -import { defineConfig } from 'vitepress'; +import { defineConfig } from 'vitepress' -import { categoryNames, coreCategoryNames, metadata } from '../metadata/metadata'; +import { categoryNames, coreCategoryNames, metadata } from '../metadata/metadata' -import viteConfig from './vite.config'; +import viteConfig from './vite.config' const Guide = [ { text: 'はじめに', link: '/guide/' }, { text: 'VueUseとは', link: '/guide/what-is-vueuse' }, { text: '環境構築', link: '/guide/setup' }, -]; +] const CoreCategories = coreCategoryNames.map(c => ({ text: c, activeMatch: '___', // never active link: `/functions#category=${c}`, -})); +})) const DefaultSideBar = [ { text: 'Guide', items: Guide }, { text: 'Core Functions', items: CoreCategories }, -]; +] -const FunctionsSideBar = getFunctionsSideBar(); +const FunctionsSideBar = getFunctionsSideBar() // https://vitepress.dev/reference/site-config export default defineConfig({ @@ -64,16 +64,16 @@ export default defineConfig({ }, // FIXME: any vite: viteConfig as any, -}); +}) function getFunctionsSideBar() { - const links: any = []; + const links: any = [] for (const name of categoryNames) { if (name.startsWith('_')) - continue; + continue - const functions = metadata.functions.filter(i => i.category === name && !i.internal); + const functions = metadata.functions.filter(i => i.category === name && !i.internal) links.push({ text: name, @@ -84,8 +84,8 @@ function getFunctionsSideBar() { link: name.startsWith('@') ? (functions[0].external || `/${functions[0].package}/README`) : undefined, - }); + }) } - return links; + return links } diff --git a/packages/.vitepress/plugins/markdownTransform.ts b/packages/.vitepress/plugins/markdownTransform.ts index 6bb9c86..01a46e3 100644 --- a/packages/.vitepress/plugins/markdownTransform.ts +++ b/packages/.vitepress/plugins/markdownTransform.ts @@ -1,9 +1,9 @@ -import { join, resolve } from 'node:path'; -import type { Plugin } from 'vite'; -import fs from 'fs-extra'; +import { join, resolve } from 'node:path' +import type { Plugin } from 'vite' +import fs from 'fs-extra' // import ts from 'typescript'; -import { packages } from '../../../meta/packages'; -import { functionNames, getFunction } from '../../../packages/metadata/metadata'; +import { packages } from '../../../meta/packages' +import { functionNames, getFunction } from '../../../packages/metadata/metadata' // import { getTypeDefinition, replacer } from '../../../scripts/utils'; export function MarkdownTransform(): Plugin { @@ -18,31 +18,31 @@ export function MarkdownTransform(): Plugin { enforce: 'pre', async transform(code, id) { if (!id.match(/\.md\b/)) - return null; + return null // linkify function names code = code.replace( new RegExp(`\`({${functionNames.join('|')}})\`(.)`, 'g'), (_, name, ending) => { if (ending === ']') // already a link - return _; - const fn = getFunction(name)!; - return `[\`${fn.name}\`](${fn.docs}) `; + return _ + const fn = getFunction(name)! + return `[\`${fn.name}\`](${fn.docs}) ` }, - ); + ) // TODO: set link after deployed // convert links to relative // code = code.replace(/https?:\/\/vueuse\.org\//g, '/'); - const [pkg, _name, i] = id.split('/').slice(-3); + const [pkg, _name, i] = id.split('/').slice(-3) - const name = functionNames.find(n => n.toLowerCase() === _name.toLowerCase()) || _name; + const name = functionNames.find(n => n.toLowerCase() === _name.toLowerCase()) || _name if (functionNames.includes(name) && i === 'index.md') { - const frontmatterEnds = code.indexOf('---\n\n'); - const firstHeader = code.search(/\n#{2,6}\s.+/); - const sliceIndex = firstHeader < 0 ? frontmatterEnds < 0 ? 0 : frontmatterEnds + 4 : firstHeader; + const frontmatterEnds = code.indexOf('---\n\n') + const firstHeader = code.search(/\n#{2,6}\s.+/) + const sliceIndex = firstHeader < 0 ? frontmatterEnds < 0 ? 0 : frontmatterEnds + 4 : firstHeader // Insert JS/TS code blocks // code = await replaceAsync(code, /\n```ts( [^\n]+)?\n(.+?)\n```\n/gs, async (_, meta = '', snippet = '') => { @@ -73,32 +73,32 @@ export function MarkdownTransform(): Plugin { // \n`; // }); - const { header } = await getFunctionMarkdown(pkg, name); + const { header } = await getFunctionMarkdown(pkg, name) // if (hasTypes) // code = replacer(code, footer, 'FOOTER', 'tail'); if (header) - code = code.slice(0, sliceIndex) + header + code.slice(sliceIndex); + code = code.slice(0, sliceIndex) + header + code.slice(sliceIndex) code = code - .replace(/(# \w+?)\n/, `$1\n\n\n`); + .replace(/(# \w+?)\n/, `$1\n\n\n`) // .replace(/## (Components?(?:\sUsage)?)/i, '## $1\n\n\n') // .replace(/## (Directives?(?:\sUsage)?)/i, '## $1\n\n\n'); } - return code; + return code }, - }; + } } -const DIR_SRC = resolve(__dirname, '../..'); -const GITHUB_BLOB_URL = 'https://github.com/pei-pay/VueYous/blob/main/packages'; +const DIR_SRC = resolve(__dirname, '../..') +const GITHUB_BLOB_URL = 'https://github.com/pei-pay/VueYous/blob/main/packages' export async function getFunctionMarkdown(pkg: string, name: string) { - const URL = `${GITHUB_BLOB_URL}/${pkg}/${name}`; + const URL = `${GITHUB_BLOB_URL}/${pkg}/${name}` - const dirname = join(DIR_SRC, pkg, name); - const demoPath = ['demo.vue'].find(i => fs.existsSync(join(dirname, i))); + const dirname = join(DIR_SRC, pkg, name) + const demoPath = ['demo.vue'].find(i => fs.existsSync(join(dirname, i))) // const types = await getTypeDefinition(pkg, name); // if (!types) @@ -128,9 +128,9 @@ export async function getFunctionMarkdown(pkg: string, name: string) { ['Docs', `${URL}/index.md`], ]) .filter(i => i) - .map(i => `[${i![0]}](${i![1]})`).join(' • '); + .map(i => `[${i![0]}](${i![1]})`).join(' • ') - const sourceSection = `## Source\n\n${links}\n`; + const sourceSection = `## Source\n\n${links}\n` // const ContributorsSection = ` // ## Contributors @@ -155,21 +155,21 @@ import Demo from \'./${demoPath}\' ` - : ''; + : '' const packageNote = packages.find(p => p.name === pkg)!.addon ? `Available in the @vueyous/${pkg} add-on.\n` - : ''; + : '' // const footer = `${typingSection}\n\n${sourceSection}\n${ContributorsSection}\n${changelogSection}\n`; - const footer = `${sourceSection}`; + const footer = `${sourceSection}` - const header = demoSection + packageNote; + const header = demoSection + packageNote return { footer, header, - }; + } } // function replaceAsync(str: string, match: RegExp, replacer: (substring: string, ...args: any[]) => Promise) { diff --git a/packages/.vitepress/theme/components/DemoContainer.vue b/packages/.vitepress/theme/components/DemoContainer.vue index 3984f60..37bec84 100644 --- a/packages/.vitepress/theme/components/DemoContainer.vue +++ b/packages/.vitepress/theme/components/DemoContainer.vue @@ -1,11 +1,11 @@