[object Object]

← back to Dw Fleet Registry

fix-header-inject: re-inject dw-header before real </body> (was trapped in a doc-comment on 51/65 sites → header rebuild was inert)

2cf83545f83501cc160a45d536c88d18921b882c · 2026-06-01 15:45:02 -0700 · Steve Abrams

Files touched

Diff

commit 2cf83545f83501cc160a45d536c88d18921b882c
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon Jun 1 15:45:02 2026 -0700

    fix-header-inject: re-inject dw-header before real </body> (was trapped in a doc-comment on 51/65 sites → header rebuild was inert)
---
 fix-header-inject.mjs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/fix-header-inject.mjs b/fix-header-inject.mjs
new file mode 100644
index 0000000..9d42c3f
--- /dev/null
+++ b/fix-header-inject.mjs
@@ -0,0 +1,58 @@
+#!/usr/bin/env node
+// FIX: the fanout injected dw-header before the FIRST '</body>' — which on many sites
+// is a fake </body> inside a doc-comment ("Inject before … </body> in every DW-family
+// sister site."). Result: the dw-header <script> tags sit INSIDE the comment → never run
+// → old header shows. This removes the mis-placed block and re-injects it before the
+// REAL final </body>, outside any comment. Preserves each site's existing DwHeaderConfig.
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import { execSync } from 'node:child_process';
+
+const PROJECTS = path.join(os.homedir(), 'Projects');
+const targets = fs.readFileSync('/tmp/fleet-targets.txt', 'utf8').split('\n').filter(Boolean);
+const sh = (c, cwd) => { try { return execSync(c, { cwd, stdio: ['ignore','pipe','pipe'] }).toString().trim(); } catch { return null; } };
+
+let fixed = 0, ok = 0;
+for (const slug of targets) {
+  const idx = path.join(PROJECTS, slug, 'public', 'index.html');
+  if (!fs.existsSync(idx)) continue;
+  let html = fs.readFileSync(idx, 'utf8');
+  if (!html.includes('/dw-header.js')) continue;
+
+  // preserve the existing per-site config
+  const cfgM = html.match(/<script>\s*window\.DwHeaderConfig=\{[\s\S]*?\};?\s*<\/script>/);
+  const cfg = cfgM ? cfgM[0] : null;
+
+  // is it already correctly placed? (script tag appears AFTER the last real </body>-12 chars, i.e. just before final </body>, and NOT inside a comment)
+  const lastBody = html.lastIndexOf('</body>');
+  const scriptIdx = html.lastIndexOf('<script src="/dw-header.js"');
+  const alreadyOk = scriptIdx > 0 && scriptIdx < lastBody && (lastBody - scriptIdx) < 400 && !insideComment(html, scriptIdx);
+  if (alreadyOk) { ok++; continue; }
+
+  // strip every existing config script + dw-header script tag (wherever they are, incl. inside the comment)
+  html = html.replace(/<script>\s*window\.DwHeaderConfig=\{[\s\S]*?\};?\s*<\/script>\s*/g, '');
+  html = html.replace(/<script src="\/dw-header\.js"[^>]*><\/script>\s*/g, '');
+
+  // re-inject before the REAL final </body>
+  const cfgBlock = (cfg || `<script>window.DwHeaderConfig={siteName:${JSON.stringify(slug)}};</script>`);
+  const inject = `${cfgBlock}\n<script src="/dw-header.js" defer></script>\n`;
+  const lb = html.lastIndexOf('</body>');
+  if (lb < 0) { console.log(`  ${slug}: no </body>?! skipped`); continue; }
+  html = html.slice(0, lb) + inject + html.slice(lb);
+
+  fs.writeFileSync(idx, html);
+  const dir = path.join(PROJECTS, slug);
+  sh('git checkout -B style-rebuild-pilot', dir);
+  sh('git add public/index.html', dir);
+  const c = sh(`git -c user.email="steve@designerwallcoverings.com" -c user.name="Steve Abrams" commit -q -m "FIX: dw-header was injected inside a doc-comment (never ran); re-inject before the real </body>" && git rev-parse --short HEAD`, dir);
+  fixed++;
+  console.log(`  fixed ${slug.padEnd(24)} ${c || ''}`);
+}
+
+function insideComment(s, i) {
+  const open = s.lastIndexOf('<!--', i), close = s.lastIndexOf('-->', i);
+  return open > close; // last <!-- is after last --> before i → we're inside a comment
+}
+
+console.log(`\n${fixed} sites re-injected · ${ok} already correctly placed`);

← c4ca891 library: harvest full Shopify image arrays + room/pattern/sw  ·  back to Dw Fleet Registry  ·  dw-header: hide ANY pre-existing <header> + propagate to fle af278f4 →