Skip to content

Commit 424850e

Browse files
committed
Adds logging to defer_pagefind
Locally it is working, but on Netlify it doesn't
1 parent 2e0c975 commit 424850e

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

processors/defer_pagefind.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,41 @@ import type { Page } from "../types/lume.ts";
55

66
export default function deferPagefind() {
77
return (pages: Page[]) => {
8+
console.log("Starting deferPagefind script...");
89
for (const page of pages) {
910
const content = page.content;
10-
if (typeof content !== "string") continue;
11+
if (typeof content !== "string") {
12+
console.log(`Skipping non-string content for: ${page.src?.path || "unknown page"}`);
13+
continue;
14+
}
15+
16+
console.log(`Processing page: ${page.src?.path || "unknown page"}`);
17+
console.log(`Original content snippet (first 200 chars): ${content.substring(0, 200)}`);
1118

1219
let updated = content;
1320
let modified = false;
1421

15-
// Replace Pagefind CSS link
22+
// Check for Pagefind CSS link BEFORE replacement
23+
const cssMatch = content.match(/<link\s+[^>]*href=["']\/pagefind\/pagefind-ui\.css["'][^>]*>/gi);
24+
if (cssMatch) {
25+
console.log(`Found Pagefind CSS link on ${page.src?.path}: ${cssMatch[0]}`);
26+
} else {
27+
console.log(`❌ Pagefind CSS link NOT found on ${page.src?.path}`);
28+
}
29+
1630
updated = updated.replace(
1731
/<link\s+[^>]*href=["']\/pagefind\/pagefind-ui\.css["'][^>]*>/gi,
1832
`<link rel="stylesheet" href="/pagefind/pagefind-ui.css" media="print" onload="this.media='all'">`
1933
);
2034

21-
// Replace Pagefind JS script
35+
// Check for Pagefind JS script BEFORE replacement
36+
const jsMatch = content.match(/<script\s+[^>]*src=["']\/pagefind\/pagefind-ui\.js["'][^>]*><\/script>/gi);
37+
if (jsMatch) {
38+
console.log(`Found Pagefind JS script on ${page.src?.path}: ${jsMatch[0]}`);
39+
} else {
40+
console.log(`❌ Pagefind JS script NOT found on ${page.src?.path}`);
41+
}
42+
2243
updated = updated.replace(
2344
/<script\s+[^>]*src=["']\/pagefind\/pagefind-ui\.js["'][^>]*><\/script>/gi,
2445
`<script type="text/javascript" src="/pagefind/pagefind-ui.js" defer></script>`
@@ -27,8 +48,11 @@ export default function deferPagefind() {
2748
if (updated !== content) {
2849
page.content = updated;
2950
console.log(`✅ Modified: ${page.src?.path || "unknown page"}`);
51+
console.log(`Updated content snippet (first 200 chars): ${page.content.substring(0, 200)}`);
52+
} else {
53+
console.log(`No changes made to: ${page.src?.path || "unknown page"}`);
3054
}
3155
}
56+
console.log("Finished deferPagefind script.");
3257
};
3358
}
34-

0 commit comments

Comments
 (0)