Skip to content

Commit

Permalink
implement content collections
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkulpinski committed Jul 10, 2024
1 parent 1666103 commit f569919
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
/.cache
/build
/public/*.json
/.content-collections

# Local env files
.env
Expand Down
17 changes: 17 additions & 0 deletions app/routes/blog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Link } from "@remix-run/react"
import { allPosts } from "content-collections"

export default function BlogPage() {
return (
<ul>
{allPosts.map(post => (
<li key={post._meta.path}>
<Link to={`/blog/${post._meta.path}`} unstable_viewTransition>
<h3>{post.title}</h3>
<p>{post.description}</p>
</Link>
</li>
))}
</ul>
)
}
Binary file modified bun.lockb
Binary file not shown.
15 changes: 15 additions & 0 deletions content-collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineCollection, defineConfig } from "@content-collections/core"

const posts = defineCollection({
name: "posts",
directory: "content/posts",
include: "**/*.md",
schema: z => ({
title: z.string(),
description: z.string(),
}),
})

export default defineConfig({
collections: [posts],
})
9 changes: 9 additions & 0 deletions content/posts/hello-world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Hello world"
description: "This is my first post!"
---

# Hello world

This is my first post!
... rest of the content
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
},
"devDependencies": {
"@biomejs/biome": "^1.7.1",
"@content-collections/core": "^0.6.0",
"@content-collections/remix-vite": "^0.1.1",
"@remix-run/dev": "^2.10.0",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.10",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
"~/*": ["./app/*"],
"content-collections": ["./.content-collections/generated"]
},

// Vite takes care of building everything, not tsc.
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { installGlobals } from "@remix-run/node"
import { vercelPreset } from "@vercel/remix/vite"
import { defineConfig } from "vite"
import tsconfigPaths from "vite-tsconfig-paths"
import contentCollections from "@content-collections/remix-vite"

installGlobals()

export default defineConfig({
ssr: {
noExternal: ["tailwind-merge", "remix-utils"],
},
plugins: [tsconfigPaths(), remix({ presets: [vercelPreset()] })],
plugins: [tsconfigPaths(), remix({ presets: [vercelPreset()] }), contentCollections()],
})

0 comments on commit f569919

Please sign in to comment.