first commit

This commit is contained in:
2026-05-03 00:02:51 +02:00
parent a1be01183d
commit db038a61a9
138 changed files with 9146 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
<?php
// build/generate_index.php
$dir = __DIR__ . '/../content/';
echo "DEBUG: Hledám soubory v cestě: $dir\n";
echo "DEBUG: Existuje složka? " . (is_dir($dir) ? "ANO" : "NE") . "\n";
$files = glob($dir . '*.md');
echo "DEBUG: Počet nalezených souborů: " . count($files) . "\n";
if (empty($files)) {
echo "Chyba: Nenašel jsem žádné .md soubory v $dir\n";
echo "Seznam obsahu složky:\n";
print_r(scandir($dir));
die();
}
$articles = [];
foreach ($files as $file) {
$content = file_get_contents($file);
$filename = basename($file, '.md');
// 1. Extrahování titulu (první řádek začínající #)
$lines = explode("\n", $content);
$title = $filename; // Fallback
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
$title = trim(ltrim($line, '# '));
break;
}
}
// 2. Extrahování data (hledáme '> Datum: ...')
$date = date('Y-m-d'); // Fallback na dnes
foreach ($lines as $line) {
if (preg_match('/> Datum:\s*(.*)/', $line, $matches)) {
$rawDate = trim($matches[1]);
// Zkusíme převedení na formát Y-m-d
$parsedDate = strtotime($rawDate);
if ($parsedDate) {
$date = date('Y-m-d', $parsedDate);
}
break;
}
}
// 3. Vyčištění excerptu
// Odstraníme Markdown syntaxi pro lepší čitelnost ve vyhledávání
$cleanContent = $content;
$cleanContent = preg_replace('/^#.*$/m', '', $cleanContent); // Odstranit nadpisy
$cleanContent = preg_replace('/\*\*(.*?)\*\*/', '$1', $cleanContent); // Odstranit tučné
$cleanContent = preg_replace('/\*(.*?)\*/', '$1', $cleanContent); // Odstranit kurzívu
$cleanContent = preg_replace('/`(.+?)`/', '$1', $cleanContent); // Odstranit inline kód
$cleanContent = strip_tags($cleanContent); // Odstranit HTML (pokud nějaký vznikl)
$cleanContent = preg_replace('/\s+/', ' ', $cleanContent); // Sjednotit mezery
$cleanContent = trim($cleanContent);
$excerpt = mb_substr($cleanContent, 0, 150);
if (strlen($cleanContent) > 150) {
$excerpt .= '...';
}
$articles[] = [
'title' => $title,
'slug' => $filename, // Používáme filename jako slug pro hledání
'date' => $date,
'excerpt' => $excerpt
];
}
// Seřazení podle data (nejnovější první)
usort($articles, function($a, $b) {
return strtotime($b['date']) - strtotime($a['date']);
});
// Cesta k výstupu
$outputDir = __DIR__ . '/../public/data/';
// Vytvoř složku, pokud neexistuje
if (!is_dir($outputDir)) {
if (!mkdir($outputDir, 0755, true)) {
die("Chyba: Nelze vytvořit složku $outputDir\n");
}
}
$outputFile = $outputDir . 'articlesSearch.json';
if (file_put_contents($outputFile, json_encode($articles, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
echo "✅ Index vygenerován úspěšně: " . count($articles) . " článků do $outputFile\n";
} else {
die("❌ Chyba: Nelze zapsat soubor $outputFile\n");
}
+132
View File
@@ -0,0 +1,132 @@
<?php
// build/import_old_articles.php
// Tento skript převede staré .php články na .md pro nový web
$oldDir = '/srv/http/EOS_PHP/'; // Cesta ke starému projektu
$newContentDir = '/srv/http/eos-modern/content/'; // Cesta k novému obsahu
// Ujisti se, že složka existuje
if (!is_dir($newContentDir)) {
mkdir($newContentDir, 0755, true);
}
// Seznam souborů, které chceme importovat
$files = glob($oldDir . '*.php');
// Filtr: Ignorovat systémové soubory
$ignoreFiles = [
'index.php', 'search.php', 'header.php', 'footer.php', 'base.php',
'config.php', 'functions.php', 'returnbutton.php', 'head.php',
'wiki.php', 'rozcestnik.php', 'o-nas.php', 'odkazy.php',
'z-internetu.php', 'novinky.php', 'clanky.php', 'style.css',
'script.js', 'wiki.css', 'LICENSE.md', 'README.md',
'import_old_articles.php' // Samotný tento skript
];
$importedCount = 0;
foreach ($files as $file) {
$basename = basename($file);
// Ignorovat soubory v seznamu
if (in_array($basename, $ignoreFiles)) {
continue;
}
// Získat slug (název bez .php)
$slug = pathinfo($basename, PATHINFO_FILENAME);
// Číst obsah
$content = file_get_contents($file);
// Extrahovat obsah z <main> sekce
if (preg_match('/<main[^>]*>(.*?)<\/main>/s', $content, $matches)) {
$mainContent = $matches[1];
// 1. Odstranit PHP tagy
$mainContent = preg_replace('/<\?php.*?\?>/s', '', $mainContent);
// 2. Odstranit obrázky a nahradit textem
$mainContent = preg_replace('/<img[^>]*src="([^"]*)"[^>]*alt="([^"]*)"[^>]*>/i', '[Obrázek: $2]', $mainContent);
// 3. Odstranit zbytečné divy a sekce (zachovat text)
$mainContent = preg_replace('/<div[^>]*>/', "\n", $mainContent);
$mainContent = preg_replace('/<\/div>/', "\n", $mainContent);
$mainContent = preg_replace('/<section[^>]*>/', "\n", $mainContent);
$mainContent = preg_replace('/<\/section>/', "\n", $mainContent);
// 4. Odstranit <br>
$mainContent = str_replace('<br>', "\n", $mainContent);
$mainContent = str_replace('<br/>', "\n", $mainContent);
// 5. Odstranit <hr>
$mainContent = preg_replace('/<hr[^>]*>/i', "---\n", $mainContent);
// 6. Odstranit <strong> a <em>
$mainContent = preg_replace('/<strong>(.*?)<\/strong>/i', '**$1**', $mainContent);
$mainContent = preg_replace('/<em>(.*?)<\/em>/i', '*$1*', $mainContent);
// 7. Odstranit <a> a převést na Markdown
$mainContent = preg_replace('/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/i', '[$2]($1)', $mainContent);
// 8. Odstranit <pre><code> a převést na ```bash
$mainContent = preg_replace('/<pre[^>]*><code[^>]*>(.*?)<\/code><\/pre>/s', "\n```bash\n$1\n```\n", $mainContent);
$mainContent = preg_replace('/<code>(.*?)<\/code>/i', '`$1`', $mainContent);
// 9. Odstranit <h1>...<h6> a převést na # (OPRAVENO)
$mainContent = preg_replace_callback('/<h([1-6])[^>]*>(.*?)<\/h\1>/i', function($matches) {
$level = intval($matches[1]); // Převod na číslo
$text = $matches[2];
return "\n" . str_repeat('#', $level) . ' ' . $text . "\n";
}, $mainContent);
// 10. Odstranit <p>
$mainContent = preg_replace('/<p[^>]*>(.*?)<\/p>/s', "\n$1\n", $mainContent);
// 11. Odstranit <ul>, <ol>, <li>
$mainContent = preg_replace('/<ul[^>]*>/i', "\n", $mainContent);
$mainContent = preg_replace('/<\/ul>/i', "\n", $mainContent);
$mainContent = preg_replace('/<ol[^>]*>/i', "\n", $mainContent);
$mainContent = preg_replace('/<\/ol>/i', "\n", $mainContent);
$mainContent = preg_replace('/<li[^>]*>(.*?)<\/li>/i', "- $1\n", $mainContent);
// 12. Odstranit všechny zbývajících HTML tagy
$mainContent = strip_tags($mainContent);
// 13. Čištění mezer
$mainContent = preg_replace('/\n{3,}/', "\n\n", $mainContent);
$mainContent = trim($mainContent);
// Získání titulku
$title = $slug;
if (preg_match('/<h1[^>]*>(.*?)<\/h1>/i', $content, $titleMatches)) {
$title = strip_tags($titleMatches[1]);
}
// Datum
$date = date('Y-m-d');
if (preg_match('/(\d{1,2}\.\d{1,2}\.\d{4})/', $content, $dateMatches)) {
$parts = explode('.', $dateMatches[1]);
if (count($parts) == 3) {
$date = "$parts[2]-$parts[1]-{$parts[0]}";
}
}
// Vytvořit Markdown obsah
$markdownContent = "# $title\n\n";
$markdownContent .= "> Datum: $date\n\n";
$markdownContent .= $mainContent;
// Uložit
$newFile = $newContentDir . $slug . '.md';
file_put_contents($newFile, $markdownContent);
echo "Importováno: $slug -> $newFile\n";
$importedCount++;
} else {
echo "Nenašel se <main> v: $basename\n";
}
}
echo "\nCelkem importováno článků: $importedCount\n";
echo "Nyní spusť: php build/generate_index.php\n";