Skip to content

Commit

Permalink
tweak: delete unnecessary codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pei-pay committed Apr 14, 2024
1 parent c23f73a commit 609e9d3
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions packages/.vitepress/plugins/markdownTransform.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
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 { getTypeDefinition, replacer } from '../../../scripts/utils';

export function MarkdownTransform(): Plugin {
// const DIR_TYPES = resolve(__dirname, '../../../types/packages');
// const hasTypes = fs.existsSync(DIR_TYPES);

// if (!hasTypes)
// console.warn('No types dist found, run `npm run build:types` first.');

return {
name: 'vueyous-md-transform',
enforce: 'pre',
Expand All @@ -31,10 +23,6 @@ export function MarkdownTransform(): Plugin {
},
)

// 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 name = functionNames.find(n => n.toLowerCase() === _name.toLowerCase()) || _name
Expand All @@ -44,39 +32,8 @@ export function MarkdownTransform(): Plugin {
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 = '') => {
// const formattedTS = (await format(snippet.replace(/\n+/g, '\n'), { semi: false, singleQuote: true, parser: 'typescript' })).trim();
// const js = ts.transpileModule(formattedTS, {
// compilerOptions: { target: 99 },
// });
// const formattedJS = (await format(js.outputText, { semi: false, singleQuote: true, parser: 'typescript' }))
// .trim();
// if (formattedJS === formattedTS)
// return _;
// return `
// <CodeToggle>
// <div class="code-block-ts">

// \`\`\`ts ${meta}
// ${snippet}
// \`\`\`

// </div>
// <div class="code-block-js">

// \`\`\`js
// ${formattedJS}
// \`\`\`

// </div>
// </CodeToggle>\n`;
// });

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)

Expand All @@ -97,28 +54,6 @@ export async function getFunctionMarkdown(pkg: string, name: string) {

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)
// console.warn(`No types found for ${pkg}/${name}`);

// let typingSection = '';

// if (types) {
// const code = `\`\`\`typescript\n${types.trim()}\n\`\`\``;
// typingSection = types.length > 1000
// ? `
// ## Type Declarations

// <details>
// <summary op50 italic cursor-pointer select-none>Show Type Declarations</summary>

// ${code}

// </details>
// `
// : `\n## Type Declarations\n\n${code}`;
// }

const links = ([
['Source', `${URL}/index.ts`],
Expand All @@ -129,16 +64,6 @@ export async function getFunctionMarkdown(pkg: string, name: string) {
.map(i => `[${i![0]}](${i![1]})`).join(' • ')

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

// <Contributors fn="${name}" />
// `;
// const changelogSection = `
// ## Changelog

// <Changelog fn="${name}" />
// `;

const demoSection = demoPath
? `
Expand All @@ -159,7 +84,6 @@ import Demo from \'./${demoPath}\'
? `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 header = demoSection + packageNote
Expand All @@ -169,12 +93,3 @@ import Demo from \'./${demoPath}\'
header,
}
}

// function replaceAsync(str: string, match: RegExp, replacer: (substring: string, ...args: any[]) => Promise<string>) {
// const promises: Promise<string>[] = [];
// str.replace(match, (...args) => {
// promises.push(replacer(...args));
// return '';
// });
// return Promise.all(promises).then(replacements => str.replace(match, () => replacements.shift()!));
// }

0 comments on commit 609e9d3

Please sign in to comment.