Rezygnacja z bazy, przeniesienie danych do plików yamla
This commit is contained in:
@@ -1,26 +1,86 @@
|
||||
---
|
||||
import path from "node:path";
|
||||
|
||||
import DefaultLayout from "../../layouts/DefaultLayout.astro";
|
||||
import OffersSwitches from "../../islands/OffersSwitches.jsx";
|
||||
import InternetCards from "../../islands/Internet/InternetCards.jsx";
|
||||
import SectionRenderer from "../../components/sections/SectionRenderer.astro";
|
||||
import InternetCards from "../../islands/Internet/InternetCards.jsx";
|
||||
|
||||
import yaml from "js-yaml";
|
||||
import fs from "fs";
|
||||
import { loadYamlFile } from "../../lib/loadYaml";
|
||||
|
||||
const seo = yaml.load(
|
||||
fs.readFileSync("./src/content/internet-swiatlowodowy/seo.yaml", "utf8"),
|
||||
type SeoYaml = any;
|
||||
|
||||
type InternetParam = { klucz: string; label: string; value: string | number };
|
||||
type InternetCena = { budynek: number | string; umowa: number | string; miesiecznie: number; aktywacja?: number };
|
||||
type InternetCard = { nazwa: string; widoczny?: boolean; popularny?: boolean; parametry?: InternetParam[]; ceny?: InternetCena[] };
|
||||
type InternetCardsYaml = {
|
||||
tytul?: string;
|
||||
opis?: string;
|
||||
waluta?: string;
|
||||
cena_opis?: string;
|
||||
cards?: InternetCard[];
|
||||
};
|
||||
|
||||
// TELEFON YAML (twój format)
|
||||
type PhoneParam = { klucz: string; label: string; value: string | number };
|
||||
type PhoneCard = { nazwa: string; widoczny?: boolean; popularny?: boolean; cena?: { wartosc: number; opis?: string }; parametry?: PhoneParam[] };
|
||||
type PhoneCardsYaml = { cards?: PhoneCard[] };
|
||||
|
||||
// ADDONS YAML (twój format)
|
||||
type Addon = { id: string; nazwa: string; typ?: string; ilosc?: boolean; min?: number; max?: number; krok?: number; opis?: string; cena: number };
|
||||
type AddonsYaml = { cena_opis?: string; dodatki?: Addon[] };
|
||||
|
||||
const seo = loadYamlFile<SeoYaml>(
|
||||
path.join(process.cwd(), "src", "content", "internet-swiatlowodowy", "seo.yaml"),
|
||||
);
|
||||
|
||||
const data = loadYamlFile<InternetCardsYaml>(
|
||||
path.join(process.cwd(), "src", "content", "internet-swiatlowodowy", "cards.yaml"),
|
||||
);
|
||||
|
||||
const phoneData = loadYamlFile<PhoneCardsYaml>(
|
||||
path.join(process.cwd(), "src", "content", "telefon", "cards.yaml"),
|
||||
);
|
||||
|
||||
const addonsData = loadYamlFile<AddonsYaml>(
|
||||
path.join(process.cwd(), "src", "content", "internet-swiatlowodowy", "addons.yaml"),
|
||||
);
|
||||
|
||||
const tytul = data?.tytul ?? "";
|
||||
const opis = data?.opis ?? "Wybierz rodzaj budynku i czas trwania umowy";
|
||||
|
||||
const waluta = data?.waluta ?? "PLN";
|
||||
const cenaOpis = data?.cena_opis ?? "zł/mies.";
|
||||
|
||||
const cards: InternetCard[] = Array.isArray(data?.cards)
|
||||
? data.cards.filter((c) => c?.widoczny === true)
|
||||
: [];
|
||||
|
||||
const phoneCards: PhoneCard[] = Array.isArray(phoneData?.cards)
|
||||
? phoneData.cards.filter((c) => c?.widoczny === true)
|
||||
: [];
|
||||
|
||||
const addons: Addon[] = Array.isArray(addonsData?.dodatki)
|
||||
? addonsData.dodatki
|
||||
: [];
|
||||
|
||||
// jeśli chcesz, możesz nadpisać cenaOpis w modalu z addons.yaml:
|
||||
const addonsCenaOpis = addonsData?.cena_opis ?? cenaOpis;
|
||||
---
|
||||
|
||||
<DefaultLayout seo={seo}>
|
||||
<section class="f-section">
|
||||
<div class="f-section-grid-single md:grid-cols-1">
|
||||
<h1 class="f-section-title">Internet światłowodowy</h1>
|
||||
<div class="fuz-markdown max-w-none">
|
||||
<p>Wybierz rodzaj budynku i czas trwania umowy</p>
|
||||
</div>
|
||||
<OffersSwitches client:load />
|
||||
<InternetCards client:load />
|
||||
<InternetCards
|
||||
client:load
|
||||
title={tytul}
|
||||
description={opis}
|
||||
cards={cards}
|
||||
waluta={waluta}
|
||||
cenaOpis={cenaOpis}
|
||||
phoneCards={phoneCards}
|
||||
addons={addons}
|
||||
addonsCenaOpis={addonsCenaOpis}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user