Skip to content

Commit

Permalink
refactor(projects): add zod schema
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed May 8, 2024
1 parent 40ef9ca commit 34f4451
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/_data/projects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
// @ts-check
import EleventyFetch from '@11ty/eleventy-fetch';
import { z } from 'zod';

const projects = {
const schema = z.record(
z.array(
z
.object({
name: z.string().min(1),
link: z.string().url().startsWith('https://github.com'),
featured: z.boolean().default(false).optional(),

stack: z.array(z.string()).default([]).optional(),

description: z.string().optional(),
live: z.string().optional(),
})
.strict(),
),
);

/** @type {z.infer<typeof schema>} */
const projects = schema.parse({
current: [
{
name: 'kittysay',
Expand Down Expand Up @@ -52,7 +72,6 @@ const projects = {
stack: ['rust'],
},
{
name: 'sttr-rs',
link: 'https://github.com/uncenter/sttr-rs',
stack: ['rust'],
},
Expand Down Expand Up @@ -89,7 +108,7 @@ const projects = {
stack: ['eleventy'],
},
],
};
});

async function fetchRepository(username, repository, fetchOptions) {
const response = await EleventyFetch(
Expand All @@ -103,7 +122,6 @@ async function fetchRepository(username, repository, fetchOptions) {
return {
description: response?.description || '',
homepage: response?.homepage || false,
language: response.language,
};
}

Expand All @@ -125,7 +143,6 @@ export default async function () {
headers,
});
project.description = project.description || data.description;
project.language = data.language;
if (data.homepage) project.live = data.homepage;
}
}
Expand Down

0 comments on commit 34f4451

Please sign in to comment.