Skip to content

Commit 3b27fe3

Browse files
committed
WIP to migrate to Astro 5 content layer API
Fixes: #1611
1 parent 9b3d957 commit 3b27fe3

File tree

7 files changed

+82
-19
lines changed

7 files changed

+82
-19
lines changed

astro.config.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export default defineConfig({
2626
start_url: "/",
2727
}
2828
})],
29-
legacy: {
30-
collections: true, // TODO: migrate to Content Layer API
31-
},
3229
markdown: {
3330
shikiConfig: {
3431
theme: syntaxTheme,

src/components/pages/download/DownloadAccordion.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { getCollection } from 'astro:content';
2+
import { getCollection, render } from 'astro:content';
33
44
const { family = 'nix' } = Astro.props;
55
const accordionId = `download-${family}-accordion`;
@@ -13,7 +13,7 @@ let downloadOptions = (await getCollection('download')).filter(
1313
<div class="download-accordion-menu">
1414
{
1515
downloadOptions.map(async (option) => {
16-
const { Content } = await option.render();
16+
const { Content } = await render(option);
1717
const needsInstallInfix =
1818
option.data.family === 'nix' && option.data.platform !== 'more';
1919
const optionId = `${option.data.family}-${needsInstallInfix ? 'install-' : ''}${option.data.platform}`;

src/content.config.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { defineCollection, z } from 'astro:content';
2+
import { glob } from 'astro/loaders';
3+
4+
const blog = defineCollection({
5+
loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: './src/content/blog' }),
6+
});
7+
8+
const community = defineCollection({
9+
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/community' }),
10+
});
11+
12+
const download = defineCollection({
13+
loader: glob({
14+
pattern: '**/[^_]*.{md,mdx}',
15+
base: './src/content/download',
16+
}),
17+
});
18+
19+
const explore = defineCollection({
20+
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/explore' }),
21+
});
22+
23+
const landing = defineCollection({
24+
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/landing' }),
25+
});
26+
27+
const landingFeatures = defineCollection({
28+
loader: glob({
29+
pattern: '**/[^_]*.{md,mdx}',
30+
base: './src/content/landing-features',
31+
}),
32+
});
33+
34+
const learningManuals = defineCollection({
35+
loader: glob({
36+
pattern: '**/[^_]*.{md,mdx}',
37+
base: './src/content/learning-manuals',
38+
}),
39+
});
40+
41+
const menus = defineCollection({
42+
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/menus' }),
43+
});
44+
45+
// research is a hardcoded json
46+
47+
const sponsors = defineCollection({
48+
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/sponsors' }),
49+
});
50+
51+
const teams = defineCollection({
52+
loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: './src/content/teams' }),
53+
});
54+
55+
// The following collections have been auto-generated: blog, community, download, explore, landing, landing-features, learning-manuals, menus, research, sponsors, teams
56+
57+
export const collections = {
58+
blog,
59+
community,
60+
download,
61+
explore,
62+
landing,
63+
landingFeatures,
64+
learningManuals,
65+
menus,
66+
sponsors,
67+
teams,
68+
};

src/lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import MarkdownIt from 'markdown-it';
33
export function generatePathFromPost(post, attachBlog = true) {
44
const postDate = new Date(post.data.date);
55
return `/${attachBlog ? 'blog/' : ''}${
6-
post.slug.split('/')[0] +
6+
post.id.split('/')[0] +
77
'/' +
88
postDate.getFullYear() +
99
'/' +
10-
post.slug.split('/').pop().split('_').pop()
10+
post.id.split('/').pop().split('_').pop()
1111
}`;
1212
}
1313

src/pages/community.astro

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ import nixosFoundationLogo from '../assets/image/nixos-foundation-logo.svg';
422422
teams.map((team) => (
423423
<li class="flex grow basis-72 flex-col items-center gap-2 text-center text-white md:items-start md:text-left [&>a]:inline-block">
424424
<img
425-
src={`/images/teams/${team.slug.split('_')[1]}.svg`}
425+
src={`/images/teams/${team.id.split('_')[1]}.svg`}
426426
alt={`${team.data.name} Logo`}
427427
class="h-24"
428428
/>
@@ -432,7 +432,7 @@ import nixosFoundationLogo from '../assets/image/nixos-foundation-logo.svg';
432432
</p>
433433
<Button
434434
color="green"
435-
href={'/community/teams/' + team.slug.split('_')[1]}
435+
href={'/community/teams/' + team.id.split('_')[1]}
436436
>
437437
Read more
438438
</Button>
@@ -461,9 +461,7 @@ import nixosFoundationLogo from '../assets/image/nixos-foundation-logo.svg';
461461
<ul class="mx-auto mt-2 list-disc pl-8 md:w-72 md:pl-10">
462462
{
463463
teams
464-
.filter(
465-
(team) => team.slug.split('_')[1] === 'foundation-board',
466-
)[0]
464+
.filter((team) => team.id.split('_')[1] === 'foundation-board')[0]
467465
.data.members.map((member) => (
468466
<li class="mb-1">
469467
{member.name}

src/pages/index.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { getCollection, getEntry } from 'astro:content';
2+
import { getCollection, getEntry, render } from 'astro:content';
33
import Container from '../components/layout/Container.astro';
44
import Button from '../components/ui/Button.astro';
55
import NixosSearchInput from '../components/ui/NixosSearchInput.astro';
@@ -10,7 +10,7 @@ import Asciinema from '../components/ui/Asciinema.astro';
1010
import Banner from '../components/ui/Banner.astro';
1111
import InlineSVG from '../components/util/InlineSVG.astro';
1212
13-
const landingFeatures = await getCollection('landing-features');
13+
const landingFeatures = await getCollection('landingFeatures');
1414
const demos = await getEntry('landing', 'demos');
1515
const posts = await getCollection('blog');
1616
posts
@@ -20,7 +20,7 @@ posts
2020
return dateA > dateB ? -1 : 1;
2121
})
2222
.filter((p) => {
23-
return p.slug.split('/')?.[0] === 'announcements';
23+
return p.id.split('/')?.[0] === 'announcements';
2424
})
2525
.reverse();
2626
---
@@ -77,7 +77,7 @@ posts
7777
<Container class="grid gap-8 md:grid-cols-3 md:gap-4">
7878
{
7979
landingFeatures.map(async (feature) => {
80-
const { Content } = await feature.render();
80+
const { Content } = await render(feature);
8181
return (
8282
<div class="flex flex-col text-center">
8383
<InlineSVG

src/pages/learn.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
import { getCollection } from 'astro:content';
2+
import { getCollection, render } from 'astro:content';
33
import Container from '../components/layout/Container.astro';
44
import Divider from '../components/layout/Divider.astro';
55
import PageHeader from '../components/layout/PageHeader.astro';
66
import Button from '../components/ui/Button.astro';
77
import NixosSearchInput from '../components/ui/NixosSearchInput.astro';
88
import InlineSVG from '../components/util/InlineSVG.astro';
99
import Layout from '../layouts/Layout.astro';
10-
const learningManuals = await getCollection('learning-manuals');
10+
const learningManuals = await getCollection('learningManuals');
1111
1212
const learningFeatures = [
1313
{
@@ -96,7 +96,7 @@ const learningResources = [
9696
<Container class="grid items-start gap-4 py-16 md:grid-cols-3">
9797
{
9898
learningManuals.map(async (manual) => {
99-
const { Content } = await manual.render();
99+
const { Content } = await render(manual);
100100
return (
101101
<div class="border-0.5 border-nix-blue-darker flex flex-col items-center justify-start gap-4 rounded-2xl p-4">
102102
<article>

0 commit comments

Comments
 (0)