Skip to content

Commit

Permalink
feat(site/blog): update to nextjs v15
Browse files Browse the repository at this point in the history
  • Loading branch information
qhanw committed Jan 6, 2025
1 parent 1de9087 commit d863156
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 401 deletions.
7 changes: 0 additions & 7 deletions site/blog/.eslintrc.json

This file was deleted.

13 changes: 9 additions & 4 deletions site/blog/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage
Expand All @@ -24,9 +28,10 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local
# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel
Expand Down
19 changes: 10 additions & 9 deletions site/blog/app/(web)/code-snippets/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Metadata, ResolvingMetadata } from "next";
import { Metadata /** ResolvingMetadata */ } from "next";
import Link from "next/link";

// import { remark } from "remark";
Expand All @@ -21,12 +21,13 @@ import MDXContent from "./MDXContent";
import "./styles.scss";

type Props = {
params: { slug: string };
searchParams: { [key: string]: string | string[] | undefined };
params: Promise<{ slug: string }>;
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
};

async function fetchCodeSnippet(params: Props["params"]) {
const post = getCodeSnippet(params.slug);
const slug = (await params).slug;
const post = getCodeSnippet(slug);
// const markdown = await remark()
// .use(remarkToc, { maxDepth: 4 })
// .use(remarkGfm)
Expand All @@ -38,7 +39,7 @@ async function fetchCodeSnippet(params: Props["params"]) {
// .process(post.content || "");

const posts = getAllCodeSnippets();
const idx = posts.findIndex((c) => c.slug === params.slug);
const idx = posts.findIndex((c) => c.slug === slug);

const next = posts[idx + 1];
const prev = posts[idx - 1];
Expand All @@ -60,10 +61,10 @@ export async function generateStaticParams() {
}

export async function generateMetadata(
{ params, searchParams }: Props,
parent: ResolvingMetadata
props: Props
// parent: ResolvingMetadata
): Promise<Metadata> {
const { post } = await fetchCodeSnippet(params);
const { post } = await fetchCodeSnippet(props.params);
return seo({
title: post?.meta?.title || "",
description: post?.meta?.description || post?.excerpt || "",
Expand Down Expand Up @@ -97,7 +98,7 @@ export default async ({ params }: Props) => {
<time className="inline-flex items-center ml-2">
<span className="i-heroicons:clock mr-1 w-4 h-4 text-brand" />
阅读
{Math.ceil(post.meta?.readingTime?.minutes!)}
{Math.ceil(post.meta?.readingTime?.minutes ?? 0)}
分钟
</time>
</div>
Expand Down
2 changes: 1 addition & 1 deletion site/blog/app/(web)/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getGitLastUpdatedTimeStamp(filePath: string) {
).stdout.toString("utf-8");

lastUpdated = timestamp ? new Date(parseInt(timestamp) * 1000) : new Date();
} catch (e) {
} catch {
/* do not handle for now */
}
return lastUpdated;
Expand Down
23 changes: 12 additions & 11 deletions site/blog/app/(web)/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Metadata, ResolvingMetadata } from "next";
import { Metadata /* ResolvingMetadata */ } from "next";
import Link from "next/link";

// import { remark } from "remark";
Expand All @@ -21,12 +21,13 @@ import MDXContent from "./MDXContent";
import "./styles.scss";

type Props = {
params: { slug: string };
searchParams: { [key: string]: string | string[] | undefined };
params: Promise<{ slug: string }>;
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
};

async function fetchPost(params: Props["params"]) {
const post = getPost(params.slug);
const slug = (await params).slug;
const post = getPost(slug);
// const markdown = await remark()
// .use(remarkToc, { maxDepth: 4 })
// .use(remarkGfm)
Expand All @@ -38,7 +39,7 @@ async function fetchPost(params: Props["params"]) {
// .process(post.content || "");

const posts = getAllPosts();
const idx = posts.findIndex((c) => c.slug === params.slug);
const idx = posts.findIndex((c) => c.slug === slug);

const next = posts[idx + 1];
const prev = posts[idx - 1];
Expand All @@ -60,18 +61,18 @@ export async function generateStaticParams() {
}

export async function generateMetadata(
{ params, searchParams }: Props,
parent: ResolvingMetadata
props: Props
// parent: ResolvingMetadata
): Promise<Metadata> {
const { post } = await fetchPost(params);
const { post } = await fetchPost(props.params);
return seo({
title: post?.meta?.title || "",
description: post?.meta?.description || post?.excerpt || "",
});
}

export default async ({ params }: Props) => {
const { post, prev, next } = await fetchPost(params);
export default async (props: Props) => {
const { post, prev, next } = await fetchPost(props.params);

// const message = await new Promise<string>((resolve) => {
// console.log("in executing sleep!");
Expand All @@ -97,7 +98,7 @@ export default async ({ params }: Props) => {
<time className="inline-flex items-center ml-2">
<span className="i-heroicons:clock mr-1 w-4 h-4 text-brand" />
阅读
{Math.ceil(post.meta?.readingTime?.minutes!)}
{Math.ceil(post.meta?.readingTime?.minutes ?? 0)}
分钟
</time>
</div>
Expand Down
5 changes: 2 additions & 3 deletions site/blog/app/(web)/projects/components/PicGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ type PicGalleryProps = {

export default function PicGallery({ id, images }: PicGalleryProps) {
useEffect(() => {
let lightbox = new PhotoSwipeLightbox({
let lightbox: PhotoSwipeLightbox | null = new PhotoSwipeLightbox({
gallery: "#" + id,
children: "a",
pswpModule: () => import("photoswipe"),
});
lightbox.init();

return () => {
lightbox.destroy();
lightbox?.destroy();

// @ts-ignore
lightbox = null;
};
}, [id]);
Expand Down
1 change: 0 additions & 1 deletion site/blog/app/(web)/projects/kupo-monitor/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Footer from "@/app/(web)/components/Footer";
import seo from "@/utils/seo";
import Image from "next/image";

import PicGallery from "../components/PicGallery";

Expand Down
1 change: 0 additions & 1 deletion site/blog/app/(web)/projects/luban/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Footer from "@/app/(web)/components/Footer";
import seo from "@/utils/seo";
import Image from "next/image";

import PicGallery from "../components/PicGallery";

Expand Down
23 changes: 23 additions & 0 deletions site/blog/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
{
rules: {
"import/no-anonymous-default-export": "off",
"react/display-name": "off",
"@typescript-eslint/no-explicit-any": "off",
},
},
];

export default eslintConfig;
2 changes: 1 addition & 1 deletion site/blog/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
4 changes: 0 additions & 4 deletions site/blog/next.config.js

This file was deleted.

7 changes: 7 additions & 0 deletions site/blog/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
12 changes: 6 additions & 6 deletions site/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"clsx": "^2.1.1",
"dayjs": "^1.11.13",
"gray-matter": "^4.0.3",
"next": "15.1.3",
"next": "^15.1.3",
"next-mdx-remote": "^5.0.0",
"next-themes": "^0.4.4",
"nextjs-toploader": "^3.7.15",
"photoswipe": "^5.4.4",
"plyr": "^3.7.8",
"react": "19.0.0",
"react-dom": "19.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-use": "^17.6.0",
"reading-time": "^1.5.0",
"rehype-autolink-headings": "^7.1.0",
Expand All @@ -43,9 +43,9 @@
"@types/react-dom": "19.0.2",
"@unocss/postcss": "^0.65.3",
"@vercel/analytics": "^1.4.1",
"autoprefixer": "10.4.20",
"eslint": "9.17.0",
"eslint-config-next": "15.1.3",
"eslint": "^9.17.0",
"eslint-config-next": "^15.1.3",
"@eslint/eslintrc": "^3.2.0",
"postcss": "8.4.49",
"sass": "^1.83.1",
"typescript": "5.7.2",
Expand Down
Loading

0 comments on commit d863156

Please sign in to comment.