feat(theme): replace with twemojis

This commit is contained in:
taskylizard 2024-01-24 07:53:57 +00:00
parent 4cead6f935
commit 0e69461b59
No known key found for this signature in database
GPG Key ID: 1820131ED1A24120
4 changed files with 56 additions and 2 deletions

4
.github/replace.py vendored
View File

@ -53,6 +53,10 @@ def general(text: str):
text = re.sub("## ▷", "###", text)
text = re.sub("####", "###", text)
text = re.sub("", ":star:", text)
text = re.sub("🌐", ":globe-with-meridians: ", text)
text = re.sub("↪️ ", ":repeat-button: ", text)
text = re.sub(
r"^\*\*Note\*\* - (.+)$", r":::tip\n\1\n:::", text, flags=re.MULTILINE
)

View File

@ -5,6 +5,7 @@ import { commitRef, feedback, meta, search, sidebar, socialLinks } from "./const
import { generateImages, generateMeta, generateFeed } from "./hooks";
import { toggleStarredPlugin } from "./markdown/toggleStarred";
import { base64DecodePlugin } from "./markdown/base64";
import { movePlugin, emojiRender, defs } from "./markdown/emoji";
const baseUrl = process.env.GITHUB_ACTIONS ? "/FMHYedit" : "/";
export default defineConfig({
@ -41,10 +42,17 @@ export default defineConfig({
.finally(() => consola.success("Success!"));
},
vite: {
optimizeDeps: { exclude: ["workbox-window"] },
plugins: [
UnoCSS({
configFile: "../unocss.config.ts",
}),
{
name: "custom:adjust-order",
configResolved(c) {
movePlugin(c.plugins as any, "vitepress", "before", "unocss:transformers:pre");
},
},
],
build: {
// Shut the fuck up
@ -52,7 +60,9 @@ export default defineConfig({
},
},
markdown: {
emoji: { defs },
config(md) {
md.use(emojiRender);
md.use(toggleStarredPlugin);
md.use(base64DecodePlugin);
},

View File

@ -0,0 +1,39 @@
import { icons as twemoji } from "@iconify-json/twemoji";
import type { MarkdownRenderer } from "vitepress";
export const defs = {
...Object.fromEntries(
Object.entries(twemoji.icons).map(([key]) => {
return [key, ""];
}),
),
};
export function emojiRender(md: MarkdownRenderer) {
md.renderer.rules.emoji = (tokens, idx) => {
return `<span class="i-twemoji-${tokens[idx].markup}"></span>`;
};
}
export function movePlugin(
plugins: { name: string }[],
pluginAName: string,
order: "before" | "after",
pluginBName: string,
) {
const pluginBIndex = plugins.findIndex((p) => p.name === pluginBName);
if (pluginBIndex === -1) return;
const pluginAIndex = plugins.findIndex((p) => p.name === pluginAName);
if (pluginAIndex === -1) return;
if (order === "before" && pluginAIndex > pluginBIndex) {
const pluginA = plugins.splice(pluginAIndex, 1)[0];
plugins.splice(pluginBIndex, 0, pluginA);
}
if (order === "after" && pluginAIndex < pluginBIndex) {
const pluginA = plugins.splice(pluginAIndex, 1)[0];
plugins.splice(pluginBIndex, 0, pluginA);
}
}

View File

@ -1,6 +1,7 @@
{
"extends": "./.nitro/types/tsconfig.json",
"compilerOptions": {
"verbatimModuleSyntax": true
}
"verbatimModuleSyntax": true,
},
"include": ["./.vitepress/"],
}