fix: removed unnessary & redundant transformation replacement options for markdowns that causes unexpected vite wepacking behaviors such as whitespaces and `unrecongized import of assets

This commit is contained in:
Anda Toshiki 2023-09-17 02:14:12 -07:00
parent 864be27d0c
commit 549f6b640c

View File

@ -1,6 +1,6 @@
import type { Plugin } from 'vite' import type { Plugin } from 'vite'
import { replacer } from '../../../scripts/markdownTransform'
import { getReadingTime } from './../theme/utils' import { getReadingTime } from './../theme/utils'
// import { replacer } from '../../../scripts/utils'
export function MarkdownTransform(): Plugin { export function MarkdownTransform(): Plugin {
return { return {
@ -9,7 +9,7 @@ export function MarkdownTransform(): Plugin {
async transform(code, id) { async transform(code, id) {
if (!id.match(/\.md\b/)) return null if (!id.match(/\.md\b/)) return null
// convert links to relative // convert links to relative
code = code.replace(/https?:\/\/toshiki-notebook\.dev\//g, '/') code = code.replace(/https?:\/\/note.toshiki\.dev\//g, '/')
const [_name, i] = id.split('/').slice(-2) const [_name, i] = id.split('/').slice(-2)
// convert img by applying regex // convert img by applying regex
@ -25,19 +25,22 @@ export function MarkdownTransform(): Plugin {
// } // }
// convert links to components // convert links to components
const linkRegex = /\[(.+?)\]\((.+?)\)/g // const linkRegex = /\[(.+?)\]\((.+?)\)/g;
let matches = linkRegex.exec(code) // let matches = linkRegex.exec(code);
while (matches) { // while (matches) {
const [text, link] = matches.slice(1) // const [text, link] = matches.slice(1);
code = code.replace(matches[0], `<CustomLink title="${text}" href="${link}" />`) // code = code.replace(
matches = linkRegex.exec(code) // matches[0],
} // `<CustomLink title="${text}" href="${link}" />`
// );
// matches = linkRegex.exec(code);
// }
// cut index.md // cut index.md
if (_name === 'docs' && i === 'index.md') return code if (_name === 'docs' && i === 'index.md') return code
const { footer } = await getDocsMarkdown() // const { footer } = await getDocsMarkdown()
code = replacer(code, footer, 'FOOTER', 'tail') // code = replacer(code, footer, 'FOOTER', 'tail')
const { readTime, words } = getReadingTime(code) const { readTime, words } = getReadingTime(code)
code = code.replace(/(#\s.+?\n)/, `$1\n\n<PageInfo readTime="${readTime}" words="${words}"/>\n`) code = code.replace(/(#\s.+?\n)/, `$1\n\n<PageInfo readTime="${readTime}" words="${words}"/>\n`)
@ -46,13 +49,13 @@ export function MarkdownTransform(): Plugin {
} }
} }
export async function getDocsMarkdown() { // export async function getDocsMarkdown() {
const CopyRightSection = ` // const CopyRightSection = `
<CopyRight/>` // <CopyRight/>`;
const footer = `${CopyRightSection}\n` // const footer = `${CopyRightSection}\n`;
return { // return {
footer, // footer,
} // };
} // }