Skip to content

Commit

Permalink
Merge pull request #295 from gagahpangeran/generate-static-routes
Browse files Browse the repository at this point in the history
Generate static page for all blog routes
  • Loading branch information
gagahpangeran authored Feb 24, 2025
2 parents c4b4888 + 3190366 commit 0e26b1f
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 286 deletions.
78 changes: 78 additions & 0 deletions src/app/blog/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) Gagah Pangeran Rosfatiputra (GPR) <[email protected]>.
// Licensed under The MIT License.
// Read the LICENSE file in the repository root for full license text.

import { type Metadata } from "next";
import { notFound } from "next/navigation";
import Blog from "@/templates/Blog";
import Post from "@/templates/Post";
import {
getOtherMetadata,
getPageMetadata,
notFoundMetadata
} from "@/utils/metadata";
import { getAllBlogPageRoutes, getBlogPageDataBySlug } from "@/utils/page";

interface Props {
params: Promise<{ slug?: string[] }>;
}

export const dynamicParams = false;

export async function generateStaticParams() {
const allRoutes = getAllBlogPageRoutes();
const allSlugs = allRoutes.map(route => {
const [_, ...slug] = route.split("/").filter(Boolean);
return { slug };
});
return allSlugs;
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params;
const data = getBlogPageDataBySlug(slug);

if (data == null) {
return notFoundMetadata;
}

if (data.kind === "post") {
const { title, description, image } = data.post;
return {
title,
description,
...getOtherMetadata(title, description, image)
};
}

const { type, filterValue } = data;
const metadata = getPageMetadata({ type, filterValue });

if (metadata == null) {
return notFoundMetadata;
}

return metadata;
}

export default async function BlogPage({ params }: Props) {
const { slug } = await params;
const data = getBlogPageDataBySlug(slug);

if (data == null) {
notFound();
}

if (data.kind === "post") {
return <Post post={data.post} />;
}

const { type, filterValue } = data;

const metadata = getPageMetadata({ type, filterValue });
if (metadata == null) {
notFound();
}

return <Blog {...metadata} {...data} />;
}
81 changes: 0 additions & 81 deletions src/app/blog/[slug]/page.tsx

This file was deleted.

72 changes: 0 additions & 72 deletions src/app/blog/lang/[...slug]/page.tsx

This file was deleted.

43 changes: 0 additions & 43 deletions src/app/blog/page.tsx

This file was deleted.

72 changes: 0 additions & 72 deletions src/app/blog/tag/[...slug]/page.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions src/app/changelog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Link from "next/link";
import Page from "@/templates/Page";
import { getAllReleases } from "@/utils/changelog";

export const revalidate = 0;

const title = "Changelog";
const desc = "All release changelog";

Expand Down
Loading

0 comments on commit 0e26b1f

Please sign in to comment.