File size: 1,864 Bytes
51bdde0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
/**
 * Script to update all HTML files in src/pages to use Handlebars partials
 * for navbar and footer
 */

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const pagesDir = path.join(__dirname, '..', 'src', 'pages');

// Get all HTML files in src/pages
const htmlFiles = fs.readdirSync(pagesDir).filter((f) => f.endsWith('.html'));

console.log(`Found ${htmlFiles.length} HTML files to process...`);

let updatedCount = 0;
let skippedCount = 0;

for (const file of htmlFiles) {
  const filePath = path.join(pagesDir, file);
  let content = fs.readFileSync(filePath, 'utf-8');
  let modified = false;

  // Check if already using partials
  if (content.includes('{{> navbar }}') && content.includes('{{> footer }}')) {
    console.log(`  [SKIP] ${file} - already using partials`);
    skippedCount++;
    continue;
  }

  // Replace navbar - match from <nav to </nav>
  const navbarRegex =
    /<nav class="bg-gray-800 border-b border-gray-700 sticky top-0 z-30">[\s\S]*?<\/nav>/;
  if (navbarRegex.test(content)) {
    content = content.replace(navbarRegex, '{{> navbar }}');
    modified = true;
  }

  // Replace footer - match from <footer to </footer>
  const footerRegex =
    /<footer class="mt-16 border-t-2 border-gray-700 py-8">[\s\S]*?<\/footer>/;
  if (footerRegex.test(content)) {
    content = content.replace(footerRegex, '{{> footer }}');
    modified = true;
  }

  if (modified) {
    fs.writeFileSync(filePath, content, 'utf-8');
    console.log(`  [UPDATED] ${file}`);
    updatedCount++;
  } else {
    console.log(`  [NO MATCH] ${file} - navbar/footer pattern not found`);
    skippedCount++;
  }
}

console.log(
  `\nDone! Updated ${updatedCount} files, skipped ${skippedCount} files.`
);