refactor: use a content collection for talks
This commit is contained in:
parent
85644e4f2d
commit
7b97ad3af2
42 changed files with 111 additions and 92 deletions
|
@ -6,8 +6,7 @@ interface ItemProps {
|
|||
title: string;
|
||||
}
|
||||
|
||||
const { date, description, excerpt, title } = Astro.props.item.item
|
||||
.frontmatter as ItemProps;
|
||||
const { date, description, excerpt, title } = Astro.props.item.item.data as ItemProps;
|
||||
const { slug } = Astro.props.item;
|
||||
---
|
||||
|
||||
|
|
20
src/content/config.ts
Normal file
20
src/content/config.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { defineCollection, z } from 'astro:content';
|
||||
|
||||
const talkCollection = defineCollection({
|
||||
schema: z.object({
|
||||
description: z.string(),
|
||||
events: z.array(z.object({
|
||||
date: z.string(),
|
||||
location: z.string().optional(),
|
||||
name: z.string(),
|
||||
online: z.boolean().optional(),
|
||||
})),
|
||||
title: z.string(),
|
||||
// TODO: add SpeakerDeck
|
||||
// TODO: add Video
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = {
|
||||
'talk': talkCollection,
|
||||
};
|
|
@ -21,6 +21,7 @@ events:
|
|||
time: "15:00 - 15:40"
|
||||
|
||||
- name: Drupal Somerset
|
||||
location: Glastonbury, UK
|
||||
date: "2017-10-26"
|
||||
---
|
||||
|
|
@ -69,7 +69,6 @@ events:
|
|||
|
||||
- name: Midwest PHP
|
||||
date: "2021-04-23"
|
||||
location: ~
|
||||
url: https://midwestphp.org/talks/1q5XUF2tTdXXLYOoujMkpF/Deploying_PHP_applications_with_Ansible_Ansible_Vault_and_Ansistrano
|
||||
online: true
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
title: An introduction to mob programming
|
||||
description: ''
|
||||
speakerdeck:
|
||||
id: f37b16f915d64bc0b4a20f9f965e5353
|
||||
ratio: 1.77725118483412
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Working without Workspace
|
||||
description: ~
|
||||
description: ''
|
||||
speakerdeck:
|
||||
id: dd406a45f04047fda765346b75efa3c3
|
||||
ratio: "1.77798682972719"
|
||||
|
@ -12,4 +12,3 @@ events:
|
|||
url: https://www.meetup.com/phplondon/events/292657869
|
||||
date: "2023-04-06"
|
||||
---
|
||||
|
1
src/env.d.ts
vendored
1
src/env.d.ts
vendored
|
@ -1 +1,2 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
||||
/// <reference types="astro/client" />
|
||||
|
|
|
@ -6,22 +6,21 @@ import Markdown from "~/components/Markdown.astro";
|
|||
import Slides from "~/components/talk/Slides.astro";
|
||||
import Video from "~/components/talk/Video.astro";
|
||||
import { getSlugFromFile } from "~/utils.ts";
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const talks = await Astro.glob("../../talks/*.md");
|
||||
const talks = await getCollection('talk')
|
||||
|
||||
return talks.map((talk) => {
|
||||
const slug = getSlugFromFile(talk.file);
|
||||
|
||||
return {
|
||||
params: { slug },
|
||||
params: { slug: talk.slug },
|
||||
props: { talk },
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const { Content } = Astro.props.talk;
|
||||
const { events, speakerdeck, title, video } = Astro.props.talk.frontmatter;
|
||||
const { Content } = await Astro.props.talk.render();
|
||||
const { events, speakerdeck, title, video } = Astro.props.talk.data;
|
||||
---
|
||||
|
||||
<Layout title={title}>
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
---
|
||||
import PageLayout from "~/layouts/PageLayout.astro";
|
||||
import _ from "lodash";
|
||||
import { getSlugFromFile } from "~/utils.ts";
|
||||
import ListingPage from "~/components/ListingPage.astro";
|
||||
import _ from "lodash";
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
const talks = await Astro.glob("../../talks/*.md");
|
||||
const talks = await getCollection('talk');
|
||||
|
||||
const talkCount = _(talks)
|
||||
.flatMap((talk) => talk.frontmatter.events)
|
||||
.flatMap((talk) => talk.data.events)
|
||||
.size();
|
||||
|
||||
const sortedTalks = talks
|
||||
.map((talk) => {
|
||||
const slug = `/talks/${getSlugFromFile(talk.file)}`;
|
||||
const slug = `/talks/${talk.slug}`
|
||||
|
||||
return { slug, item: talk };
|
||||
})
|
||||
.sort((b, a) => {
|
||||
const events = [
|
||||
a.item.frontmatter.events[a.item.frontmatter.events.length - 1],
|
||||
b.item.frontmatter.events[b.item.frontmatter.events.length - 1],
|
||||
a.item.data.events[a.item.data.events.length - 1],
|
||||
b.item.data.events[b.item.data.events.length - 1],
|
||||
];
|
||||
|
||||
return (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue