Skip to content

Commit

Permalink
Merge pull request #16 from taga3s/feat/blogs-page
Browse files Browse the repository at this point in the history
feat: posts
  • Loading branch information
taga3s committed Sep 3, 2024
2 parents 3e7a8a7 + b0c56a2 commit 449c5f9
Show file tree
Hide file tree
Showing 14 changed files with 2,596 additions and 27 deletions.
7 changes: 7 additions & 0 deletions app/api/posts/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Post = {
id: string;
title: string;
publishedAt: string;
};

export type { Post };
1 change: 1 addition & 0 deletions app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Header = () => {
<nav class={headerNav}>
<a href="/">about me</a>
<a href="/history">history</a>
<a href="/posts">posts</a>
<a href="/works">works</a>
</nav>
</div>
Expand Down
25 changes: 25 additions & 0 deletions app/components/posts/Posts.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { css } from "hono/css";

const postsStyle = {
wrapper: css`
display: flex;
flex-direction: column;
gap: 16px;
margin-top: 32px;
`,
item: css`
display: flex;
flex-direction: column;
gap: 8px;
width: 100%;
padding: 16px;
border: 1px solid #ccc;
border-radius: 8px;
`,
itemTitle: css`
font-size: 20px;
font-weight: bold;
`,
};

export { postsStyle };
27 changes: 27 additions & 0 deletions app/components/posts/Posts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { FC } from "hono/jsx";
import type { Post } from "../../api/posts/model";
import { Section } from "../Section";
import { postsStyle } from "./Posts.css";

type Props = {
posts: Post[];
};

const Posts: FC<Props> = ({ posts }) => {
return (
<Section title="Posts">
<div class={postsStyle.wrapper}>
{posts.map((post) => {
return (
<a key={post.id} href={`/${post.id}`} class={postsStyle.item}>
<span>{post.publishedAt}</span>
<span class={postsStyle.itemTitle}>{post.title}</span>
</a>
);
})}
</div>
</Section>
);
};

export { Posts };
13 changes: 13 additions & 0 deletions app/components/posts/PostsPresenter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { FC } from "hono/jsx";
import { Posts } from "./Posts";
import type { Post } from "../../api/posts/model";

type Props = {
posts: Post[];
};

const PostsPresenter: FC<Props> = ({ posts }) => {
return <Posts posts={posts} />;
};

export { PostsPresenter };
9 changes: 4 additions & 5 deletions app/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import {} from "hono";

type Head = {
title?: string;
description?: string;
};

declare module "hono" {
interface Env {
Variables: {};
Bindings: {};
}
type ContextRenderer = (content: string | Promise<string>, head?: Head) => Response | Promise<Response>;
type ContextRenderer = (
content: string | Promise<string>,
head?: Head & { frontmatter?: Head; description?: string },) => Response | Promise<Response>
}
10 changes: 8 additions & 2 deletions app/routes/_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const bodyLayout = css`
const HeaderMemorized = memo(() => <Header />);
const FooterMemorized = memo(() => <Footer />);

export default jsxRenderer(({ children }) => {
export default jsxRenderer(({ children, title }) => {
const _title = title ?? "taga3s-dev";

return (
<html lang="ja" class={htmlLayout}>
<head>
Expand All @@ -39,11 +41,15 @@ export default jsxRenderer(({ children }) => {

{/* reset css */}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/destyle.css" />

{/* global css */}
<link rel="stylesheet" href="/markdown-styles.css" />
<Style />

<Script src="/app/client.ts" async />

<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, user-scalable=yes" />
<title>taga3s-dev</title>
<title>{_title}</title>
</head>
<body class={bodyLayout}>
<ErrorBoundary fallback={<p>Sorry, Out of Service.</p>}>
Expand Down
20 changes: 20 additions & 0 deletions app/routes/posts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createRoute } from "honox/factory";
import { PostsPresenter } from "../components/posts/PostsPresenter";

export type Meta = {
title: string;
publishedAt: string;
};

export default createRoute(async (c) => {
const rawPosts = import.meta.glob<{ frontmatter: Meta }>("./posts/*.mdx", {
eager: true,
});
const posts = Object.entries(rawPosts).map(([id, module]) => ({
id: id.replace(/\.mdx$/, ""),
title: module.frontmatter.title ?? "",
publishedAt: module.frontmatter.publishedAt ?? "",
}));

return c.render(<PostsPresenter posts={posts} />);
});
9 changes: 9 additions & 0 deletions app/routes/posts/_renderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { jsxRenderer } from "hono/jsx-renderer";

export default jsxRenderer(({ children, Layout, frontmatter }) => {
return (
<Layout title={frontmatter?.title}>
<article class="markdown-body">{children}</article>
</Layout>
);
});
35 changes: 35 additions & 0 deletions app/routes/posts/md_test.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "Markdown試し打ち"
publishedAt: "2024-09-XX"
---

# # Markdown試し打ち

これはMarkdownの試し打ちです。適宜チューニングしていきたい。以下、怪文書が続きます。

## ## Section 1

**以下は、法学部の生徒が学ぶ代表的な法律の分野です。**

- 刑法
- 民法
- 民法総則
- 債権総論
- etc...
- 憲法

とある法学部の学生が、法律の勉強をしているときに、次のような名言を思い出しました。

> Sweet are the uses of adversity, Which, like the toad, ugly and venomous, Wears yet a precious jewel in his head.
>
> Shakespeare
### ### Section 2

~ねこ~ いぬ(w300 * h200)
<img width="300" height="200" src="https://images.dog.ceo/breeds/terrier-welsh/lucy.jpg" />

動物の画像を表示してみました。
- [ ] 犬はkawaii
- [x] 猫もkawaii

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "taga3s-dev",
"name": "taga3s-dev-website",
"type": "module",
"version": "1.0.1",
"license": "MIT",
Expand All @@ -22,8 +22,12 @@
"@hono/vite-cloudflare-pages": "^0.4.2",
"@hono/vite-dev-server": "^0.14.0",
"@hono/vite-ssg": "^0.1.0",
"@mdx-js/rollup": "^3.0.1",
"husky": "^9.1.1",
"lint-staged": "^15.2.7",
"remark-frontmatter": "^5.0.0",
"remark-mdx-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"vite": "^5.4.2",
"wrangler": "^3.72.2"
},
Expand Down
Loading

0 comments on commit 449c5f9

Please sign in to comment.