Update template to Astro 5.0, use Content Collections

This commit is contained in:
Cassidy Williams committed 2024-12-14 09:46:58 -06:00
1 parent 90a26b0085
commit 444cbe1502
16 files changed
+11033 -9230

No files matched your search

+4
View File
@@ -46,3 +46,7 @@ TINACLIENTID=<from tina.io>
TINATOKEN=<from tina.io> TINATOKEN=<from tina.io>
TINASEARCH=<from tina.io> TINASEARCH=<from tina.io>
``` ```
If you get a remote GraphQL schema error, chances are you need to update TinaCMS, [details here](https://tina.io/docs/introduction/faq#how-do-i-resolve-the-local-graphql-schema-doesnt-match-the-remote-graphql-schema-errors)!
## Have fun!
+10961 -9175
View File
File diff suppressed because it is too large. Load diff
+7 -7
View File
@@ -10,14 +10,14 @@
"astro": "astro" "astro": "astro"
}, },
"devDependencies": { "devDependencies": {
"@astrojs/rss": "^4.0.1", "@astrojs/rss": "^4.0.10",
"@astrojs/sitemap": "^3.0.5", "@astrojs/sitemap": "^3.2.1",
"astro": "^4.1.1", "astro": "^5.0.5",
"prettier": "^3.1.0", "prettier": "^3.3.3",
"prettier-plugin-astro": "^0.12.2" "prettier-plugin-astro": "^0.14.1"
}, },
"dependencies": { "dependencies": {
"@tinacms/cli": "^1.5.43", "@tinacms/cli": "^1.7.0",
"tinacms": "^1.6.1" "tinacms": "^2.5.2"
} }
} }
+3 -3
View File
@@ -8,8 +8,8 @@ const { allPosts } = Astro.props;
let posts = allPosts let posts = allPosts
.sort( .sort(
(a, b) => (a, b) =>
new Date(b.frontmatter.updated || b.frontmatter.added).valueOf() - new Date(b.data.updated || b.data.added).valueOf() -
new Date(a.frontmatter.updated || a.frontmatter.added).valueOf() new Date(a.data.updated || a.data.added).valueOf(),
) )
.slice(0, 5); .slice(0, 5);
--- ---
@@ -20,7 +20,7 @@ let posts = allPosts
posts.map( posts.map(
({ ({
url, url,
frontmatter: { description, slug, title, tags, added: date }, data: { description, slug, title, tags, added: date },
}) => <Post {url} {description} {date} {slug} {title} {tags} /> }) => <Post {url} {description} {date} {slug} {title} {tags} />
) )
} }
+17
View File
@@ -0,0 +1,17 @@
import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";
const posts = defineCollection({
loader: glob({ pattern: "*.md", base: "./src/posts" }),
schema: z.object({
title: z.string(),
slug: z.string(),
description: z.string(),
added: z.union([z.string(), z.date()]),
updated: z.union([z.string(), z.date()]).optional(),
tags: z.array(z.string()),
}),
});
export const collections = { posts };
+2 -1
View File
@@ -1,4 +1,5 @@
--- ---
import { getCollection } from "astro:content";
import BaseHead from "../components/BaseHead.astro"; import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro"; import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro"; import Footer from "../components/Footer.astro";
@@ -6,7 +7,7 @@ import ColorScript from "../components/ColorScript.astro";
import Tags from "../components/Tags.astro"; import Tags from "../components/Tags.astro";
import getTags from "../scripts/getTags"; import getTags from "../scripts/getTags";
const posts = await Astro.glob("../posts/*.md"); const posts = await getCollection("posts");
const allTags = getTags(posts); const allTags = getTags(posts);
let { let {
+2 -2
View File
@@ -1,4 +1,5 @@
--- ---
import { getCollection } from "astro:content";
import BaseHead from "../components/BaseHead.astro"; import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro"; import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro"; import Footer from "../components/Footer.astro";
@@ -9,8 +10,7 @@ import { SITE_TITLE, SITE_DESCRIPTION } from "../config";
import { Content as About } from "./about.md"; import { Content as About } from "./about.md";
import getTags from "../scripts/getTags"; import getTags from "../scripts/getTags";
const posts = await Astro.glob("../posts/*.md"); const posts = await getCollection("posts");
const tags = getTags(posts); const tags = getTags(posts);
--- ---
+10 -7
View File
@@ -1,19 +1,22 @@
--- ---
// Credit to @rachsmithcodes for this function import { getCollection, render } from "astro:content";
import BlogPost from "../../layouts/BlogPost.astro";
export async function getStaticPaths() { export async function getStaticPaths() {
let posts = await Astro.glob(`../../posts/*.md`); let posts = await getCollection("posts");
return posts.map((post) => { return posts.map((post) => {
return { return {
params: { slug: post.frontmatter.slug }, params: { slug: post.data.slug },
props: { post: post }, props: { post },
}; };
}); });
} }
const { post } = Astro.props; const { post } = Astro.props;
const { Content } = post; const { Content } = await render(post);
--- ---
<Content /> <BlogPost content={post.data}>
<Content />
</BlogPost>
+7 -5
View File
@@ -1,4 +1,5 @@
--- ---
import { getCollection } from "astro:content";
import BaseHead from "../components/BaseHead.astro"; import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro"; import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro"; import Footer from "../components/Footer.astro";
@@ -7,11 +8,12 @@ import ColorScript from "../components/ColorScript.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../config"; import { SITE_TITLE, SITE_DESCRIPTION } from "../config";
// Use Astro.glob() to fetch all posts, and then sort them by date. let posts = await getCollection("posts");
const posts = (await Astro.glob("../posts/*.md")).sort(
posts = posts.sort(
(a, b) => (a, b) =>
new Date(b.frontmatter.updated || b.frontmatter.added).valueOf() - new Date(b.data.updated || b.data.added).valueOf() -
new Date(a.frontmatter.updated || a.frontmatter.added).valueOf() new Date(a.data.updated || a.data.added).valueOf(),
); );
--- ---
@@ -27,7 +29,7 @@ const posts = (await Astro.glob("../posts/*.md")).sort(
posts.map( posts.map(
({ ({
url, url,
frontmatter: { description, slug, title, tags, added: date }, data: { description, slug, title, tags, added: date },
}) => <Post {description} {date} {slug} {title} {tags} /> }) => <Post {description} {date} {slug} {title} {tags} />
) )
} }
+13 -11
View File
@@ -1,29 +1,31 @@
import rss from "@astrojs/rss"; import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import { SITE_TITLE, SITE_DESCRIPTION } from "../config"; import { SITE_TITLE, SITE_DESCRIPTION } from "../config";
let posts = Object.values(import.meta.glob("../posts/*.md", { eager: true })); let posts = await getCollection("posts");
posts = posts.sort( posts = posts.sort(
(a, b) => (a, b) =>
new Date(b.frontmatter.updated || b.frontmatter.added).valueOf() - new Date(b.data.updated || b.data.added).valueOf() -
new Date(a.frontmatter.updated || a.frontmatter.added).valueOf() new Date(a.data.updated || a.data.added).valueOf()
); );
export const GET = () => export const GET = () =>
rss({ rss({
title: SITE_TITLE, title: SITE_TITLE || "",
description: SITE_DESCRIPTION, description: SITE_DESCRIPTION || "",
site: import.meta.env.SITE, site: import.meta.env.SITE,
items: posts.map((post) => { items: posts.map((post) => {
return { return {
link: `/post/${post.frontmatter.slug}`, link: `/post/${post.data.slug}`,
title: post.frontmatter.title, title: post.data.title,
pubDate: post.frontmatter.added, pubDate: post.data.added,
description: post.frontmatter.description, description: post.data.description,
content: post.compiledContent(), content: post.body,
customData: `<updated>${ customData: `<updated>${
post.frontmatter.updated ? post.frontmatter.updated : "" post.data.updated ? post.data.updated : ""
}</updated>`, }</updated>`,
}; };
}), }),
stylesheet: "/rss-styles.xsl",
}); });
+5 -7
View File
@@ -1,4 +1,5 @@
--- ---
import { getCollection } from "astro:content";
import BaseHead from "../../components/BaseHead.astro"; import BaseHead from "../../components/BaseHead.astro";
import Header from "../../components/Header.astro"; import Header from "../../components/Header.astro";
import Footer from "../../components/Footer.astro"; import Footer from "../../components/Footer.astro";
@@ -7,11 +8,10 @@ import ColorScript from "../../components/ColorScript.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../../config"; import { SITE_TITLE, SITE_DESCRIPTION } from "../../config";
// Credit to @rachsmithcodes for helping out my lil ol brain
export async function getStaticPaths() { export async function getStaticPaths() {
let posts = await Astro.glob(`../../posts/*.md`); let posts = await getCollection("posts");
const tags = posts.reduce((allTags, post) => { const tags = posts.reduce((allTags, post) => {
const postTags = post.frontmatter.tags; const postTags = post.data.tags;
if (postTags) { if (postTags) {
postTags.forEach((tag) => { postTags.forEach((tag) => {
if (!allTags[tag]) { if (!allTags[tag]) {
@@ -35,9 +35,7 @@ const { tag } = Astro.props;
const { tag: currentTag } = Astro.params; const { tag: currentTag } = Astro.params;
let sortedPosts = tag.sort( let sortedPosts = tag.sort(
(a, b) => (a, b) => new Date(b.data.added).valueOf() - new Date(a.data.added).valueOf(),
new Date(b.frontmatter.added).valueOf() -
new Date(a.frontmatter.added).valueOf()
); );
--- ---
@@ -54,7 +52,7 @@ let sortedPosts = tag.sort(
sortedPosts.map( sortedPosts.map(
({ ({
url, url,
frontmatter: { description, slug, title, tags, added: date }, data: { description, slug, title, tags, added: date },
}) => <Post {url} {description} {date} {slug} {title} {tags} /> }) => <Post {url} {description} {date} {slug} {title} {tags} />
) )
} }
-1
View File
@@ -1,5 +1,4 @@
--- ---
layout: ../layouts/BlogPost.astro
title: Hello, world! title: Hello, world!
slug: hello-world slug: hello-world
description: >- description: >-
-1
View File
@@ -1,5 +1,4 @@
--- ---
layout: ../layouts/BlogPost.astro
title: Markdown Example title: Markdown Example
slug: markdown slug: markdown
description: >- description: >-
+1 -1
View File
@@ -2,7 +2,7 @@ export default function getTags(posts) {
// Get tags from all posts // Get tags from all posts
const allTags = posts const allTags = posts
.map((post) => { .map((post) => {
const postTags = post.frontmatter.tags; const postTags = post.data.tags;
let allTags = []; let allTags = [];
if (postTags?.length > 0) { if (postTags?.length > 0) {
-8
View File
@@ -26,7 +26,6 @@ export default defineConfig({
path: "src/posts", path: "src/posts",
defaultItem: () => ({ defaultItem: () => ({
title: "New Post", title: "New Post",
layout: "../layouts/BlogPost.astro",
added: new Date(), added: new Date(),
tags: [], tags: [],
}), }),
@@ -40,13 +39,6 @@ export default defineConfig({
}, },
}, },
fields: [ fields: [
{
name: "layout",
label: "Layout",
type: "string",
required: true,
searchable: false,
},
{ {
name: "title", name: "title",
label: "Title", label: "Title",
+1 -1
View File
@@ -1 +1 @@
{"schema":{"version":{"fullVersion":"1.4.33","major":"1","minor":"4","patch":"33"},"meta":{"flags":["experimentalData"]},"collections":[{"name":"post","label":"Posts","path":"src/posts","defaultItem":{"namespace":["post","defaultItem"]},"ui":{"dateFormat":"MMM DD YYYY","filename":{"readonly":false}},"fields":[{"name":"layout","label":"Layout","type":"string","required":true,"searchable":false,"namespace":["post","layout"],"uid":false},{"name":"title","label":"Title","type":"string","isTitle":true,"required":true,"namespace":["post","title"],"searchable":true,"uid":false},{"label":"Slug","name":"slug","type":"string","required":true,"namespace":["post","slug"],"searchable":true,"uid":false},{"label":"Description","name":"description","type":"string","required":true,"namespace":["post","description"],"searchable":true,"uid":false},{"label":"Tags","name":"tags","type":"string","list":true,"options":[{"value":"technical","label":"Technical"},{"value":"advice","label":"Advice"},{"value":"events","label":"Events"},{"value":"learning","label":"Learning"},{"value":"meta","label":"Meta"},{"value":"work","label":"Work"},{"value":"personal","label":"Personal"},{"value":"musings","label":"Musings"}],"namespace":["post","tags"],"searchable":true,"uid":false},{"label":"Added","name":"added","type":"datetime","dateFormat":"MMM DD YYYY","required":true,"namespace":["post","added"],"searchable":true,"uid":false},{"label":"Updated","name":"updated","type":"datetime","dateFormat":"MMM DD YYYY","namespace":["post","updated"],"searchable":true,"uid":false},{"type":"rich-text","name":"body","label":"Body","isBody":true,"namespace":["post","body"],"searchable":true,"parser":{"type":"markdown"},"uid":false}],"namespace":["post"]}],"config":{"media":{"tina":{"publicFolder":"public","mediaRoot":"assets"}},"search":{"tina":{"indexerToken":"db93ec0964cdeb35845c3f869e77cb4d04e13100","stopwordLanguages":["eng"]},"indexBatchSize":50,"maxSearchIndexFieldLength":100}}},"lookup":{"DocumentConnection":{"type":"DocumentConnection","resolveType":"multiCollectionDocumentList","collections":["post"]},"Node":{"type":"Node","resolveType":"nodeDocument"},"DocumentNode":{"type":"DocumentNode","resolveType":"multiCollectionDocument","createDocument":"create","updateDocument":"update"},"Post":{"type":"Post","resolveType":"collectionDocument","collection":"post","createPost":"create","updatePost":"update"},"PostConnection":{"type":"PostConnection","resolveType":"collectionDocumentList","collection":"post"}},"graphql":{"kind":"Document","definitions":[{"kind":"ScalarTypeDefinition","name":{"kind":"Name","value":"Reference"},"description":{"kind":"StringValue","value":"References another document, used as a foreign key"},"directives":[]},{"kind":"ScalarTypeDefinition","name":{"kind":"Name","value":"JSON"},"description":{"kind":"StringValue","value":""},"directives":[]},{"kind":"ObjectTypeDefinition","interfaces":[],"directives":[],"name":{"kind":"Name","value":"SystemInfo"},"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"filename"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"title"},"arguments":[],"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"basename"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"breadcrumbs"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"excludeExtension"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}],"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"path"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"relativePath"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"extension"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"template"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"collection"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Collection"}}}}]},{"kind":"ObjectTypeDefinition","interfaces":[],"directives":[],"name":{"kind":"Name","value":"Folder"},"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"name"},"argumeLine truncated {"schema":{"version":{"fullVersion":"1.5.9","major":"1","minor":"5","patch":"9"},"meta":{"flags":["experimentalData"]},"collections":[{"name":"post","label":"Posts","path":"src/posts","defaultItem":{"namespace":["post","defaultItem"]},"ui":{"dateFormat":"MMM DD YYYY","filename":{"readonly":false}},"fields":[{"name":"title","label":"Title","type":"string","isTitle":true,"required":true,"namespace":["post","title"],"searchable":true,"uid":false},{"label":"Slug","name":"slug","type":"string","required":true,"namespace":["post","slug"],"searchable":true,"uid":false},{"label":"Description","name":"description","type":"string","required":true,"namespace":["post","description"],"searchable":true,"uid":false},{"label":"Tags","name":"tags","type":"string","list":true,"options":[{"value":"technical","label":"Technical"},{"value":"advice","label":"Advice"},{"value":"events","label":"Events"},{"value":"learning","label":"Learning"},{"value":"meta","label":"Meta"},{"value":"work","label":"Work"},{"value":"personal","label":"Personal"},{"value":"musings","label":"Musings"}],"namespace":["post","tags"],"searchable":true,"uid":false},{"label":"Added","name":"added","type":"datetime","dateFormat":"MMM DD YYYY","required":true,"namespace":["post","added"],"searchable":true,"uid":false},{"label":"Updated","name":"updated","type":"datetime","dateFormat":"MMM DD YYYY","namespace":["post","updated"],"searchable":true,"uid":false},{"type":"rich-text","name":"body","label":"Body","isBody":true,"namespace":["post","body"],"searchable":true,"parser":{"type":"markdown"},"uid":false}],"namespace":["post"]}],"config":{"media":{"tina":{"publicFolder":"public","mediaRoot":"assets"}}}},"lookup":{"DocumentConnection":{"type":"DocumentConnection","resolveType":"multiCollectionDocumentList","collections":["post"]},"Node":{"type":"Node","resolveType":"nodeDocument"},"DocumentNode":{"type":"DocumentNode","resolveType":"multiCollectionDocument","createDocument":"create","updateDocument":"update"},"Post":{"type":"Post","resolveType":"collectionDocument","collection":"post","createPost":"create","updatePost":"update"},"PostConnection":{"type":"PostConnection","resolveType":"collectionDocumentList","collection":"post"}},"graphql":{"kind":"Document","definitions":[{"kind":"ScalarTypeDefinition","name":{"kind":"Name","value":"Reference"},"description":{"kind":"StringValue","value":"References another document, used as a foreign key"},"directives":[]},{"kind":"ScalarTypeDefinition","name":{"kind":"Name","value":"JSON"},"description":{"kind":"StringValue","value":""},"directives":[]},{"kind":"ObjectTypeDefinition","interfaces":[],"directives":[],"name":{"kind":"Name","value":"SystemInfo"},"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"filename"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"title"},"arguments":[],"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"basename"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"hasReferences"},"arguments":[],"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"breadcrumbs"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"excludeExtension"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}],"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"path"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"relativePath"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"extension"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"template"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinition","name":{"kind":"Name","value":"collection"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Collection"}}}}]},{"kind":"ObjectTypeDefinition","interfaces":[],"directives":[],"name":{"kind":"Name","value":"Folder"},"fields":[{"kind":"FieldDefinition","name":{"kind":"Name","value":"name"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"FieldDefinitioLine truncated