Skip to content

Commit

Permalink
fix(theme): fix emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
taskylizard committed Jan 23, 2024
1 parent b7e3e03 commit a18bd9d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
36 changes: 21 additions & 15 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ import { withPwa } from "@vite-pwa/vitepress";
import fg from "fast-glob";
import { resolve } from "node:path";
import { FileSystemIconLoader } from "@iconify/utils/lib/loader/node-loaders";
import { icons } from "@iconify-json/octicon";
import { icons as octicon } from "@iconify-json/octicon";
import { icons as twemoji } from "@iconify-json/twemoji";

const defs = Object.fromEntries(
Object.entries(icons.icons).map(([key]) => {
return [key, ""];
}),
);

const shortcuts = Object.fromEntries(
Object.entries(icons.aliases || {}).map(([key, value]) => {
return [key, value.parent];
}),
);
const defs = {
...Object.fromEntries(
Object.entries(octicon.icons).map(([key]) => {
return [`octicon-${key}`, ""];
}),
),
...Object.fromEntries(
Object.entries(twemoji.icons).map(([key]) => {
return [key, ""];
}),
),
};

function emojiRender(md: MarkdownRenderer) {
md.renderer.rules.emoji = (token, idx) => {
return `<span class="i-octicon-${token[idx].markup}"></span>`;
md.renderer.rules.emoji = (tokens, idx) => {
if (tokens[idx].markup.startsWith("octicon-")) {
return `<span class="i-${tokens[idx].markup}"></span>`;
}
return `<span class="i-twemoji-${tokens[idx].markup}"></span>`;
};
}

Expand Down Expand Up @@ -97,7 +102,7 @@ export default withPwa(
generateImages(context);
},
markdown: {
emoji: { defs, shortcuts },
emoji: { defs },
config(md) {
md.use(emojiRender);
md.use(imgLazyload);
Expand All @@ -107,6 +112,7 @@ export default withPwa(
},
},
vite: {
optimizeDeps: { exclude: ["workbox-window"] },
plugins: [
UnoCSS({
presets: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@iconify-json/mdi": "^1.1.55",
"@iconify-json/octicon": "^1.1.52",
"@iconify-json/simple-icons": "^1.1.76",
"@iconify-json/twemoji": "^1.1.15",
"@iconify/utils": "^2.1.11",
"@types/node": "^20.8.9",
"prettier": "^3.2.1"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a18bd9d

Please sign in to comment.