53 lines
995 B
TypeScript
53 lines
995 B
TypeScript
import {
|
|
Controller,
|
|
Param,
|
|
Route,
|
|
View,
|
|
ViewRoot,
|
|
} from "@muddle/decorators";
|
|
import type { ViewPropsOf } from "../../_muddle/contracts/views.ts";
|
|
|
|
const NAV = [
|
|
{ label: "Home", href: "/" },
|
|
];
|
|
|
|
const POSTS = [
|
|
{ id: "test1", title: "Test1", excerpt: "Test1" },
|
|
{ id: "test2", title: "Test2", excerpt: "Test2" },
|
|
{ id: "test3", title: "Test3", excerpt: "Test3" },
|
|
];
|
|
|
|
@Controller("/")
|
|
@ViewRoot("./views")
|
|
export class AppController {
|
|
@View("index.spug")
|
|
index(): ViewPropsOf<"modules/app/views/index"> {
|
|
return {
|
|
title: "Blog",
|
|
nav: NAV,
|
|
posts: POSTS,
|
|
};
|
|
}
|
|
|
|
@Route("/posts/:id")
|
|
@View("post.spug")
|
|
show(@Param("id") id: string): ViewPropsOf<"modules/app/views/post"> {
|
|
const post = POSTS.find((entry) => entry.id === id) ?? null;
|
|
if (!post) {
|
|
return {
|
|
title: "Not found",
|
|
nav: NAV,
|
|
post: null,
|
|
};
|
|
}
|
|
return {
|
|
title: post.title,
|
|
nav: NAV,
|
|
post: {
|
|
id: post.id,
|
|
title: post.title,
|
|
excerpt: post.excerpt,
|
|
},
|
|
};
|
|
}
|
|
}
|