Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export default defineConfig({
start_url: "/",
}
})],
legacy: {
collections: true, // TODO: migrate to Content Layer API
},
markdown: {
shikiConfig: {
theme: syntaxTheme,
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/blog/BlogListEntry.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { post } = Astro.props;
---

<article
data-category={post.slug.split('/')[0]}
data-category={post.id.split('/')[0]}
class="font-light"
aria-hidden="false"
>
Expand Down
10 changes: 5 additions & 5 deletions src/components/pages/download/DownloadAccordion.astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';

const { family = 'nix' } = Astro.props;
const accordionId = `download-${family}-accordion`;

let downloadOptions = (await getCollection('download')).filter(
(option) => option.data.family === family,
);
let downloadOptions = (await getCollection('download'))
.sort((a, b) => a.id.localeCompare(b.id))
.filter((option) => option.data.family === family);
---

<div id={accordionId} class="download-accordion">
<div class="download-accordion-menu">
{
downloadOptions.map(async (option) => {
const { Content } = await option.render();
const { Content } = await render(option);
const needsInstallInfix =
option.data.family === 'nix' && option.data.platform !== 'more';
const optionId = `${option.data.family}-${needsInstallInfix ? 'install-' : ''}${option.data.platform}`;
Expand Down
66 changes: 66 additions & 0 deletions src/content.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';

const blog = defineCollection({
loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: './src/content/blog' }),
});

const community = defineCollection({
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/community' }),
});

const download = defineCollection({
loader: glob({
pattern: '**/[^_]*.{md,mdx}',
Comment on lines +5 to +14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we glob every directory on md,mdx,yaml or is this fine? it might be annoying in the future if we add a new filetype to a collection and forget to edit this config

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can fix it then. At the end of the day this prevents devs from inserting incompatible file types without implementation on the rendering side.

base: './src/content/download',
}),
});

const explore = defineCollection({
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/explore' }),
});

const landing = defineCollection({
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/landing' }),
});

const landingFeatures = defineCollection({
loader: glob({
pattern: '**/[^_]*.{md,mdx}',
base: './src/content/landing-features',
}),
});

const learningManuals = defineCollection({
loader: glob({
pattern: '**/[^_]*.{md,mdx}',
base: './src/content/learning-manuals',
}),
});

const menus = defineCollection({
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/menus' }),
});

// TODO get `research` from astro collection instead of hardcoded json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like research is using this json inside the astro file

const papers: ReadonlyArray<Paper> = [
instead of the content collection. I see some discussion about this in a related PR #1602

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, lets tackle this in the PR you mentioned since it does not hurt content collection migration right now


const sponsors = defineCollection({
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/sponsors' }),
});

const teams = defineCollection({
loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: './src/content/teams' }),
});

export const collections = {
blog,
community,
download,
explore,
landing,
landingFeatures,
learningManuals,
menus,
sponsors,
teams,
};
4 changes: 2 additions & 2 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import MarkdownIt from 'markdown-it';
export function generatePathFromPost(post, attachBlog = true) {
const postDate = new Date(post.data.date);
return `/${attachBlog ? 'blog/' : ''}${
post.slug.split('/')[0] +
post.id.split('/')[0] +
'/' +
postDate.getFullYear() +
'/' +
post.slug.split('/').pop().split('_').pop()
post.id.split('/').pop().split('_').pop()
}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/blog/[category].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getStaticPaths() {
const blogEntries = await getCollection('blog');

const filteredEntries = blogEntries.reduce((groups, entry) => {
const category = entry.slug.split('/')[0];
const category = entry.id.split('/')[0];
if (!groups[category]) {
groups[category] = {
params: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/blog/[category]/[year].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getStaticPaths() {
const blogEntries = await getCollection('blog');

const filteredEntries = blogEntries.reduce((groups, entry) => {
const category = entry.slug.split('/')[0];
const category = entry.id.split('/')[0];
const postYear = new Date(entry.data.date).getFullYear();
if (!groups[category + postYear]) {
groups[category + postYear] = {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/blog/[category]/[year]/[id].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
import Container from '../../../../components/layout/Container.astro';
import PageHeader from '../../../../components/layout/PageHeader.astro';
import Layout from '../../../../layouts/Layout.astro';
Expand All @@ -8,16 +8,16 @@ export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
return blogEntries.map((entry) => ({
params: {
category: entry.slug.split('/')[0],
category: entry.id.split('/')[0],
year: new Date(entry.data.date).getFullYear(),
id: entry.slug.split('/').pop().split('_').pop(),
id: entry.id.split('/').pop().split('_').pop(),
},
props: { entry },
}));
}

const { entry } = Astro.props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---

<Layout title=`${entry.data.title} | Blog`>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/community.astro
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Layout from '../layouts/Layout.astro';
const meetups = await getEntry('community', 'meetups');
const teams = await getCollection('teams');

teams.sort((a, b) => a.id.localeCompare(b.id));

const nixcons = [
{
title: 'NixCon 2024 - Berlin',
Expand Down Expand Up @@ -422,7 +424,7 @@ import nixosFoundationLogo from '../assets/image/nixos-foundation-logo.svg';
teams.map((team) => (
<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">
<img
src={`/images/teams/${team.slug.split('_')[1]}.svg`}
src={`/images/teams/${team.id.split('_')[1]}.svg`}
alt={`${team.data.name} Logo`}
class="h-24"
/>
Expand All @@ -432,7 +434,7 @@ import nixosFoundationLogo from '../assets/image/nixos-foundation-logo.svg';
</p>
<Button
color="green"
href={'/community/teams/' + team.slug.split('_')[1]}
href={'/community/teams/' + team.id.split('_')[1]}
>
Read more
</Button>
Expand Down Expand Up @@ -461,9 +463,7 @@ import nixosFoundationLogo from '../assets/image/nixos-foundation-logo.svg';
<ul class="mx-auto mt-2 list-disc pl-8 md:w-72 md:pl-10">
{
teams
.filter(
(team) => team.slug.split('_')[1] === 'foundation-board',
)[0]
.find((team) => team.id.split('_')[1] === 'foundation-board')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small refactor to use find instead of filter(...)[0]

.data.members.map((member) => (
<li class="mb-1">
{member.name}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/community/teams/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';

import Container from '../../../components/layout/Container.astro';
import PageHeader from '../../../components/layout/PageHeader.astro';
Expand All @@ -9,13 +9,13 @@ import Layout from '../../../layouts/Layout.astro';
export async function getStaticPaths() {
const teamEntries = await getCollection('teams');
return teamEntries.map((entry) => ({
params: { slug: entry.slug.split('_')[1] },
params: { slug: entry.id.split('_')[1] },
props: { entry },
}));
}

const { entry } = Astro.props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---

<Layout title={entry.data.name}>
Expand Down
11 changes: 7 additions & 4 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { getCollection, getEntry } from 'astro:content';
import { getCollection, getEntry, render } from 'astro:content';
import Container from '../components/layout/Container.astro';
import Button from '../components/ui/Button.astro';
import NixosSearchInput from '../components/ui/NixosSearchInput.astro';
Expand All @@ -10,17 +10,20 @@ import Asciinema from '../components/ui/Asciinema.astro';
import Banner from '../components/ui/Banner.astro';
import InlineSVG from '../components/util/InlineSVG.astro';

const landingFeatures = await getCollection('landing-features');
const landingFeatures = await getCollection('landingFeatures');
const demos = await getEntry('landing', 'demos');
const posts = await getCollection('blog');

landingFeatures.sort((a, b) => a.id.localeCompare(b.id));

posts
.sort((a, b) => {
const dateA = new Date(a.data.date);
const dateB = new Date(b.data.date);
return dateA > dateB ? -1 : 1;
})
.filter((p) => {
return p.slug.split('/')?.[0] === 'announcements';
return p.id.split('/')?.[0] === 'announcements';
})
.reverse();
---
Expand Down Expand Up @@ -77,7 +80,7 @@ posts
<Container class="grid gap-8 md:grid-cols-3 md:gap-4">
{
landingFeatures.map(async (feature) => {
const { Content } = await feature.render();
const { Content } = await render(feature);
return (
<div class="flex flex-col text-center">
<InlineSVG
Expand Down
8 changes: 5 additions & 3 deletions src/pages/learn.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
import Container from '../components/layout/Container.astro';
import Divider from '../components/layout/Divider.astro';
import PageHeader from '../components/layout/PageHeader.astro';
import Button from '../components/ui/Button.astro';
import NixosSearchInput from '../components/ui/NixosSearchInput.astro';
import InlineSVG from '../components/util/InlineSVG.astro';
import Layout from '../layouts/Layout.astro';
const learningManuals = await getCollection('learning-manuals');
const learningManuals = await getCollection('learningManuals');

learningManuals.sort((a, b) => a.id.localeCompare(b.id));

const learningFeatures = [
{
Expand Down Expand Up @@ -96,7 +98,7 @@ const learningResources = [
<Container class="grid items-start gap-4 py-16 md:grid-cols-3">
{
learningManuals.map(async (manual) => {
const { Content } = await manual.render();
const { Content } = await render(manual);
return (
<div class="border-0.5 border-nix-blue-darker flex flex-col items-center justify-start gap-4 rounded-2xl p-4">
<article>
Expand Down