make patching more robust. backup original html and patch fresh on every container start.

This commit is contained in:
Nystik
2026-03-19 16:23:04 +01:00
parent 6a40fe344c
commit 2add5238b8
2 changed files with 19 additions and 14 deletions

View File

@@ -20,9 +20,6 @@ if [ ! -f "$OBSIDIAN_DIR/index.html" ]; then
/tmp/obsidian-pkg/opt/Obsidian/resources/obsidian.asar \
"$OBSIDIAN_DIR"
echo "[ignis] Patching..."
node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR"
rm -rf /tmp/obsidian.deb /tmp/obsidian-deb /tmp/obsidian-pkg
echo "[ignis] Obsidian v${OBSIDIAN_VERSION} ready."
@@ -30,7 +27,8 @@ else
echo "[ignis] Obsidian already set up."
fi
# Always copy latest bundles (they may have been updated between rebuilds)
# Always patch and copy latest bundles (they may have been updated between rebuilds)
node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR"
cp /app/dist/ignis-ui.js "$OBSIDIAN_DIR/ignis-ui.js"
cp /app/dist/shim-loader.js "$OBSIDIAN_DIR/shim-loader.js"
cp /app/images/favicon.png "$OBSIDIAN_DIR/favicon.png"

View File

@@ -14,11 +14,21 @@ if (!asarDir) {
}
function patchHtml(filePath) {
if (!fs.existsSync(filePath)) {
const backupPath = filePath + ".orig";
if (!fs.existsSync(filePath) && !fs.existsSync(backupPath)) {
console.warn(`[patch] Skipping (not found): ${filePath}`);
return;
}
// Create backup of the original on first patch; restore from it on subsequent runs
if (!fs.existsSync(backupPath)) {
fs.copyFileSync(filePath, backupPath);
console.log(`[patch] Backed up original: ${backupPath}`);
} else {
fs.copyFileSync(backupPath, filePath);
}
let html = fs.readFileSync(filePath, "utf-8");
// Remove CSP meta tag
@@ -27,18 +37,15 @@ function patchHtml(filePath) {
"\n",
);
// Inject favicon into <head>
html = html.replace(
"</head>",
' <link rel="icon" type="image/png" href="favicon.png">\n</head>',
);
// Inject ignis assets before the first <script> tag
const ignisBlock =
' <link rel="icon" type="image/png" href="favicon.png">\n' +
' <script type="text/javascript" src="ignis-ui.js"></script>\n' +
' <script type="text/javascript" src="shim-loader.js"></script>\n';
// Inject ignis-ui and shim-loader before the first <script> tag
html = html.replace(
'<script type="text/javascript"',
'<script type="text/javascript" src="ignis-ui.js"></script>\n' +
'<script type="text/javascript" src="shim-loader.js"></script>\n' +
'<script type="text/javascript"',
ignisBlock + '<script type="text/javascript"',
);
fs.writeFileSync(filePath, html);