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
2 changes: 2 additions & 0 deletions src/content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const blogCollection = defineCollection({
})
.optional(),
tags: z.array(z.string()),
// Hidden from production builds, still visible in dev. See scripts/content.js.
draft: z.boolean().default(false),
}),
});

Expand Down
1 change: 1 addition & 0 deletions src/content/blog/css-container-queries-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pubDate: 2026-03-02
author: "Yann"
tags: ["css", "queries"]
description: "Reading the specs and the nitty griddy details on MDN is great to get a solid understanding of container queries. But it's a lot faster to do if you got the gist of it through a few carefully selected examples that **show you** the basics."
draft: true
---

import CanIUse from "../../components/_CanIUse.astro";
Expand Down
5 changes: 3 additions & 2 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
import { getCollection, render } from 'astro:content';
import { render } from 'astro:content';
import MarkdownPostLayout from '../../layouts/BlogPostLayout.astro';
import { getBlogPosts } from '../../scripts/content.js';

export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
const blogEntries = await getBlogPosts();
return blogEntries.map((entry) => ({
params: { slug: entry.id },
props: { entry },
Expand Down
4 changes: 2 additions & 2 deletions src/pages/blog/index.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
import { getCollection } from 'astro:content';
import { createMarkdownProcessor } from '@astrojs/markdown-remark';
import { getBlogPosts } from '../../scripts/content.js';
import BaseLayout from '../../layouts/BaseLayout.astro';
import CardList from '../../components/CardList.astro';
import Card from '../../components/Card.astro';

const title = 'mCSS Blog';
const allPosts = await getCollection('blog');
const allPosts = await getBlogPosts();
allPosts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());

const md = await createMarkdownProcessor();
Expand Down
5 changes: 3 additions & 2 deletions src/pages/blog/tags/[tag].astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
import { getCollection, type CollectionEntry } from 'astro:content';
import { type CollectionEntry } from 'astro:content';
import { createMarkdownProcessor } from '@astrojs/markdown-remark';
import BaseLayout from '../../../layouts/BaseLayout.astro';
import { slugify } from '../../../scripts/utilities';
import { getBlogPosts } from '../../../scripts/content.js';

export async function getStaticPaths() {
const allPosts = await getCollection('blog');
const allPosts = await getBlogPosts();

// Group by slug so tags that differ only in case or spacing share one page.
// The first spelling encountered becomes the display name.
Expand Down
4 changes: 2 additions & 2 deletions src/pages/blog/tags/index.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
import { getCollection } from 'astro:content';
import BaseLayout from '../../../layouts/BaseLayout.astro';

import Tags from '../../../components/Tags.astro';
import { getBlogPosts } from '../../../scripts/content.js';

const allPosts = await getCollection('blog');
const allPosts = await getBlogPosts();
const tags = [...new Set(allPosts.map((post) => post.data.tags).flat())];
---

Expand Down
4 changes: 2 additions & 2 deletions src/pages/rss.xml.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import { getBlogPosts } from "../scripts/content.js";

export async function GET(context) {
const blog = await getCollection("blog");
const blog = await getBlogPosts();
return rss({
title: "mCSS News",
description: "Stay up to date with mCSS updates",
Expand Down
18 changes: 18 additions & 0 deletions src/scripts/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// CONTENT HELPERS
// Kept separate from utilities.js: this module imports `astro:content`, so it
// must never be pulled into a client-side bundle.

import { getCollection } from "astro:content";

/**
* Blog posts, with drafts hidden in production builds and visible in dev.
* Always use this instead of getCollection("blog") so a draft cannot leak
* into a listing, a tag page, the RSS feed, or the sitemap.
*
* @returns {Promise<import("astro:content").CollectionEntry<"blog">[]>}
*/
export async function getBlogPosts() {
return getCollection("blog", ({ data }) =>
import.meta.env.PROD ? !data.draft : true,
);
}
Loading