This commit is contained in:
17
src/pages/hobby/[id].astro
Normal file
17
src/pages/hobby/[id].astro
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
import { getCollection, render } from 'astro:content';
|
||||
// 1. Generate a new path for every collection entry
|
||||
export async function getStaticPaths() {
|
||||
const hobbies = await getCollection('hobbies');
|
||||
return hobbies.map(hobby => ({
|
||||
params: { id: hobby.id },
|
||||
props: { post: hobby },
|
||||
}));
|
||||
}
|
||||
// 2. For your template, you can get the entry directly from the prop
|
||||
const { hobby } = Astro.props;
|
||||
const { Content } = await render(hobby);
|
||||
|
||||
---
|
||||
<h1>{hobby.id}</h1>
|
||||
<Content />
|
||||
49
src/pages/index.astro
Normal file
49
src/pages/index.astro
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
const projects = await getCollection('projects');
|
||||
const hobbies = await getCollection('hobbies');
|
||||
---
|
||||
<h1>My Projects</h1>
|
||||
<ul>
|
||||
{projects.map(project => (
|
||||
<li><a href={`/project/${project.id}`}>{project.id}</a></li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<h1>My Hobbies</h1>
|
||||
<ul>
|
||||
{hobbies.map(project => (
|
||||
<li><a href={`/hobby/${project.id}`}>{project.id}</a></li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<!--import BaseLayout from "../layouts/BaseLayout.astro";-->
|
||||
<!--import { getCollection, render } from 'astro:content';-->
|
||||
<!--import type { CollectionEntry } from 'astro:content';-->
|
||||
|
||||
<!--// 1. Generate a new path for every collection entry-->
|
||||
<!--export async function getStaticPaths() {-->
|
||||
<!-- const project = await getCollection('project');-->
|
||||
<!-- console.log(project)-->
|
||||
<!-- return project.map(post => ({-->
|
||||
<!-- params: { slug: post.slug }, props: { post },-->
|
||||
<!-- }));-->
|
||||
<!--}-->
|
||||
<!--// 2. For your template, you can get the entry directly from the prop-->
|
||||
|
||||
<!--const { post } = Astro.props;-->
|
||||
<!--const { Content } = await render(post);-->
|
||||
<!--// const { Content } = await entry.render();-->
|
||||
<!-- ----->
|
||||
<!--<BaseLayout pageTitle="">-->
|
||||
<!--<!– <Baseout pageTitle={entry.data.title}>–>-->
|
||||
<!--<!– <h1 class="text-2xl font-bold pt-10">{entry.data.title}</h1>–>-->
|
||||
<!--<!– <p class="text-sm py-2">{entry.data.date}</p>–>-->
|
||||
<!--<!– <h2 class="font-bold py-2">Tags</h2>–>-->
|
||||
<!--<!– <!–<ul class="list-disc list-inside py-2">–>–>-->
|
||||
<!--<!– <!– {entry.data.tags?.map((tag) => <li><a href={`/tags/${tag}`}>{tag}</a></li>)}–>–>-->
|
||||
<!--<!– <!–</ul>–>–>-->
|
||||
<!--<!– <div class="prose">–>-->
|
||||
<!--<!– <!–<Content />–>–>-->
|
||||
<!--<!– </div>–>-->
|
||||
<!--</BaseLayout>-->
|
||||
17
src/pages/project/[id].astro
Normal file
17
src/pages/project/[id].astro
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
import { getCollection, render } from 'astro:content';
|
||||
// 1. Generate a new path for every collection entry
|
||||
export async function getStaticPaths() {
|
||||
const projects = await getCollection('projects');
|
||||
return projects.map(project => ({
|
||||
params: { id: project.id },
|
||||
props: { post: project },
|
||||
}));
|
||||
}
|
||||
// 2. For your template, you can get the entry directly from the prop
|
||||
const { project } = Astro.props;
|
||||
const { Content } = await render(project);
|
||||
|
||||
---
|
||||
<h1>{project.id}</h1>
|
||||
<Content />
|
||||
Reference in New Issue
Block a user