Files
TechradarDev/docker/patch_document.py
syoul 3553f1d839 fix: Script team-block-script.js avec remplacement DOM
- Nouvelle approche: remplace le DOM apres chargement (defer-compatible)
- Charge Cytoscape, ECharts dynamiquement
- Initialise les 3 visualisations: graphe reseau, matrice congestion, equipe genese
- Ajout de patch_document.py pour inclure le script dans _document.tsx
2025-12-09 17:03:20 +01:00

43 lines
1.5 KiB
Python

#!/usr/bin/env python3
# Script pour modifier _document.tsx et charger team-block-script.js en premier
import sys
doc_path = ".techradar/src/pages/_document.tsx"
try:
with open(doc_path, "r") as f:
content = f.read()
# Ajouter l'import de Script si pas present
if "import Script from 'next/script'" not in content and 'import Script from "next/script"' not in content:
content = content.replace(
'import { Head, Html, Main, NextScript } from "next/document";',
'import { Head, Html, Main, NextScript } from "next/document";\nimport Script from "next/script";'
)
# Ajouter le script dans <Head> avec strategy="beforeInteractive"
if "team-block-script.js" not in content:
# Trouver la fin de <Head /> et la remplacer par un <Head> avec contenu
if "<Head />" in content:
content = content.replace(
"<Head />",
'<Head>\n <Script src="/team-block-script.js" strategy="beforeInteractive" />\n </Head>'
)
elif "<Head>" in content and "</Head>" in content:
# Ajouter avant </Head>
content = content.replace(
"</Head>",
' <Script src="/team-block-script.js" strategy="beforeInteractive" />\n </Head>'
)
with open(doc_path, "w") as f:
f.write(content)
print("_document.tsx modifie pour charger team-block-script.js en premier")
sys.exit(0)
except Exception as e:
print(f"Erreur: {e}")
sys.exit(1)