From 68b02752cd22ea4a9f903613a910ad1809e1bfaa Mon Sep 17 00:00:00 2001 From: 0xB917 <50108258+kwaa@users.noreply.github.com> Date: Sun, 26 Dec 2021 21:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20fix=20typo=20&=20prettify?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdsvex.config.js | 47 +++++++++++++------------ src/lib/components/footer.svelte | 6 ++-- src/lib/config/date.ts | 2 +- svelte.config.js | 14 ++++---- urara/hello-world/toc-disabled/index.md | 2 +- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/mdsvex.config.js b/mdsvex.config.js index 1b19727f..7ef7a621 100644 --- a/mdsvex.config.js +++ b/mdsvex.config.js @@ -7,31 +7,34 @@ import { visit } from 'unist-util-visit' import { toString } from 'mdast-util-to-string' import { parse, join } from 'path' -const highlighter = async (code, lang) => `{@html \`${await shiki.getHighlighter({ theme: 'material-default' }).then(highlighter => - highlighter - .codeToHtml(code, { lang }) - .replace(/[{}`]/g, c => ({ '{': '{', '}': '}', '`': '`' }[c])) - .replace(/\\([trn])/g, '\$1') -)}\` }` +const highlighter = async (code, lang) => + `{@html \`${await shiki.getHighlighter({ theme: 'material-default' }).then(highlighter => + highlighter + .codeToHtml(code, { lang }) + .replace(/[{}`]/g, c => ({ '{': '{', '}': '}', '`': '`' }[c])) + .replace(/\\([trn])/g, '\$1') + )}\` }` -const remarkUraraFm = () => (tree, { data, filename }) => { - const filepath = filename.split('/src/routes')[1] - let { dir, name } = parse(filepath) - if (!data.fm) data.fm = {} - data.fm.slug = filepath - data.fm.path = join(dir, `/${name}`.replace('\/index', '').replace('\.svelte', '')) - if (data.fm?.toc !== false) { - let [slugs, toc] = [new Slugger(), []] - visit(tree, 'heading', node => { - toc.push({ - depth: node.depth, - title: toString(node), - slug: slugs.slug(toString(node)) +const remarkUraraFm = + () => + (tree, { data, filename }) => { + const filepath = filename.split('/src/routes')[1] + let { dir, name } = parse(filepath) + if (!data.fm) data.fm = {} + data.fm.slug = filepath + data.fm.path = join(dir, `/${name}`.replace('/index', '').replace('.svelte', '')) + if (data.fm?.toc !== false) { + let [slugs, toc] = [new Slugger(), []] + visit(tree, 'heading', node => { + toc.push({ + depth: node.depth, + title: toString(node), + slug: slugs.slug(toString(node)) + }) }) - }) - data.fm.toc = toc + data.fm.toc = toc + } } -} const remarkUraraSpoiler = () => tree => visit(tree, 'paragraph', node => { diff --git a/src/lib/components/footer.svelte b/src/lib/components/footer.svelte index b8b09b83..cf1e9308 100644 --- a/src/lib/components/footer.svelte +++ b/src/lib/components/footer.svelte @@ -5,7 +5,9 @@ export { className as class } -