Skip to content

Commit

Permalink
refactor: re-structure collections + schema-based validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Dec 15, 2024
1 parent f2e0753 commit 4f2a440
Show file tree
Hide file tree
Showing 159 changed files with 290,568 additions and 290,330 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Exchange rates API sourced from the National Bank of Hungary (Magyar Nemzeti Ban

The project is powered by [Astro](https://astro.build/) and hosted on [Cloudflare Pages](https://pages.cloudflare.com/).

Data gets scraped regularly using [this GitHub Actions workflow](./.github/workflows/scraper.yaml). Static file endpoints are generated from [the resulting files](./src/content/quoteRecords/) and then served through a CDN.
Data gets scraped regularly using [this GitHub Actions workflow](./.github/workflows/scraper.yaml). Static file endpoints are generated from [the resulting files](./src/data/tickers/) and then served through a CDN.

Documentation is built with [Starlight](https://starlight.astro.build/), leveraging [an OpenAPI renderer plugin](https://github.com/HiDeoo/starlight-openapi).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"fetch:mnb": "tsx ./src/data/quoteRecords/_scrape.ts",
"fetch:mnb": "tsx ./src/data/tickers/_scrape.ts",
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
Expand Down
10 changes: 5 additions & 5 deletions src/components/CurrencySelectFieldWithData.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import {
type Props = Omit<CurrencySelectFieldProps, "items">;
const quoteRecords = await getCollection("quoteRecords");
const activeBaseCurrencies = quoteRecords
.filter((quoteRecord) => {
const lastQuote = Object.entries(quoteRecord.data).at(-1);
const tickers = await getCollection("tickers");
const activeBaseCurrencies = tickers
.filter((ticker) => {
const lastQuote = Object.entries(ticker.data.data).at(-1);
if (lastQuote != null) {
const [lastDate] = lastQuote;
return !isDateStale(new Date(lastDate));
}
return false;
})
.map((quoteRecord) => baseCurrencyFromSymbol(quoteRecord.id));
.map((ticker) => baseCurrencyFromSymbol(ticker.data.symbol));
---

<CurrencySelectField
Expand Down
10 changes: 5 additions & 5 deletions src/content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { docsSchema } from "@astrojs/starlight/schema";
import { glob } from "astro/loaders";
import { defineCollection } from "astro:content";

import { QuoteRecordSchema } from "./data/quoteRecords/_schema";
import { TickerSchema } from "./data/tickers/_schema";

const docs = defineCollection({
loader:
Expand All @@ -15,12 +15,12 @@ const docs = defineCollection({
schema: docsSchema(),
});

const quoteRecords = defineCollection({
loader: glob({ pattern: "[^_]*.json", base: "./src/data/quoteRecords" }),
schema: QuoteRecordSchema,
const tickers = defineCollection({
loader: glob({ pattern: "[^_]*.json", base: "./src/data/tickers" }),
schema: TickerSchema,
});

export const collections = {
docs,
quoteRecords,
tickers,
};
Loading

0 comments on commit 4f2a440

Please sign in to comment.