build with redirected images
This commit is contained in:
1 parent
5a8edf9330
commit
f4a0c8d883
4 files changed
+59
-19
No files matched your search
@@ -1 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
.env
|
||||||
Vendored
+4
@@ -6,6 +6,10 @@
|
|||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
"editor.maxTokenizationLineLength": 2500,
|
"editor.maxTokenizationLineLength": 2500,
|
||||||
},
|
},
|
||||||
|
"[typescript]": {
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
},
|
||||||
"[vue]": {
|
"[vue]": {
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
|||||||
+53
-19
@@ -1,35 +1,71 @@
|
|||||||
import { defineConfig } from 'vitepress'
|
import { defineConfig } from "vitepress";
|
||||||
|
import { execSync } from "node:child_process";
|
||||||
|
|
||||||
const host = process.env.TAURI_DEV_HOST;
|
const host = process.env.TAURI_DEV_HOST;
|
||||||
|
|
||||||
|
const {
|
||||||
|
IMG_ORIGIN = `https://git.polv.cc/polv/yt2press/raw/branch/${
|
||||||
|
execSync("git branch --show-current").toString().trimEnd()
|
||||||
|
}/docs/public`,
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
// https://vitepress.dev/reference/site-config
|
// https://vitepress.dev/reference/site-config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
title: "yt2press",
|
title: "yt2press",
|
||||||
description: "video to vitepress",
|
description: "video to vitepress",
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
// https://vitepress.dev/reference/default-theme-config
|
// https://vitepress.dev/reference/default-theme-config
|
||||||
nav: [
|
nav: [{ text: "Home", link: "/" }],
|
||||||
{ text: 'Home', link: '/' },
|
|
||||||
],
|
|
||||||
|
|
||||||
sidebar: [
|
sidebar: [
|
||||||
{
|
{
|
||||||
text: 'Preview',
|
text: "Preview",
|
||||||
// items: [
|
// items: [
|
||||||
// { text: 'Markdown Examples', link: '/markdown-examples' },
|
// { text: 'Markdown Examples', link: '/markdown-examples' },
|
||||||
// { text: 'Runtime API Examples', link: '/api-examples' }
|
// { text: 'Runtime API Examples', link: '/api-examples' }
|
||||||
// ]
|
// ]
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
socialLinks: [
|
socialLinks: [
|
||||||
{ icon: 'github', link: 'https://git.polv.cc/polv/yt2press' }
|
{ icon: "github", link: "https://git.polv.cc/polv/yt2press" },
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
markdown: {
|
markdown: {
|
||||||
image: {
|
image: {
|
||||||
lazyLoading: true,
|
lazyLoading: true,
|
||||||
},
|
},
|
||||||
|
config(md) {
|
||||||
|
// production-only gate
|
||||||
|
const isProd =
|
||||||
|
process.env.NODE_ENV === "production" ||
|
||||||
|
process.env.VITEPRESS_ENV === "production"; // extra safety
|
||||||
|
|
||||||
|
if (isProd) {
|
||||||
|
md.core.ruler.push("rewrite-image-urls", (state) => {
|
||||||
|
if (!state.tokens) return;
|
||||||
|
|
||||||
|
for (const token of state.tokens) {
|
||||||
|
if (token.type !== "inline") continue;
|
||||||
|
|
||||||
|
for (const child of token.children ?? []) {
|
||||||
|
// images: 
|
||||||
|
if (
|
||||||
|
child.type === "image" &&
|
||||||
|
typeof child.attrGet("src") === "string"
|
||||||
|
) {
|
||||||
|
const src = child.attrGet("src");
|
||||||
|
|
||||||
|
// rewrite only /images/* (adjust if your paths differ)
|
||||||
|
if (src && src.startsWith("/images/")) {
|
||||||
|
child.attrSet("src", `${IMG_ORIGIN}${src}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
clearScreen: false,
|
clearScreen: false,
|
||||||
@@ -42,28 +78,26 @@ export default defineConfig({
|
|||||||
host: host || false,
|
host: host || false,
|
||||||
watch: {
|
watch: {
|
||||||
// tell vite to ignore watching `src-tauri`
|
// tell vite to ignore watching `src-tauri`
|
||||||
ignored: ['**/src-tauri/**'],
|
ignored: ["**/src-tauri/**"],
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
'/socket': {
|
"/socket": {
|
||||||
target: 'ws://localhost:8080',
|
target: "ws://localhost:8080",
|
||||||
ws: true,
|
ws: true,
|
||||||
rewriteWsOrigin: true,
|
rewriteWsOrigin: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Env variables starting with the item of `envPrefix` will be exposed in tauri's source code through `import.meta.env`.
|
// Env variables starting with the item of `envPrefix` will be exposed in tauri's source code through `import.meta.env`.
|
||||||
envPrefix: ['VITE_', 'TAURI_ENV_*'],
|
envPrefix: ["VITE_", "TAURI_ENV_*"],
|
||||||
build: {
|
build: {
|
||||||
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
|
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
|
||||||
target:
|
target:
|
||||||
process.env.TAURI_ENV_PLATFORM == 'windows'
|
process.env.TAURI_ENV_PLATFORM == "windows" ? "chrome105" : "safari13",
|
||||||
? 'chrome105'
|
|
||||||
: 'safari13',
|
|
||||||
// don't minify for debug builds
|
// don't minify for debug builds
|
||||||
minify: !process.env.TAURI_ENV_DEBUG ? 'esbuild' : false,
|
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
|
||||||
// produce sourcemaps for debug builds
|
// produce sourcemaps for debug builds
|
||||||
sourcemap: !!process.env.TAURI_ENV_DEBUG,
|
sourcemap: !!process.env.TAURI_ENV_DEBUG,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
@@ -14,3 +14,4 @@ async function removeAllVideos(dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await removeAllVideos("docs/.vitepress/dist");
|
await removeAllVideos("docs/.vitepress/dist");
|
||||||
|
await fs.rm("docs/.vitepress/dist/images", { recursive: true });
|
||||||
Reference in new issue
Block a user