[upgrade] Abstract components on the page into subcomponents

This commit is contained in:
PrinOrange
2024-09-28 00:18:55 +08:00
parent f00a79fcf3
commit 959e513dcd
31 changed files with 508 additions and 374 deletions

View File

@@ -1,8 +1,7 @@
import fs from "fs";
import path from "path";
import { PostFilesDirectory } from "@/consts/consts";
import type { TPostFrontmatter } from "@/types/frontmatter.type";
import type { TPostListItem, TPostsByTag } from "@/types/docs.type";
import type { TPostFrontmatter, TPostListItem, TPostsByTag } from "@/types/docs.type";
import { serialize } from "next-mdx-remote/serialize";
import { titleCase } from "title-case";
import { isEmptyString, nullifyEmptyArray, nullifyEmptyString } from "./utils";
@@ -93,7 +92,7 @@ const sortOutPosts = async (): Promise<{
});
allPostList.forEach((item) => {
item.frontMatter.tags?.forEach((tagName) => {
item.frontMatter.tags?.forEach((tagName: string) => {
if (postsByTag[tagName] == null) {
postsByTag[tagName] = [];
}

View File

@@ -65,7 +65,7 @@ export const generateRSSFeed = async () => {
for (let i = 0; i < Math.min(LatestPostCountInHomePage, sortedPosts.allPostList.length); i++) {
const post = sortedPosts.allPostList[i];
const postFileContent = `${getPostFileContent(post.id)}${NoticeForRSSReaders(post.id)}`;
const dateNumber = post.frontMatter.time.split("-").map((num) => Number.parseInt(num));
const dateNumber = post.frontMatter.time.split("-").map((num: string) => Number.parseInt(num));
const mdxSource = await serialize(postFileContent ?? "", {
parseFrontmatter: true,
mdxOptions: {
@@ -89,7 +89,9 @@ export const generateRSSFeed = async () => {
link: `https://${Config.SiteDomain}/about`,
},
],
category: post.frontMatter.tags?.map((tagname) => ({ name: tagname })),
category: post.frontMatter.tags?.map((tagname: string) => ({
name: tagname,
})),
date: new Date(dateNumber[0], dateNumber[1], dateNumber[2]),
image: post.frontMatter.coverURL ?? undefined,
});

View File

@@ -1,4 +1,4 @@
import type { TTOCItem } from "@/types/docs.type";
import type { TPostTOCItem } from "@/types/docs.type";
import { JSDOM } from "jsdom";
/**
@@ -10,7 +10,7 @@ import { JSDOM } from "jsdom";
export const makeTOCTree = (htmlCode: string) => {
const doc_dom = new JSDOM(htmlCode);
const all_headers = doc_dom.window.document.querySelectorAll("h1,h2,h3,h4,h5,h6");
const result: TTOCItem[] = [];
const result: TPostTOCItem[] = [];
for (let i = 0; i < all_headers.length; i++) {
const level = Number.parseInt(all_headers[i].tagName.replace("H", ""));
result.push({