add content collection schemas

master
Avraham Sakal 5 months ago
parent 4c1bcf02ed
commit 626d94694c

@ -18,6 +18,7 @@
"typescript": "^5.6.3"
},
"devDependencies": {
"@unocss/preset-uno": "^0.64.1",
"unocss": "^0.64.1"
}
}

@ -24,6 +24,9 @@ importers:
specifier: ^5.6.3
version: 5.6.3
devDependencies:
'@unocss/preset-uno':
specifier: ^0.64.1
version: 0.64.1
unocss:
specifier: ^0.64.1
version: 0.64.1(postcss@8.4.49)(rollup@4.27.2)(vite@5.4.11(sass@1.81.0))(vue@3.5.13(typescript@5.6.3))

@ -1,11 +1,29 @@
// 1. Import utilities from `astro:content`
import { defineCollection } from "astro:content";
import { defineCollection, z } from "astro:content";
// 2. Define your collection(s)
const blogCollection = defineCollection({
/* ... */
const journalCollection = defineCollection({
type: "content",
schema: z.object({
title: z.string(),
date: z.date(),
tags: z.string().array(),
category: z.string().optional(),
description: z.string().optional(),
}),
});
const articleCollection = defineCollection({
type: "content",
schema: z.object({
title: z.string(),
date: z.date(),
tags: z.string().array(),
category: z.string().optional(),
description: z.string().optional(),
}),
});
// 3. Export a single `collections` object to register your collection(s)
// This key should match your collection directory name in "src/content"
export const collections = {
blog: blogCollection,
"journal-entries": journalCollection,
articles: articleCollection,
};

@ -1,6 +1,9 @@
---
title: MySQL JSON Shenanigans
date: 2024-11-19
tags: ["mysql"]
category: "MySQL"
description: "Out of the box, there is a MySQL text encoding mismatch between VARCHAR columns and JSON columns."
---
In an effort to support out-of-date installations of our app, I had to keep a JSON column in our database. The column is obsolete, as are the values within it; but these installations continue to use it. So, knowing this, I decided to put the proper values into the column. I didn't want to pollute the code of our services to do so, though. So I made it into a `GENERATED` column.

@ -1,6 +1,9 @@
---
title: Elasticsearch Ingestion Daemon
date: 2024-11-20
tags: ["elasticsearch"]
category: "Elasticsearch"
description: "Batch-processing boundaries need to be defined with enough information to point to exactly one record, taking into account records being updated between batches."
---
I still saw requests coming in through an old Cloudflare-Worker-based proxy I had set up, before I released the current one, which rewrites `m3u8` files on-the-fly, besides proxying the segment files themselves (among other features). I updated our website and app to use the new proxy; where were these requests coming from? I inspected some requests as they came in using the Cloudflare interface, and I found that the User Agent was always one of our apps; and different versions of it at that. We still had un-updated versions of our app out in the wild, but I also saw requests from the latest version! How could this be?

@ -1,6 +1,9 @@
---
title: React-Admin Wrestling, a Little More Elasticsearch
date: 2024-11-21
tags: ["react", "react-admin", "elasticsearch"]
category: "React Admin"
description: "(This article is still incomplete. I began writing this entry after work the day it happened, and I didn't get a chance to get back to it until today (12 days later), so I forgot what I was planning on writing about!)"
---
React-admin is a wonderful framework, and is quite flexible; but if you need something that it doesn't offer, it's very difficult to dig through the docs to find out how to do it.

@ -1,6 +1,9 @@
---
title: "@astrojs/node Build Error"
date: 2024-11-23
tags: ["astro"]
category: "Astro"
description: "Always prefix native imports with `node:`, even in dependencies. If a dependency doesn't do it, adjust your build-step to do it for you."
---
Today's entry is about this very site.
@ -62,4 +65,4 @@ export default defineConfig({
});
```
The worked famously.
This worked famously.

@ -1,6 +1,9 @@
---
title: "Content Frontmatter Causes `astro build` Error?"
date: 2024-11-24
tags: ["astro"]
category: "Astro"
description: "Keep your eyes peeled for special characters."
---
Another entry for this site. I ran `pnpm run build` after adding yesterday's entry, and got this error:
@ -48,3 +51,5 @@ date: 2024-11-23
<... rest of the file...>
```
It seems that the `@` character signals an import from another file, and obviously there wasn't any so-named file.

@ -11,7 +11,7 @@ const { title } = Astro.props;
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Astro description" />
<meta name="description" content="A practical coding blog in the form of journal entries and articles." />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
@ -42,35 +42,14 @@ const { title } = Astro.props;
frame="fill"
position="relative"
color="brand"
class:list={["mb-6"]}
/>
<slot />
</body>
</html>
<style is:global>
:root {
--accent: 136, 58, 234;
--accent-light: 224, 204, 250;
--accent-dark: 49, 10, 101;
--accent-gradient: linear-gradient(
45deg,
rgb(var(--accent)),
rgb(var(--accent-light)) 30%,
white 60%
);
}
html {
font-family: system-ui, sans-serif;
background: #13151a;
}
code {
font-family:
Menlo,
Monaco,
Lucida Console,
Liberation Mono,
DejaVu Sans Mono,
Bitstream Vera Sans Mono,
Courier New,
monospace;
}
</style>

@ -1,9 +1,30 @@
---
import Layout from '../../layouts/Layout.astro';
import Section from 'fulldev-ui/components/Section.astro';
import { getCollection } from 'astro:content';
const articles = await getCollection('articles');
export const prerender = true;
---
<Layout title="Articles">
<main>
<Section
title="Articles"
text="Coming Soon!"
cards={articles.map((article)=>({
frame:"panel",
title:article.data.title,
tagline: article.data.date.toISOString().substring(0,10),
// list: ["one", "two"],
badge: article.data.category,
href: `/articles/${article.slug}`,
description: article.data.description,
}))}
align='center'
justify="start"
structure="grid"
>
</Section>
</main>
</Layout>

@ -1,9 +1,35 @@
---
import { getCollection } from 'astro:content';
import Layout from '../../layouts/Layout.astro';
import Section from 'fulldev-ui/components/Section.astro';
import Text from 'fulldev-ui/components/Text.astro';
const journalEntries = await getCollection('journal-entries');
export const prerender = true;
---
<Layout title="Journal Entries">
<main>
<Section
title="Journal Entries"
cards={journalEntries.map((journalEntry)=>({
frame:"panel",
title:journalEntry.data.title,
tagline: journalEntry.data.date.toISOString().substring(0,10),
badge: journalEntry.data.category,
// badges: journalEntry.data.tags,
href: `/journal/${journalEntry.slug}`,
description: journalEntry.data.description,
// html: <Text>{journalEntry.data.description}</Text>,
size: "sm",
}))}
align='center'
justify="start"
structure="grid"
size="md"
>
</Section>
</main>
</Layout>

@ -1,3 +1,6 @@
{
"extends": "astro/tsconfigs/strict"
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"strictNullChecks": true
}
}

@ -1,8 +1,12 @@
import { defineConfig } from "unocss";
import presetUno from "@unocss/preset-uno";
import fulldevUI from "fulldev-ui/unocss";
export default defineConfig({
injectReset: false,
injectReset: true,
presets: [
presetUno,
//@ts-ignore
presets: [fulldevUI],
fulldevUI,
],
});

Loading…
Cancel
Save