diff --git a/src/components/BlogHeader.astro b/src/components/BlogHeader.astro
index b033977..5010d9e 100644
--- a/src/components/BlogHeader.astro
+++ b/src/components/BlogHeader.astro
@@ -15,8 +15,6 @@ const { title, date, slug } = Astro.props;
{slug ? {title} : title}
{
- tags.sort().map((tag: string) => (
+ tags.sort().map((tag: Tag) => (
#{tag}
diff --git a/src/content/config.ts b/src/content/config.ts
index ef0a04f..2fbf11c 100644
--- a/src/content/config.ts
+++ b/src/content/config.ts
@@ -1,27 +1,29 @@
import { z, defineCollection } from 'astro:content';
+export enum Tag {
+ 'Apps' = 'Apps',
+ 'Digital Life' = 'Digital Life',
+ 'Gaming' = 'Gaming',
+ 'Learning' = 'Learning',
+ 'Life' = 'Life',
+ 'MacOS' = 'MacOS',
+ 'Music' = 'Music',
+ 'Making Stuff' = 'Making Stuff',
+ 'Mental Health' = 'Mental Health',
+ 'Movies & TV' = 'Movies & TV',
+ 'Programming' = 'Programming',
+ 'Tech' = 'Tech',
+ 'Tutorial' = 'Tutorial',
+ 'Web Dev' = 'Web Dev',
+ // only for filtering
+ all = 'all',
+}
+
const blogCollection = defineCollection({
schema: z.object({
title: z.string(),
pubDate: z.string().transform((str) => new Date(str)),
- tags: z.array(
- z.enum([
- 'Apps',
- 'Digital Life',
- 'Gaming',
- 'Learning',
- 'Life',
- 'MacOS',
- 'Music',
- 'Making Stuff',
- 'Mental Health',
- 'Movies & TV',
- 'Programming',
- 'Tech',
- 'Tutorial',
- 'Web Dev',
- ])
- ),
+ tags: z.array(z.nativeEnum(Tag)),
}),
});
diff --git a/src/pages/archive/[tag].astro b/src/pages/archive/[tag].astro
index 8f8e359..e680984 100644
--- a/src/pages/archive/[tag].astro
+++ b/src/pages/archive/[tag].astro
@@ -1,19 +1,25 @@
---
import { getCollection } from 'astro:content';
+import { Tag as TagEnum } from '../../content/config';
import Layout from '@layouts/Layout.astro';
import FormattedDate from '@components/FormattedDate.astro';
-const { tag } = Astro.params;
+const { tag }: { tag?: TagEnum } = Astro.params;
-const page = Number.parseInt(Astro.url.searchParams.get('page'));
+const page = Number.parseInt(Astro.url.searchParams.get('page') || '1');
const prevPage = page - 1;
const nextPage = page + 1;
const posts = await getCollection('blog', ({ data }) => {
- if (tag === 'all') {
+ if (!tag) {
+ return false;
+ }
+
+ if (tag === TagEnum.all) {
return true;
}
+
return data.tags.includes(tag);
});
diff --git a/tsconfig.json b/tsconfig.json
index 11e63d7..5b466b1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -3,6 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"strictNullChecks": true,
+ "strict": true,
"paths": {
"@components/*": ["src/components/*"],
"@layouts/*": ["src/layouts/*"],