2023-07-04 21:33:22 +08:00
|
|
|
import adapter from "@sveltejs/adapter-static";
|
2024-04-25 06:55:14 +08:00
|
|
|
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
|
2023-11-22 06:06:17 +08:00
|
|
|
import { redirects } from "./src/routes/redirects.js";
|
2024-02-29 02:05:48 +08:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
import { fileURLToPath } from "url";
|
2024-05-30 06:26:54 +08:00
|
|
|
import { mdsvex, code_highlighter } from "mdsvex";
|
|
|
|
import slugify from "@sindresorhus/slugify";
|
|
|
|
import { toString as to_string } from "hast-util-to-string";
|
2023-08-11 22:54:56 +08:00
|
|
|
|
2024-02-29 02:05:48 +08:00
|
|
|
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
let version = "4.0.0";
|
|
|
|
|
|
|
|
const get_version = async () => {
|
|
|
|
try {
|
|
|
|
const versionPath = path.join(
|
|
|
|
currentDir,
|
|
|
|
"src",
|
|
|
|
"lib",
|
|
|
|
"json",
|
|
|
|
"version.json"
|
|
|
|
);
|
|
|
|
if (!fs.existsSync(versionPath)) {
|
|
|
|
console.error(
|
|
|
|
"Using fallback version 4.0.0 as version.json was not found. Run `generate_jsons/generate.py` to get the latest version."
|
|
|
|
);
|
|
|
|
return version;
|
|
|
|
} else {
|
|
|
|
const versionData = fs.readFileSync(versionPath, "utf8");
|
|
|
|
const versionJson = JSON.parse(versionData);
|
|
|
|
version = versionJson.version;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(
|
|
|
|
"Using fallback version 4.0.0 as version.json was not found. Run `generate_jsons/generate.py` to get the latest version."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return version;
|
|
|
|
};
|
|
|
|
|
|
|
|
get_version();
|
2023-07-04 21:33:22 +08:00
|
|
|
|
2024-05-30 06:26:54 +08:00
|
|
|
export function make_slug_processor() {
|
|
|
|
return function (name) {
|
|
|
|
const slug = slugify(name, { separator: "-", lowercase: true });
|
|
|
|
return slug;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const doc_slug = [];
|
|
|
|
function plugin() {
|
|
|
|
const get_slug = make_slug_processor();
|
|
|
|
return function transform(tree) {
|
|
|
|
tree.children.forEach((n) => {
|
|
|
|
if (n.type === "element" && ["h3"].includes(n.tagName)) {
|
|
|
|
const str_of_heading = to_string(n);
|
|
|
|
const slug = get_slug(str_of_heading);
|
|
|
|
|
|
|
|
doc_slug.push({
|
|
|
|
text: str_of_heading,
|
|
|
|
href: `#${slug}`,
|
|
|
|
level: parseInt(n.tagName.replace("h", ""))
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!n.children) n.children = [];
|
|
|
|
n.properties.className = ["group", "header-tag"];
|
|
|
|
n.properties.id = [slug];
|
|
|
|
n.children.push({
|
|
|
|
type: "element",
|
|
|
|
tagName: "a",
|
|
|
|
properties: {
|
|
|
|
href: `#${slug}`,
|
|
|
|
className: ["invisible", "group-hover-visible"]
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
type: "element",
|
|
|
|
tagName: "img",
|
|
|
|
properties: {
|
|
|
|
src: "https://raw.githubusercontent.com/gradio-app/gradio/main/js/_website/src/lib/assets/img/anchor.svg",
|
|
|
|
className: ["anchor-img-small"]
|
|
|
|
},
|
|
|
|
children: []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-04 21:33:22 +08:00
|
|
|
/** @type {import('@sveltejs/kit').Config} */
|
|
|
|
const config = {
|
2024-05-30 06:26:54 +08:00
|
|
|
extensions: [".svelte", ".svx"],
|
|
|
|
preprocess: [
|
|
|
|
mdsvex({
|
|
|
|
extensions: [".svx"],
|
|
|
|
rehypePlugins: [plugin],
|
|
|
|
highlight: {
|
|
|
|
highlighter: async (code, lang) => {
|
|
|
|
const h = (await code_highlighter(code, lang, "")).replace(
|
|
|
|
/\{@html `|`\}/g,
|
|
|
|
""
|
|
|
|
);
|
|
|
|
return `<div class="codeblock"><CopyButton content={\`${code}\`}/>${h}</div>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vitePreprocess()
|
|
|
|
],
|
2023-07-04 21:33:22 +08:00
|
|
|
kit: {
|
2023-08-11 22:54:56 +08:00
|
|
|
prerender: {
|
2023-10-31 12:46:02 +08:00
|
|
|
crawl: true,
|
2023-08-11 22:54:56 +08:00
|
|
|
entries: [
|
|
|
|
"*",
|
|
|
|
`/${version}/docs`,
|
|
|
|
`/${version}/guides`,
|
|
|
|
`/main/docs`,
|
2023-10-31 12:46:02 +08:00
|
|
|
`/main/guides`,
|
2024-04-24 04:33:45 +08:00
|
|
|
`/docs/js`,
|
|
|
|
`/docs/js/storybook`,
|
|
|
|
`/docs/js/`,
|
2023-11-22 06:06:17 +08:00
|
|
|
`/main/docs/js`,
|
2023-11-23 08:26:33 +08:00
|
|
|
`/main/docs/js/storybook`,
|
|
|
|
`/main/docs/js/`,
|
2024-10-10 02:52:12 +08:00
|
|
|
...Object.keys(redirects),
|
|
|
|
`/4.44.1/docs`,
|
|
|
|
`/4.44.1/guides`
|
2024-05-30 06:26:54 +08:00
|
|
|
],
|
|
|
|
handleMissingId: "warn"
|
2023-08-11 22:54:56 +08:00
|
|
|
},
|
|
|
|
files: {
|
|
|
|
lib: "src/lib"
|
|
|
|
},
|
2024-10-10 02:52:12 +08:00
|
|
|
adapter: adapter({
|
|
|
|
fallback: "404.html"
|
|
|
|
}),
|
2024-08-10 08:20:12 +08:00
|
|
|
paths: {
|
|
|
|
relative: false
|
|
|
|
}
|
2023-07-04 21:33:22 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default config;
|