diff --git a/src/components/Changelog/ChangelogItem.astro b/src/components/Changelog/ChangelogItem.astro index 3d793724a..8cf3616c8 100644 --- a/src/components/Changelog/ChangelogItem.astro +++ b/src/components/Changelog/ChangelogItem.astro @@ -1,37 +1,39 @@ --- import type { ChangelogFileType } from '../../lib/changelog'; import { DateTime } from 'luxon'; -import MarkdownFile from '../MarkdownFile.astro'; interface Props { changelog: ChangelogFileType; } const { changelog } = Astro.props; -const { frontmatter } = changelog; +const { data: frontmatter } = changelog; +const { Content } = await changelog.render(); -const formattedDate = DateTime.fromISO(frontmatter.date).toFormat( +const formattedDate = DateTime.fromJSDate(frontmatter.date).toFormat( 'dd LLL, yyyy', ); ---
- +
{formattedDate} - {changelog.frontmatter.title} + {frontmatter.title}
- +
diff --git a/src/content/changelog.ts b/src/content/changelog.ts new file mode 100644 index 000000000..399be133e --- /dev/null +++ b/src/content/changelog.ts @@ -0,0 +1,16 @@ +import { defineCollection, z } from 'astro:content'; + +export const changelogCollection = defineCollection({ + type: 'content', + schema: z.object({ + title: z.string(), + description: z.string(), + seo: z + .object({ + title: z.string(), + description: z.string().optional(), + }) + .optional(), + date: z.date(), + }), +}); diff --git a/src/data/changelogs/leaderboard-page.md b/src/content/changelogs/leaderboard-page.md similarity index 100% rename from src/data/changelogs/leaderboard-page.md rename to src/content/changelogs/leaderboard-page.md diff --git a/src/data/changelogs/new-dashboard-page.md b/src/content/changelogs/new-dashboard-page.md similarity index 100% rename from src/data/changelogs/new-dashboard-page.md rename to src/content/changelogs/new-dashboard-page.md diff --git a/src/content/config.ts b/src/content/config.ts index cc4d4b9db..652b30687 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,4 +1,5 @@ import { authorCollection } from './author'; +import { changelogCollection } from './changelog'; import { guideCollection } from './guide'; import { projectCollection } from './project'; import { questionGroupCollection } from './question-group'; @@ -10,4 +11,5 @@ export const collections = { 'question-groups': questionGroupCollection, projects: projectCollection, videos: videoCollection, + changelogs: changelogCollection, }; diff --git a/src/lib/changelog.ts b/src/lib/changelog.ts index 038a03b6f..15aca763e 100644 --- a/src/lib/changelog.ts +++ b/src/lib/changelog.ts @@ -1,56 +1,15 @@ -import type { MarkdownFileType } from './file'; +import { getCollection, type CollectionEntry } from 'astro:content'; -export interface ChangelogFrontmatter { - title: string; - description: string; - seo: { - title: string; - description: string; - }; - date: string; -} - -export type ChangelogFileType = MarkdownFileType & { - id: string; -}; - -/** - * Generates id from the given changelog file - * @param filePath Markdown file path - * - * @returns unique changelog identifier - */ -function changelogPathToId(filePath: string): string { - const fileName = filePath.split('/').pop() || ''; - - return fileName.replace('.md', ''); -} +export type ChangelogFileType = CollectionEntry<'changelogs'>; /** * Gets all the changelogs sorted by the publishing date * @returns Promisifed guide files */ export async function getAllChangelogs(): Promise { - // @ts-ignore - const changelogs = import.meta.glob( - '/src/data/changelogs/*.md', - { - eager: true, - }, - ); - - const changelogFiles = Object.values(changelogs) as ChangelogFileType[]; - const enrichedChangelogs: ChangelogFileType[] = changelogFiles.map( - (changelogFile) => ({ - ...changelogFile, - id: changelogPathToId(changelogFile.file), - }), - ); - - return enrichedChangelogs.sort( - (a, b) => - new Date(b.frontmatter.date).valueOf() - - new Date(a.frontmatter.date).valueOf(), + const changelogEntries = await getCollection('changelogs'); + return changelogEntries.sort( + (a, b) => b.data.date.valueOf() - a.data.date.valueOf(), ); }