Dokumenty zmiana podejścia
This commit is contained in:
@@ -1,30 +1,121 @@
|
||||
---
|
||||
import DefaultLayout from "../../layouts/DefaultLayout.astro";
|
||||
import { listDocuments } from "../../lib/documents";
|
||||
import "../../styles/document.css";
|
||||
import yaml from "js-yaml";
|
||||
import fs from "node:fs";
|
||||
import Markdown from "../../islands/Markdown.jsx";
|
||||
|
||||
const documents = listDocuments().filter((d) => d.visible === true);
|
||||
/* ===== Typy ===== */
|
||||
|
||||
type DocFile = {
|
||||
nazwa?: string;
|
||||
file?: string; // pdf
|
||||
slug?: string; // yaml / czytaj
|
||||
};
|
||||
|
||||
type DocGroup = {
|
||||
tytul?: string;
|
||||
pliki?: DocFile[];
|
||||
};
|
||||
|
||||
type DocsYaml = {
|
||||
tytul?: string;
|
||||
opis?: string;
|
||||
grupy?: Record<string, DocGroup>;
|
||||
};
|
||||
|
||||
/* ===== Load YAML ===== */
|
||||
|
||||
const doc = yaml.load(
|
||||
fs.readFileSync("./src/content/document/documents.yaml", "utf8"),
|
||||
) as DocsYaml;
|
||||
|
||||
const pageTitle = doc?.tytul ?? "Dokumenty";
|
||||
const pageDesc = doc?.opis ?? "";
|
||||
|
||||
const groups = doc?.grupy ?? {};
|
||||
const left = groups["otworz"] ?? {};
|
||||
const right = groups["pobierz"] ?? {};
|
||||
|
||||
/* ===== Helpers ===== */
|
||||
|
||||
function normalizePublicHref(input?: string) {
|
||||
let s = String(input ?? "").trim();
|
||||
if (!s) return "";
|
||||
if (s.startsWith("/public/")) s = s.replace("/public", "");
|
||||
s = s.replace(/ /g, "%20");
|
||||
return s;
|
||||
}
|
||||
---
|
||||
|
||||
<DefaultLayout title="Dokumenty">
|
||||
<section class="f-documents">
|
||||
<h1 class="f-documents-title">Dokumenty</h1>
|
||||
<DefaultLayout title={pageTitle} description={pageDesc}>
|
||||
{/* INTRO */}
|
||||
<section class="f-section">
|
||||
<div class="f-section-grid md:grid-cols-1 items-start">
|
||||
<div>
|
||||
<h2 class="f-section-title">{pageTitle}</h2>
|
||||
{pageDesc && <Markdown text={pageDesc} />}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="f-documents-grid">
|
||||
{documents.map((doc) => (
|
||||
<a
|
||||
href={`/dokumenty/${doc.slug}`}
|
||||
class="f-document-card"
|
||||
>
|
||||
<h3 class="f-document-title">{doc.title}</h3>
|
||||
{/* CONTENT */}
|
||||
<section class="f-section">
|
||||
<div class="f-section-grid md:grid-cols-2 gap-10 items-start">
|
||||
|
||||
{doc.intro && (
|
||||
<p class="f-document-intro">{doc.intro}</p>
|
||||
)}
|
||||
{/* ===== LEWA — CZYTAJ ===== */}
|
||||
<div>
|
||||
<h3 class="f-section-title">{left.tytul ?? "Przeczytaj"}</h3>
|
||||
|
||||
{!left.pliki?.length ? (
|
||||
<p class="opacity-70 mt-4">Brak dokumentów.</p>
|
||||
) : (
|
||||
<div class="f-documents-grid">
|
||||
{left.pliki.map((p) => (
|
||||
p.slug ? (
|
||||
<a
|
||||
class="f-document-card"
|
||||
href={`/dokumenty/${p.slug}`}
|
||||
title={p.nazwa}
|
||||
>
|
||||
{/* <div class="f-document-icon">📖</div> */}
|
||||
<div class="f-document-title">{p.nazwa}</div>
|
||||
{/* <div class="f-document-meta">Otwórz</div> */}
|
||||
</a>
|
||||
) : null
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ===== PRAWA — POBIERZ ===== */}
|
||||
<div>
|
||||
<h3 class="f-section-title">{right.tytul ?? "Pobierz"}</h3>
|
||||
|
||||
{!right.pliki?.length ? (
|
||||
<p class="opacity-70 mt-4">Brak plików.</p>
|
||||
) : (
|
||||
<div class="f-documents-grid">
|
||||
{right.pliki.map((p) => {
|
||||
const href = normalizePublicHref(p.file);
|
||||
if (!href) return null;
|
||||
|
||||
return (
|
||||
<a
|
||||
class="f-document-card"
|
||||
href={href}
|
||||
download
|
||||
title={p.nazwa}
|
||||
>
|
||||
{/* <div class="f-document-icon">📄</div> */}
|
||||
<div class="f-document-title">{p.nazwa}</div>
|
||||
{/* <div class="f-document-meta">Pobierz PDF</div> */}
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<span class="f-document-link">Otwórz →</span>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</DefaultLayout>
|
||||
|
||||
Reference in New Issue
Block a user