refactor: use a content collection for talks

This commit is contained in:
Oliver Davies 2023-04-09 10:17:52 +01:00
parent 85644e4f2d
commit 7b97ad3af2
42 changed files with 111 additions and 92 deletions

142
.astro/types.d.ts vendored
View file

@ -111,251 +111,251 @@ declare module 'astro:content' {
>; >;
const entryMap: { const entryMap: {
"talks": { "talk": {
"about-drupal-association.md": { "about-drupal-association.md": {
id: "about-drupal-association.md", id: "about-drupal-association.md",
slug: "about-drupal-association", slug: "about-drupal-association",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"automated-testing-test-driven-development-drupal-8.md": { "automated-testing-test-driven-development-drupal-8.md": {
id: "automated-testing-test-driven-development-drupal-8.md", id: "automated-testing-test-driven-development-drupal-8.md",
slug: "automated-testing-test-driven-development-drupal-8", slug: "automated-testing-test-driven-development-drupal-8",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"building-presenting-slide-decks-rst2pdf.md": { "building-presenting-slide-decks-rst2pdf.md": {
id: "building-presenting-slide-decks-rst2pdf.md", id: "building-presenting-slide-decks-rst2pdf.md",
slug: "building-presenting-slide-decks-rst2pdf", slug: "building-presenting-slide-decks-rst2pdf",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"building-static-websites-sculpin.md": { "building-static-websites-sculpin.md": {
id: "building-static-websites-sculpin.md", id: "building-static-websites-sculpin.md",
slug: "building-static-websites-sculpin", slug: "building-static-websites-sculpin",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"configuring-all-the-things-drupal-8.md": { "configuring-all-the-things-drupal-8.md": {
id: "configuring-all-the-things-drupal-8.md", id: "configuring-all-the-things-drupal-8.md",
slug: "configuring-all-the-things-drupal-8", slug: "configuring-all-the-things-drupal-8",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"dancing-for-drupal.md": { "dancing-for-drupal.md": {
id: "dancing-for-drupal.md", id: "dancing-for-drupal.md",
slug: "dancing-for-drupal", slug: "dancing-for-drupal",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"decoupling-drupal-vuejs.md": { "decoupling-drupal-vuejs.md": {
id: "decoupling-drupal-vuejs.md", id: "decoupling-drupal-vuejs.md",
slug: "decoupling-drupal-vuejs", slug: "decoupling-drupal-vuejs",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"deploying-drupal-fabric.md": { "deploying-drupal-fabric.md": {
id: "deploying-drupal-fabric.md", id: "deploying-drupal-fabric.md",
slug: "deploying-drupal-fabric", slug: "deploying-drupal-fabric",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"deploying-php-ansible-ansistrano.md": { "deploying-php-ansible-ansistrano.md": {
id: "deploying-php-ansible-ansistrano.md", id: "deploying-php-ansible-ansistrano.md",
slug: "deploying-php-ansible-ansistrano", slug: "deploying-php-ansible-ansistrano",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"deploying-php-fabric.md": { "deploying-php-fabric.md": {
id: "deploying-php-fabric.md", id: "deploying-php-fabric.md",
slug: "deploying-php-fabric", slug: "deploying-php-fabric",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-8-module-development.md": { "drupal-8-module-development.md": {
id: "drupal-8-module-development.md", id: "drupal-8-module-development.md",
slug: "drupal-8-module-development", slug: "drupal-8-module-development",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-8-php-libraries-drupalorg-api.md": { "drupal-8-php-libraries-drupalorg-api.md": {
id: "drupal-8-php-libraries-drupalorg-api.md", id: "drupal-8-php-libraries-drupalorg-api.md",
slug: "drupal-8-php-libraries-drupalorg-api", slug: "drupal-8-php-libraries-drupalorg-api",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-8-rejoining-the-herd.md": { "drupal-8-rejoining-the-herd.md": {
id: "drupal-8-rejoining-the-herd.md", id: "drupal-8-rejoining-the-herd.md",
slug: "drupal-8-rejoining-the-herd", slug: "drupal-8-rejoining-the-herd",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-8.md": { "drupal-8.md": {
id: "drupal-8.md", id: "drupal-8.md",
slug: "drupal-8", slug: "drupal-8",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-ldap-module.md": { "drupal-ldap-module.md": {
id: "drupal-ldap-module.md", id: "drupal-ldap-module.md",
slug: "drupal-ldap-module", slug: "drupal-ldap-module",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-vm-generator.md": { "drupal-vm-generator.md": {
id: "drupal-vm-generator.md", id: "drupal-vm-generator.md",
slug: "drupal-vm-generator", slug: "drupal-vm-generator",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupal-vm-meet-symfony-console.md": { "drupal-vm-meet-symfony-console.md": {
id: "drupal-vm-meet-symfony-console.md", id: "drupal-vm-meet-symfony-console.md",
slug: "drupal-vm-meet-symfony-console", slug: "drupal-vm-meet-symfony-console",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drupalorg-2015.md": { "drupalorg-2015.md": {
id: "drupalorg-2015.md", id: "drupalorg-2015.md",
slug: "drupalorg-2015", slug: "drupalorg-2015",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"drush-make-drupalbristol.md": { "drush-make-drupalbristol.md": {
id: "drush-make-drupalbristol.md", id: "drush-make-drupalbristol.md",
slug: "drush-make-drupalbristol", slug: "drush-make-drupalbristol",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"getting-your-data-into-drupal-8.md": { "getting-your-data-into-drupal-8.md": {
id: "getting-your-data-into-drupal-8.md", id: "getting-your-data-into-drupal-8.md",
slug: "getting-your-data-into-drupal-8", slug: "getting-your-data-into-drupal-8",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"git-flow.md": { "git-flow.md": {
id: "git-flow.md", id: "git-flow.md",
slug: "git-flow", slug: "git-flow",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"goodbye-drush-make-hello-composer.md": { "goodbye-drush-make-hello-composer.md": {
id: "goodbye-drush-make-hello-composer.md", id: "goodbye-drush-make-hello-composer.md",
slug: "goodbye-drush-make-hello-composer", slug: "goodbye-drush-make-hello-composer",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"introduction-to-mob-programming.md": { "introduction-to-mob-programming.md": {
id: "introduction-to-mob-programming.md", id: "introduction-to-mob-programming.md",
slug: "introduction-to-mob-programming", slug: "introduction-to-mob-programming",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"it-all-started-with-a-patch.md": { "it-all-started-with-a-patch.md": {
id: "it-all-started-with-a-patch.md", id: "it-all-started-with-a-patch.md",
slug: "it-all-started-with-a-patch", slug: "it-all-started-with-a-patch",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"modern-drupal-development-with-composer.md": { "modern-drupal-development-with-composer.md": {
id: "modern-drupal-development-with-composer.md", id: "modern-drupal-development-with-composer.md",
slug: "modern-drupal-development-with-composer", slug: "modern-drupal-development-with-composer",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"out-of-the-box-initiative-update.md": { "out-of-the-box-initiative-update.md": {
id: "out-of-the-box-initiative-update.md", id: "out-of-the-box-initiative-update.md",
slug: "out-of-the-box-initiative-update", slug: "out-of-the-box-initiative-update",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"so-what-is-this-drupal-thing.md": { "so-what-is-this-drupal-thing.md": {
id: "so-what-is-this-drupal-thing.md", id: "so-what-is-this-drupal-thing.md",
slug: "so-what-is-this-drupal-thing", slug: "so-what-is-this-drupal-thing",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"taking-flight-with-tailwind-css.md": { "taking-flight-with-tailwind-css.md": {
id: "taking-flight-with-tailwind-css.md", id: "taking-flight-with-tailwind-css.md",
slug: "taking-flight-with-tailwind-css", slug: "taking-flight-with-tailwind-css",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"tdd-test-driven-drupal.md": { "tdd-test-driven-drupal.md": {
id: "tdd-test-driven-drupal.md", id: "tdd-test-driven-drupal.md",
slug: "tdd-test-driven-drupal", slug: "tdd-test-driven-drupal",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"test-drive-twig-with-sculpin.md": { "test-drive-twig-with-sculpin.md": {
id: "test-drive-twig-with-sculpin.md", id: "test-drive-twig-with-sculpin.md",
slug: "test-drive-twig-with-sculpin", slug: "test-drive-twig-with-sculpin",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"things-you-should-know-about-php.md": { "things-you-should-know-about-php.md": {
id: "things-you-should-know-about-php.md", id: "things-you-should-know-about-php.md",
slug: "things-you-should-know-about-php", slug: "things-you-should-know-about-php",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"upgrading-your-site-drupal-9.md": { "upgrading-your-site-drupal-9.md": {
id: "upgrading-your-site-drupal-9.md", id: "upgrading-your-site-drupal-9.md",
slug: "upgrading-your-site-drupal-9", slug: "upgrading-your-site-drupal-9",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"using-illuminate-collections-outside-laravel.md": { "using-illuminate-collections-outside-laravel.md": {
id: "using-illuminate-collections-outside-laravel.md", id: "using-illuminate-collections-outside-laravel.md",
slug: "using-illuminate-collections-outside-laravel", slug: "using-illuminate-collections-outside-laravel",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"working-with-workspace.md": { "working-with-workspace.md": {
id: "working-with-workspace.md", id: "working-with-workspace.md",
slug: "working-with-workspace", slug: "working-with-workspace",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
"working-without-workspace.md": { "working-without-workspace.md": {
id: "working-without-workspace.md", id: "working-without-workspace.md",
slug: "working-without-workspace", slug: "working-without-workspace",
body: string, body: string,
collection: "talks", collection: "talk",
data: any data: InferEntrySchema<"talk">
} & { render(): Render[".md"] }, } & { render(): Render[".md"] },
}, },

View file

@ -6,8 +6,7 @@ interface ItemProps {
title: string; title: string;
} }
const { date, description, excerpt, title } = Astro.props.item.item const { date, description, excerpt, title } = Astro.props.item.item.data as ItemProps;
.frontmatter as ItemProps;
const { slug } = Astro.props.item; const { slug } = Astro.props.item;
--- ---

20
src/content/config.ts Normal file
View 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,
};

View file

@ -21,6 +21,7 @@ events:
time: "15:00 - 15:40" time: "15:00 - 15:40"
- name: Drupal Somerset - name: Drupal Somerset
location: Glastonbury, UK
date: "2017-10-26" date: "2017-10-26"
--- ---

View file

@ -69,7 +69,6 @@ events:
- name: Midwest PHP - name: Midwest PHP
date: "2021-04-23" date: "2021-04-23"
location: ~
url: https://midwestphp.org/talks/1q5XUF2tTdXXLYOoujMkpF/Deploying_PHP_applications_with_Ansible_Ansible_Vault_and_Ansistrano url: https://midwestphp.org/talks/1q5XUF2tTdXXLYOoujMkpF/Deploying_PHP_applications_with_Ansible_Ansible_Vault_and_Ansistrano
online: true online: true

View file

@ -1,5 +1,6 @@
--- ---
title: An introduction to mob programming title: An introduction to mob programming
description: ''
speakerdeck: speakerdeck:
id: f37b16f915d64bc0b4a20f9f965e5353 id: f37b16f915d64bc0b4a20f9f965e5353
ratio: 1.77725118483412 ratio: 1.77725118483412

View file

@ -1,6 +1,6 @@
--- ---
title: Working without Workspace title: Working without Workspace
description: ~ description: ''
speakerdeck: speakerdeck:
id: dd406a45f04047fda765346b75efa3c3 id: dd406a45f04047fda765346b75efa3c3
ratio: "1.77798682972719" ratio: "1.77798682972719"
@ -12,4 +12,3 @@ events:
url: https://www.meetup.com/phplondon/events/292657869 url: https://www.meetup.com/phplondon/events/292657869
date: "2023-04-06" date: "2023-04-06"
--- ---

1
src/env.d.ts vendored
View file

@ -1 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" /> /// <reference types="astro/client" />

View file

@ -6,22 +6,21 @@ import Markdown from "~/components/Markdown.astro";
import Slides from "~/components/talk/Slides.astro"; import Slides from "~/components/talk/Slides.astro";
import Video from "~/components/talk/Video.astro"; import Video from "~/components/talk/Video.astro";
import { getSlugFromFile } from "~/utils.ts"; import { getSlugFromFile } from "~/utils.ts";
import { getCollection } from 'astro:content';
export async function getStaticPaths() { export async function getStaticPaths() {
const talks = await Astro.glob("../../talks/*.md"); const talks = await getCollection('talk')
return talks.map((talk) => { return talks.map((talk) => {
const slug = getSlugFromFile(talk.file);
return { return {
params: { slug }, params: { slug: talk.slug },
props: { talk }, props: { talk },
}; };
}); });
} }
const { Content } = Astro.props.talk; const { Content } = await Astro.props.talk.render();
const { events, speakerdeck, title, video } = Astro.props.talk.frontmatter; const { events, speakerdeck, title, video } = Astro.props.talk.data;
--- ---
<Layout title={title}> <Layout title={title}>

View file

@ -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 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) const talkCount = _(talks)
.flatMap((talk) => talk.frontmatter.events) .flatMap((talk) => talk.data.events)
.size(); .size();
const sortedTalks = talks const sortedTalks = talks
.map((talk) => { .map((talk) => {
const slug = `/talks/${getSlugFromFile(talk.file)}`; const slug = `/talks/${talk.slug}`
return { slug, item: talk }; return { slug, item: talk };
}) })
.sort((b, a) => { .sort((b, a) => {
const events = [ const events = [
a.item.frontmatter.events[a.item.frontmatter.events.length - 1], a.item.data.events[a.item.data.events.length - 1],
b.item.frontmatter.events[b.item.frontmatter.events.length - 1], b.item.data.events[b.item.data.events.length - 1],
]; ];
return ( return (

View file

@ -3,7 +3,8 @@
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"~/*": ["src/*"], "~/*": ["src/*"]
} },
"strictNullChecks": true
} }
} }