Skip to content

Commit

Permalink
Update: Use new category info
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Feb 23, 2024
1 parent bbb8a9e commit 7b9c1c9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/(hayao)/blog/category/[cat]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PostData } from "@/lib/markdown/post";
export default async function Categories({ params }: { params: { cat: string } }) {
const postpost = getPostList(params.cat);

//console.log(params.cat);
//console.log(decodeURI(params.cat));

return (
<CommonSpacer>
Expand Down
7 changes: 3 additions & 4 deletions src/app/(hayao)/blog/category/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Link from "next/link";

import CommonSpacer from "@/components/layouts/CommonSpacer";
import { getAllCategories } from "@/lib/blog/categories";
import { CATEGORY_DESC } from "@/lib/blog/config";
import { findCategoryInfo, getAllCategories } from "@/lib/blog/categories";

export default function CategoryTop() {
const categories = getAllCategories();
Expand All @@ -20,9 +19,9 @@ export default function CategoryTop() {
}

const Category = ({ category }: { category: string }) => {
const descList: { [key: string]: string } = CATEGORY_DESC;
const catInfo = findCategoryInfo(category);

const desc = descList[category] ? descList[category] : "";
const desc = catInfo ? catInfo.desc : "";
const link = `/blog/category/${category}`;

return (
Expand Down
3 changes: 1 addition & 2 deletions src/app/(hayao)/blog/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import Link from "next/link";

import { Heading } from "@/components/elements/Heading";
import CommonSpacer from "@/components/layouts/CommonSpacer";
import { fetchedBlogPostList } from "@/lib/blog/post";
import { fetchedBlogPostList as postlist } from "@/lib/blog/post";

export default function BlogLayout({ children }: { children: React.ReactNode }) {
const postlist = fetchedBlogPostList;
const categories = postlist.getAllCategories();
const tags = postlist.getAllTags();
const posts = postlist.getPosts().slice(undefined, 10);
Expand Down
18 changes: 15 additions & 3 deletions src/lib/blog/categories.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { CATEGORY_INFO } from "./config";
import { fetchedBlogPostList } from "./post";

export type Category = {
jp: string;
url: string;
desc: string;
};

export const getAllCategories = () => fetchedBlogPostList.getAllCategories();

export const findCategoryInfo = (category: string) => {
const catingo: { jp: string; url: string; desc: string }[] = getCategoryInfo();
return catingo.filter((c) => c.url === category || c.jp === category)[0];
export const findCategoryInfo = (category: string): Category | null => {
const catingo = getCategoryInfo();
const matched = catingo.filter((c) => c.url === category || c.jp === category);

if (matched.length === 0) {
return null;
}

return matched[0];
};

export const getCategoryInfo = () => {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/blog/config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import path from "path";

import { URLFormat } from "../markdown/url";
import { Category } from "./categories";

export const POSTLIST_ONEPAGE = 9;
export const MDFILE_DIR = path.join(process.cwd(), "posts");
export const SUMMARY_LENGTH = 200;
export const CATEGORY_DESC = {
プライベート: "プライベートなこと",
};

export const BLOG_URL_FORMAT: URLFormat = {
cutHead: path.join(process.cwd()).replaceAll(path.sep, "/").split("/").length + 1,
};

export const CATEGORY_INFO: { jp: string; url: string; desc: string }[] = [
export const CATEGORY_INFO: Category[] = [
{
jp: "プライベート",
url: "private",
Expand Down

0 comments on commit 7b9c1c9

Please sign in to comment.