46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import "./custom.css";
|
|
import "./style.css";
|
|
|
|
import DefaultTheme from "vitepress/theme";
|
|
// https://vitepress.dev/guide/custom-theme
|
|
import { h } from "vue";
|
|
|
|
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
|
|
import SentenceQuiz from "./components/SentenceQuiz.vue";
|
|
import TOC from "./components/TOC.vue";
|
|
|
|
import type { Theme } from "vitepress";
|
|
|
|
export default {
|
|
extends: DefaultTheme,
|
|
Layout: () => {
|
|
return h(DefaultTheme.Layout, null, {
|
|
// https://vitepress.dev/guide/extending-default-theme#layout-slots
|
|
});
|
|
},
|
|
enhanceApp({ app, router, siteData }) {
|
|
app.runWithContext(() => {
|
|
if (typeof window === "undefined") return;
|
|
window.document.addEventListener("click", (ev) => {
|
|
const { target } = ev;
|
|
if (!target || !(target instanceof HTMLAnchorElement)) return;
|
|
if (target.href.startsWith("https://")) {
|
|
ev.preventDefault();
|
|
if (
|
|
target.href.startsWith(
|
|
"https://resources.allsetlearning.com/chinese/grammar/",
|
|
)
|
|
)
|
|
return;
|
|
openUrl(target.href);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ...
|
|
app.component("SentenceQuiz", SentenceQuiz);
|
|
app.component("TOC", TOC);
|
|
},
|
|
} satisfies Theme;
|