feat(docs): optimize mobile layout and localized metadata

This commit is contained in:
t8y2
2026-07-31 20:19:30 +08:00
parent c43e8455c4
commit ce3bb09796
28 changed files with 909 additions and 396 deletions
+7 -7
View File
@@ -3,8 +3,6 @@ import { resolve, relative } from "path";
const OUT_DIR = resolve(import.meta.dirname, "../out");
const SITE_URL = "https://dbxio.com";
const TODAY = new Date().toISOString().split("T")[0];
const EXCLUDE = new Set(["index.html", "404.html", "_not-found.html"]);
function* walkDir(dir) {
@@ -51,9 +49,8 @@ const urls = [];
const seen = new Set();
for (const [, langs] of pagesByPath) {
const primary = langs.en || langs.cn;
if (!primary || seen.has(primary)) continue;
seen.add(primary);
const localizedPages = [langs.en, langs.cn].filter(Boolean);
if (localizedPages.length === 0) continue;
const altLinks = [];
if (langs.en) {
@@ -67,7 +64,11 @@ for (const [, langs] of pagesByPath) {
altLinks.push({ lang: "x-default", href: `${SITE_URL}${langs.en}` });
}
urls.push({ loc: `${SITE_URL}${primary}`, lastmod: TODAY, altLinks });
for (const localizedPage of localizedPages) {
if (seen.has(localizedPage)) continue;
seen.add(localizedPage);
urls.push({ loc: `${SITE_URL}${localizedPage}`, altLinks });
}
}
const sitemapXml = `<?xml version="1.0" encoding="UTF-8"?>
@@ -78,7 +79,6 @@ ${urls
(entry) =>
` <url>
<loc>${entry.loc}</loc>
<lastmod>${entry.lastmod}</lastmod>
${entry.altLinks.map((alt) => ` <xhtml:link rel="alternate" hreflang="${alt.lang}" href="${alt.href}" />`).join("\n")}
</url>`,
)
+52 -1
View File
@@ -1,5 +1,5 @@
import { readdir, readFile } from "node:fs/promises";
import { extname, join, relative } from "node:path";
import { extname, join, relative, sep } from "node:path";
import { fileURLToPath } from "node:url";
const outputDirectory = fileURLToPath(new URL("../out/", import.meta.url));
@@ -36,3 +36,54 @@ if (violations.length > 0) {
}
console.log(`Static export verified: ${files.length} files contain no GitHub API endpoints.`);
const requiredContent = [
{ file: "en.html", includes: ['<html lang="en"', '"@type":"SoftwareApplication"'] },
{ file: "cn.html", includes: ['<html lang="zh-CN"', '"@type":"SoftwareApplication"'] },
{ file: "llms.txt", includes: ["70+ database", "20 MB", "Apache-2.0"] },
];
for (const requirement of requiredContent) {
const content = await readFile(join(outputDirectory, requirement.file), "utf8");
for (const expected of requirement.includes) {
if (!content.includes(expected)) {
throw new Error(`${requirement.file} is missing required static content: ${expected}`);
}
}
if (content.includes('"potentialAction"')) {
throw new Error(`${requirement.file} advertises a search action that the static site does not provide.`);
}
}
console.log("Static export metadata verified for language, software schema, and llms.txt accuracy.");
const localizedHtmlFiles = files.filter(
(file) =>
extname(file) === ".html" &&
["en", "cn"].some(
(lang) => file === join(outputDirectory, `${lang}.html`) || file.startsWith(`${join(outputDirectory, lang)}${sep}`),
),
);
for (const file of localizedHtmlFiles) {
const content = await readFile(file, "utf8");
const relativePath = relative(outputDirectory, file);
for (const landmark of ["<main", "<h1"]) {
if (!content.includes(landmark)) {
throw new Error(`${relativePath} is missing required semantic landmark: ${landmark}>`);
}
}
}
console.log(`Static export semantics verified for ${localizedHtmlFiles.length} localized pages.`);
const sitemap = await readFile(join(outputDirectory, "sitemap.xml"), "utf8");
for (const localizedHome of ["https://dbxio.com/en", "https://dbxio.com/cn"]) {
if (!sitemap.includes(`<loc>${localizedHome}</loc>`)) {
throw new Error(`sitemap.xml is missing localized URL: ${localizedHome}`);
}
}
console.log("Static export sitemap verified with independent English and Chinese URLs.");