link opening in app

This commit is contained in:
polv committed 2026-04-16 17:34:11 +07:00
1 parent 279b5886b1
commit ff98be7d7c
12 files changed
+560 -33

No files matched your search

+22 -1
View File
@@ -1,14 +1,17 @@
import "./style.css";
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: () => {
@@ -17,6 +20,24 @@ export default {
});
},
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);