add webview

This commit is contained in:
polv committed 2026-03-23 17:01:58 +07:00
1 parent b7090b6ed2
commit e3d06ebe9f
6 files changed
+803 -7

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"editor.tabSize": 2, "editor.tabSize": 2,
"json.schemaDownload.enable": false, // "json.schemaDownload.enable": false,
"[vue]": { "[vue]": {
"editor.formatOnSave": true, "editor.formatOnSave": true,
}, },
+1
View File
@@ -4,6 +4,7 @@ import { defineConfig } from "vitepress";
export default defineConfig({ export default defineConfig({
title: "zh grammar", title: "zh grammar",
description: "Chinese grammar excerpts and interactive app", description: "Chinese grammar excerpts and interactive app",
lang: "zh-CN",
themeConfig: { themeConfig: {
// https://vitepress.dev/reference/default-theme-config // https://vitepress.dev/reference/default-theme-config
outline: { outline: {
+8 -2
View File
@@ -4,8 +4,9 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "pnpm run dev --open", "start": "pnpm run dev:webview",
"dev": "vitepress dev docs", "dev:webview": "node --disable-warning=DEP0190 webview.js",
"dev:vp": "vitepress dev docs",
"build": "vitepress build docs", "build": "vitepress build docs",
"preview": "vitepress preview docs" "preview": "vitepress preview docs"
}, },
@@ -16,5 +17,10 @@
"dependencies": { "dependencies": {
"vitepress": "2.0.0-alpha.16", "vitepress": "2.0.0-alpha.16",
"vue": "^3.5.30" "vue": "^3.5.30"
},
"devDependencies": {
"concurrently": "^9.2.1",
"kill-port": "^2.0.1",
"webview-nodejs": "^0.4.3"
} }
} }
+767 -4
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -1,2 +1,3 @@
onlyBuiltDependencies: onlyBuiltDependencies:
- esbuild - esbuild
- libwebview-nodejs
+25
View File
@@ -0,0 +1,25 @@
const { Webview } = require("webview-nodejs");
const { spawn } = require("child_process");
const PORT = 5173;
const p = spawn("pnpm", ["vitepress", "dev", "--port", String(PORT), "docs"], {
shell: true,
stdio: "inherit",
});
const w = new Webview();
w.title(require("./package.json").name);
w.size(1920, 1280);
w.init(/* js */ `
document.addEventListener('click', (ev) => {
if (ev.target.matches('a')) {
const href = ev.target.href || '';
if (href.startsWith('https://')) ev.preventDefault();
}
})
`);
w.navigate(`http://localhost:${PORT}`);
w.show();
console.log(p.kill("SIGINT"));
require("kill-port")(PORT);