diff --git a/generator/base-css-generator.ts b/generator/base-css-generator.ts deleted file mode 100644 index d9bdf30..0000000 --- a/generator/base-css-generator.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { PluginOption } from 'vite' -import fs from 'fs' -import { SiteConfiguration } from '../src/site' - -export default function newsListGenerator(): PluginOption { - const virtualModuleId = 'virtual:base.css' - const resolvedVirtualModuleId = '\0' + virtualModuleId - - return { - name: 'base-css-generator', - resolveId(id) { - if (id === virtualModuleId) { - return resolvedVirtualModuleId - } - }, - load(id) { - if (id === resolvedVirtualModuleId) { - const base = fs.readFileSync('./src/assets/base.css', 'utf-8') - return base - .replace( - '/* warning text */', - SiteConfiguration.markdown.container.warningLabel ?? 'WARNING', - ) - .replace('/* error text */', SiteConfiguration.markdown.container.errorLabel ?? 'ERROR') - .replace('/* info text */', SiteConfiguration.markdown.container.infoLabel ?? 'INFO') - } - }, - handleHotUpdate({ server, file }) { - if (file.includes('src/assets/base.css')) { - const thisModule = server.moduleGraph.getModuleById(resolvedVirtualModuleId) - if (thisModule) return [thisModule] - } - }, - } -} diff --git a/generator/content-generator.ts b/generator/content-generator.ts index 8671e29..945b395 100644 --- a/generator/content-generator.ts +++ b/generator/content-generator.ts @@ -1,5 +1,5 @@ import { PluginOption } from 'vite' -import * as mdit from 'markdown-it' +import MarkdownIt, * as mdit from 'markdown-it' import Token from 'markdown-it/lib/token.mjs' import matter from 'gray-matter' import Shiki from '@shikijs/markdown-it' @@ -27,9 +27,9 @@ const md = mdit class: 'header-anchor', }), }) - .use(MarkdownItContainer, 'warning') - .use(MarkdownItContainer, 'error') - .use(MarkdownItContainer, 'info') + .use(createContainer, 'warning', SiteConfiguration.markdown.container.warningLabel || 'WARNING') + .use(createContainer, 'error', SiteConfiguration.markdown.container.errorLabel || 'ERROR') + .use(createContainer, 'info', SiteConfiguration.markdown.container.infoLabel || 'INFO') .use(MarkdownItContainer, 'expander', { render: (tokens: Token[], idx: number) => { if (tokens[idx].nesting === 1) { @@ -103,3 +103,15 @@ function extractExpanderTitle(info: string) { if (result) return result else return SiteConfiguration.markdown.container.expanderLabel ?? 'MORE' } + +function createContainer(md: MarkdownIt, klass: string, title: string) { + MarkdownItContainer(md, klass, { + render: (tokens: Token[], idx: number) => { + console.log(md.renderer.renderAttrs(tokens[idx])) + console.log(tokens[idx]) + return tokens[idx].nesting === 1 + ? `
${title}
\n` + : '