This repository has been archived on 2023-05-26. You can view files and clone it, but cannot push or open issues or pull requests.
web/compil.php

58 lines
1.8 KiB
PHP
Executable File

<?php
require "mdp.php";
if (isset($_GET['pw']) AND $_GET['pw'] == $mdp) {
require "bibli/parsedown/Parsedown.php";
require "bibli/parsedown/ParsedownExtra.php";
$nomsPages = array_diff(scandir("pages"), array('..', '.'));
foreach ($nomsPages as $nomPage) {
$nomPage = basename($nomPage, ".md");
// pages/exemple.md > temp/exemple.temp
// Exécute le HTML/PHP avec header et footer vers du HTML statique
ob_start();
require "pages/" . $nomPage . ".md";
file_put_contents("temp/" . $nomPage . ".temp", ob_get_contents());
ob_end_clean();
// temp/exemple.temp > temp2/exemple.temp2
// Compile le Markdown/PHP vers du HTML/PHP
$contenuPage = ParsedownExtra::instance()
->setUrlsLinked(false)
->setMarkupEscaped(false)
->setBreaksEnabled(true)
->text(file_get_contents("temp/" .$nomPage . ".temp"));
file_put_contents("temp2/" . $nomPage . ".temp2", $contenuPage);
// temp2/exemple.temp2 > exemple.html
// Exécute et cache le PHP en HTML
$adresse = $nomPage;
ob_start();
require "inc/pages.php";
require "inc/debut.php";
if ($page['type'] == "article") {
echo "<h1>" . $page['h1'] . "</h1>";
echo "<article>";
} else if ($page['type'] == "centré") {
echo "<div class='centre'>";
}
require "temp2/" . $nomPage . ".temp2";
if ($page['type'] == "article") {
echo "</article>";
} else if ($page['type'] == "centré") {
echo "</div>";
}
require "inc/footer.php";
file_put_contents($nomPage . ".html", ob_get_contents());
ob_end_clean();
}
// exemple.html > exemple.html.gz
// Compresse les fichiers textes statiques HTML & CSS à la racine
exec('/usr/bin/static-compress -c zopfli "*.html" "*.css" "css/*.css"');
} else {
echo "Non authentifié·e";
}