#!/usr/bin/env node
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PROJECT_ROOT = path.resolve(__dirname, "..");
const FILES = [
"app/page.tsx",
"app/about/page.tsx",
"app/blog/page.tsx",
"app/contact/page.tsx",
];
for (const file of FILES) {
const filePath = path.join(PROJECT_ROOT, file);
let content = fs.readFileSync(filePath, "utf8");
let hasLottie = false;
// Match any
// Extract className and data-src regardless of attribute order
content = content.replace(
/
]*?data-animation-type="lottie"[^>]*?>/g,
(match) => {
const srcMatch = match.match(/data-src="([^"]*)"/);
const clsMatch = match.match(/className="([^"]*)"/);
if (!srcMatch) return match;
hasLottie = true;
const src = srcMatch[1];
const cls = clsMatch ? clsMatch[1] : "";
return ` had a matching
- we need to remove it
// Pattern:
content = content.replace(
/(]*autoplay)\n(\s*)<\/div>/g,
"$1 />"
);
if (hasLottie) {
if (!content.includes("import LottiePlayer")) {
if (content.startsWith("export")) {
content = `import LottiePlayer from "@/components/LottiePlayer"\n\n${content}`;
}
}
fs.writeFileSync(filePath, content, "utf8");
console.log(`Injected LottiePlayer into ${file}`);
}
}