Skip to content

Commit

Permalink
tweak: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pei-pay committed Apr 13, 2024
1 parent beef172 commit a81e50d
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 156 deletions.
4 changes: 2 additions & 2 deletions meta/packages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PackageManifest } from '@vueyous/metadata';
import type { PackageManifest } from '@vueyous/metadata'

export const packages: PackageManifest[] = [
{
Expand All @@ -18,4 +18,4 @@ export const packages: PackageManifest[] = [
display: 'VueYous',
description: 'Collection of essential Vue Composition Utilities',
},
];
]
64 changes: 32 additions & 32 deletions packages/.vitepress/plugins/markdownTransform.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 = '') => {
Expand Down Expand Up @@ -73,30 +73,30 @@ export function MarkdownTransform(): Plugin {
// </CodeToggle>\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<FunctionInfo fn="${name}"/>\n`);
.replace(/(# \w+?)\n/, `$1\n\n<FunctionInfo fn="${name}"/>\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)
Expand Down Expand Up @@ -126,9 +126,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

Expand All @@ -153,21 +153,21 @@ import Demo from \'./${demoPath}\'
<Demo/>
</DemoContainer>
`
: '';
: ''

const packageNote = packages.find(p => p.name === pkg)!.addon
? `Available in the <a href="/${pkg}/README">@vueyous/${pkg}</a> 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<string>) {
Expand Down
14 changes: 7 additions & 7 deletions packages/.vitepress/theme/components/FunctionInfo.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script setup lang="ts">
import { useTimeAgo } from '@vueuse/core';
import { computed } from 'vue';
import { functions } from '@vueyous/metadata';
import { useTimeAgo } from '@vueuse/core'
import { computed } from 'vue'
import { functions } from '@vueyous/metadata'
const props = defineProps<{ fn: string; }>();
const info = computed(() => functions.find(i => i.name === props.fn)!);
const lastUpdated = useTimeAgo(new Date(info.value?.lastUpdated || 0));
const link = computed(() => `/functions\#category=${encodeURIComponent(info.value!.category!)}`);
const props = defineProps<{ fn: string }>()
const info = computed(() => functions.find(i => i.name === props.fn)!)
const lastUpdated = useTimeAgo(new Date(info.value?.lastUpdated || 0))
const link = computed(() => `/functions\#category=${encodeURIComponent(info.value!.category!)}`)
</script>

<template>
Expand Down
22 changes: 11 additions & 11 deletions packages/metadata/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PackageIndexes } from './types';
import _metadata, { categories as _categories, functions as _functions, packages as _packages } from './index.json';
import type { PackageIndexes } from './types'
import _metadata, { categories as _categories, functions as _functions, packages as _packages } from './index.json'

const categoriesOrder = [
'State',
Expand All @@ -14,20 +14,20 @@ const categoriesOrder = [
'Array',
'Time',
'Utilities',
];
]

export const metadata = _metadata as PackageIndexes;
export const functions = _functions as PackageIndexes['functions'];
export const packages = _packages as PackageIndexes['packages'];
export const categories = _categories as PackageIndexes['categories'];
export const metadata = _metadata as PackageIndexes
export const functions = _functions as PackageIndexes['functions']
export const packages = _packages as PackageIndexes['packages']
export const categories = _categories as PackageIndexes['categories']

export const functionNames = functions.map(f => f.name);
export const functionNames = functions.map(f => f.name)
export const categoryNames = Array.from(categories)
.sort((a, b) => categoriesOrder.indexOf(a) - categoriesOrder.indexOf(b))
.sort((a, b) => a.startsWith('@') ? 1 : b.startsWith('@') ? -1 : 0);
.sort((a, b) => a.startsWith('@') ? 1 : b.startsWith('@') ? -1 : 0)
export const coreCategoryNames = categoryNames
.filter(f => !f.startsWith('@'));
.filter(f => !f.startsWith('@'))

export function getFunction(name: string) {
return metadata.functions.find(f => f.name === name);
return metadata.functions.find(f => f.name === name)
}
Loading

0 comments on commit a81e50d

Please sign in to comment.