do11y 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/docs/html/plugin.js
CHANGED
|
@@ -2,8 +2,9 @@ import { join } from "node:path";
|
|
|
2
2
|
import { writeFileSync } from "node:fs";
|
|
3
3
|
import { output } from "../files.js";
|
|
4
4
|
import { render } from "./render.js";
|
|
5
|
+
import { getUserViteConfig } from "../vite-config.js";
|
|
5
6
|
export const indexHtml = (folder, key) => ({
|
|
6
|
-
writeBundle(_, bundle) {
|
|
7
|
+
async writeBundle(_, bundle) {
|
|
7
8
|
const chunk = Object.values(bundle).find((chunk) => {
|
|
8
9
|
return chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId?.endsWith(`${key}.js`);
|
|
9
10
|
});
|
|
@@ -11,20 +12,22 @@ export const indexHtml = (folder, key) => ({
|
|
|
11
12
|
throw new Error(`Failed to create HTML file for ${key}.`);
|
|
12
13
|
}
|
|
13
14
|
const stylesheets = Array.from(chunk.viteMetadata?.importedCss || []);
|
|
14
|
-
const
|
|
15
|
+
const { base } = await getUserViteConfig("build");
|
|
16
|
+
const html = render(base, chunk.fileName, stylesheets);
|
|
15
17
|
writeFileSync(join(output, `${key}.html`), html);
|
|
16
18
|
if (key === "index") {
|
|
17
19
|
writeFileSync(join(output, "404.html"), html);
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
|
-
configureServer(server) {
|
|
22
|
+
async configureServer(server) {
|
|
21
23
|
const bundle = join(folder, `${key}.js`);
|
|
22
24
|
const sandboxBundle = join(folder, "sandbox.js");
|
|
23
25
|
server.middlewares.use(async (req, res, next) => {
|
|
24
26
|
if (!req.url || req.method !== "GET" || !req.headers.accept?.includes("text/html")) {
|
|
25
27
|
return next();
|
|
26
28
|
}
|
|
27
|
-
const
|
|
29
|
+
const { base } = await getUserViteConfig("build");
|
|
30
|
+
const html = render(base, `/@fs/${req.url?.startsWith("/sandbox") ? sandboxBundle : bundle}`);
|
|
28
31
|
const transformedHtml = await server.transformIndexHtml(req.url, html);
|
|
29
32
|
res.statusCode = 200;
|
|
30
33
|
res.setHeader("content-type", "text/html; charset=UTF-8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const render: (script: string, stylesheets?: string[]) => string;
|
|
1
|
+
export declare const render: (base: string | undefined, script: string, stylesheets?: string[]) => string;
|
package/dist/docs/html/render.js
CHANGED
|
@@ -2,17 +2,17 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { JSDOM } from "jsdom";
|
|
4
4
|
const template = readFileSync(join(import.meta.dirname, "index.html"), "utf-8");
|
|
5
|
-
export const render = (script, stylesheets = []) => {
|
|
5
|
+
export const render = (base = "", script, stylesheets = []) => {
|
|
6
6
|
const jsdom = new JSDOM(template);
|
|
7
7
|
const scriptElement = jsdom.window.document.createElement("script");
|
|
8
8
|
scriptElement.setAttribute("type", "module");
|
|
9
|
-
scriptElement.setAttribute("src", script);
|
|
9
|
+
scriptElement.setAttribute("src", `${base}${script}`);
|
|
10
10
|
jsdom.window.document.documentElement.appendChild(scriptElement);
|
|
11
11
|
for (const stylesheet of stylesheets) {
|
|
12
12
|
const linkElement = jsdom.window.document.createElement("link");
|
|
13
13
|
linkElement.setAttribute("as", "style");
|
|
14
14
|
linkElement.setAttribute("rel", "preload stylesheet");
|
|
15
|
-
linkElement.setAttribute("href", stylesheet);
|
|
15
|
+
linkElement.setAttribute("href", `${base}${stylesheet}`);
|
|
16
16
|
jsdom.window.document.head.appendChild(linkElement);
|
|
17
17
|
}
|
|
18
18
|
return jsdom.serialize();
|