init
This commit is contained in:
19
routes/news/[slug]/index.server.ts
Normal file
19
routes/news/[slug]/index.server.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { getParams, htmlToResponse, readDir } from "@mastrojs/mastro";
|
||||
import { readMarkdownFile } from "@mastrojs/markdown";
|
||||
import { Layout } from "../../../components/Layout.ts";
|
||||
|
||||
export const GET = async (req: Request) => {
|
||||
const { slug } = getParams(req);
|
||||
const post = await readMarkdownFile(`data/posts/${slug}.md`);
|
||||
return htmlToResponse(
|
||||
Layout({
|
||||
title: post.meta.title,
|
||||
children: post.content,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticPaths = async () => {
|
||||
const posts = await readDir("data/posts/");
|
||||
return posts.map((p) => "/news/" + p.slice(0, -3) + "/");
|
||||
};
|
||||
21
routes/news/index.server.ts
Normal file
21
routes/news/index.server.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { html, htmlToResponse } from "@mastrojs/mastro";
|
||||
import { readMarkdownFiles } from "@mastrojs/markdown";
|
||||
import { Layout } from "../../components/Layout.ts";
|
||||
|
||||
export const GET = async () => {
|
||||
const posts = await readMarkdownFiles("data/posts/*.md");
|
||||
return htmlToResponse(
|
||||
Layout({
|
||||
title: "News",
|
||||
children: posts.map((post) =>
|
||||
html`
|
||||
<p>
|
||||
<a href="${post.path.slice(12, -3) + "/"}">
|
||||
${post.meta.title}
|
||||
</a>
|
||||
</p>
|
||||
`
|
||||
),
|
||||
}),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user