Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sync content layer in dev #11365

Merged
merged 27 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update demo
  • Loading branch information
ascorbic committed Jun 25, 2024
commit 624c377928d4f0785ca9656281d8a85c63d45559
8 changes: 4 additions & 4 deletions packages/astro/src/content/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ export class DataStore {
this.#collections = new Map();
}
get(collectionName: string, key: string) {
return this.#collections.get(collectionName)?.get(key);
return this.#collections.get(collectionName)?.get(String(key));
}
entries(collectionName: string): IterableIterator<[id: string, any]> {
const collection = this.#collections.get(collectionName) ?? new Map();
return collection.entries();
}
set(collectionName: string, key: string, value: any) {
const collection = this.#collections.get(collectionName) ?? new Map();
collection.set(key, value);
collection.set(String(key), value);
this.#collections.set(collectionName, collection);
}
delete(collectionName: string, key: string) {
const collection = this.#collections.get(collectionName);
if (collection) {
collection.delete(key);
collection.delete(String(key));
}
}
clear(collectionName: string) {
Expand All @@ -29,7 +29,7 @@ export class DataStore {
has(collectionName: string, key: string) {
const collection = this.#collections.get(collectionName);
if (collection) {
return collection.has(key);
return collection.has(String(key));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
import type { GetStaticPaths } from "astro";
import { getCollection } from "astro:content"
export const getStaticPaths = (async () => {
const collection = await getCollection("blog");
if(!collection) return []
return collection.map((post) => ({
params: {
id: post.id
},
props: {
post: post.data
}
}));
}) satisfies GetStaticPaths;

interface Props {
post: {
title: string;
body: string;
}
}

const { post } = Astro.props

---

<h1>{post.title}</h1>
<p>{post.body}</p>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
import { getCollection } from 'astro:content';
import { getCollection, getDataEntryById } from 'astro:content';

const blog = await getCollection('blog');
const first = await getDataEntryById('blog', 1);
---
<html>
<head>
Expand All @@ -10,9 +11,10 @@ const blog = await getCollection('blog');
<body>
<h1>Blog Posts</h1>

<h2>{first.data.title}</h2>
<ul>
{blog.map(post => (
<li>{ post.data?.title }</li>
<li><a href={`/blog/${post.id}`}>{ post.data?.title }</a></li>
))}
</ul>
</body>
Expand Down
Loading