mirror of
https://github.com/storytold/spark.git
synced 2026-10-09 00:09:53 +00:00
Rename mkdocs assets directory to static on deployment to prevent path collision with assets directory
This commit is contained in:
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
|
||||
import { rm } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
const siteRemoteURL = "git@github.com:sparkjs-dev/sparkjs-dev.github.io.git";
|
||||
const siteRemoteURL = "git@github.com:sparkjsdev/sparkjsdev.github.io.git";
|
||||
const siteRepoDir = "site-repo";
|
||||
const siteBuild = "site";
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import {
|
||||
readFileSync,
|
||||
readdirSync,
|
||||
renameSync,
|
||||
statSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { extname, join } from "node:path";
|
||||
|
||||
const siteDirectory = "site";
|
||||
const oldAssets = join(siteDirectory, "assets");
|
||||
const newAssets = join(siteDirectory, "static");
|
||||
|
||||
// Rename assets directory
|
||||
console.log(`Renaming ${oldAssets} → ${newAssets}...`);
|
||||
renameSync(oldAssets, newAssets);
|
||||
replaceInHtmlFiles(siteDirectory);
|
||||
|
||||
function replaceInHtmlFiles(dir) {
|
||||
for (const entry of readdirSync(dir)) {
|
||||
const fullPath = join(dir, entry);
|
||||
const stat = statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
replaceInHtmlFiles(fullPath);
|
||||
} else if (stat.isFile() && extname(fullPath) === ".html") {
|
||||
const html = readFileSync(fullPath, "utf-8");
|
||||
|
||||
// Replace relative/local asset references ONLY (exclude external URLs like https://sparkjs.dev/..)
|
||||
const updated = html.replace(
|
||||
/(["'(=])((?:\.\.\/)*|\.\/|\/)assets\//g,
|
||||
(_, prefix, rel) => `${prefix}${rel}static/`,
|
||||
);
|
||||
if (updated !== html) {
|
||||
writeFileSync(fullPath, updated);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user