﻿<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Loading Article...</title>
</head>
<body>
<div id="loader">Loading article...</div>

<script>
(async function () {
    const params = new URLSearchParams(location.search);
    const id = params.get("id") || "";
    const prefix = "lzgqxhld-";

    if (!id.startsWith(prefix)) {
        document.getElementById("loader").textContent = "Invalid article ID.";
        return;
    }

    const slug = id.slice(prefix.length);

    try {
        const response = await fetch("/posts.json");
        if (!response.ok) throw new Error("Post list unavailable");

        const posts = await response.json();
        const post = posts[slug];

        if (!post || !post.path) throw new Error("Article not found");

        const articleResponse = await fetch(post.path);
        if (!articleResponse.ok) throw new Error("Article unavailable");

        const html = await articleResponse.text();
        const doc = new DOMParser().parseFromString(html, "text/html");

        const base = doc.createElement("base");
        base.href = new URL(post.path, location.origin).href;
        doc.head.prepend(base);

        document.open();
        document.write("<!DOCTYPE html>\n" + doc.documentElement.outerHTML);
        document.close();

    } catch (error) {
        document.getElementById("loader").textContent = error.message;
    }
})();
</script>
</body>
</html>
