Files
folio/scripts/content/migration_001_add_h1_headings.php
T
cedricAbonnel 72cb7acae4 fix 1.2.1 : cache index.md, H1 rendu, scroll wizard, titre Modifier
- ArticleManager : invalider le cache si index.md est plus récent que meta.json
- migration_001 : touch(meta.json) après maj index.md pour forcer l'invalidation
- post_view.php : masquer le H1 initial du contenu (déjà affiché par le template)
- step1.php : en-tête "Modifier" sans le titre de l'article
- wizard.js : retirer scrollToCursor (erroné sur auto-resize) ; Ctrl+Home/End via scrollIntoView

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 23:07:15 +02:00

51 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
// Migration 001 : préfixe chaque article avec `# Titre` si aucun titre
// Markdown de niveau 1 n'est déjà présent dans le contenu.
//
// Variables disponibles depuis le runner : $dataDir
/** @var string $dataDir */
$updated = 0;
$skipped = 0;
foreach (glob($dataDir . '/*/meta.json') as $metaPath) {
$dir = dirname($metaPath);
$mdPath = $dir . '/index.md';
if (!file_exists($mdPath)) {
$skipped++;
continue;
}
$meta = json_decode((string) file_get_contents($metaPath), true);
if (!is_array($meta)) {
$skipped++;
continue;
}
$title = trim($meta['title'] ?? '');
$content = (string) file_get_contents($mdPath);
$content = str_replace("\r\n", "\n", $content);
// Déjà un titre Markdown niveau 1 → on ne touche pas
if (preg_match('/^\s*#\s+\S/', $content)) {
$skipped++;
continue;
}
if ($title === '') {
$skipped++;
continue;
}
file_put_contents($mdPath, '# ' . $title . "\n\n" . ltrim($content));
touch($metaPath);
$updated++;
}
echo " $updated article(s) mis à jour, $skipped ignoré(s)\n";