<?php
declare(strict_types=1);

// ========================
// CONFIG
// ========================
$blogDir = __DIR__ . '/posts/';
$defaultPost = 'index';

// ========================
// SECURITY: sanitize input
// ========================
$post = $_GET['b'] ?? $defaultPost;

// allow only safe filenames
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $post)) {
    http_response_code(400);
    die('Invalid post name.');
}

$mdFile = $blogDir . $post . '.md';

if (!file_exists($mdFile)) {
    http_response_code(404);
    $mdContent = "# 404\n\nPost not found.";
} else {
    $mdContent = file_get_contents($mdFile);
}

// ========================
// MARKDOWN PARSER
// ========================
require_once __DIR__ . '/../vendor/Parsedown.php';
require_once __DIR__ . '/../vendor/ParsedownExtra.php';



$parser = new ParsedownExtra();
$parser->setSafeMode(false);       // allow HTML in markdown
$parser->setMarkupEscaped(false);  // don't escape HTML

$htmlContent = $parser->text($mdContent);
?>
<!DOCTYPE html>
<html lang="pl">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Blog</title>
    <link rel="stylesheet" href="../style.css">
<script src="https://unpkg.com/cursor-effects@latest/dist/browser.js"></script>

<script>
window.addEventListener("load", (event) => {
  new cursoreffects.ghostCursor();
});
</script>

    </style>
</head>
<body>


<main class="container interests">
  <?= $htmlContent ?>
</main>

    <footer>
        <p class="center"><img src="../favicon.ico">(c) computer_glamour</p>
    
    <img src="../buttons/-18.gif" class="footer-button">
    <img src="../buttons/xmpp.gif" class="footer-button">
    <img src="../buttons/notread.gif" class="footer-button">
    <img src="../buttons/right2repair.gif" class="footer-button">

    </footer>

</body>
</html>
