[fix] reorganize the typing files

This commit is contained in:
PrinOrange
2024-09-26 16:48:47 +08:00
parent 7e7b86c1e5
commit f00a79fcf3
19 changed files with 49 additions and 50 deletions

View File

@@ -1,25 +1,25 @@
import fs from "fs";
import path from "path";
import { PostFilesDirectory } from "@/consts/consts";
import type { TFrontmatter } from "@/types/frontmatter.type";
import type { TPostListItem, TPostsByTag } from "@/types/post-list";
import type { TPostFrontmatter } from "@/types/frontmatter.type";
import type { TPostListItem, TPostsByTag } from "@/types/docs.type";
import { serialize } from "next-mdx-remote/serialize";
import { titleCase } from "title-case";
import { isEmptyString, nullifyEmptyArray, nullifyEmptyString } from "./utils";
async function extractFrontmatters(filepath: string): Promise<TFrontmatter> {
async function extractFrontmatters(filepath: string): Promise<TPostFrontmatter> {
const source = fs.readFileSync(filepath, "utf-8");
const mdxSource = await serialize(source, {
parseFrontmatter: true,
mdxOptions: { format: "md" },
});
const frontmatter = mdxSource.frontmatter as TFrontmatter;
const frontmatter = mdxSource.frontmatter as TPostFrontmatter;
const normalizedTags = frontmatter.tags
?.filter((tagname) => !isEmptyString(tagname))
.map((tagname) => tagname.toUpperCase());
const normalizedResult: TFrontmatter = {
const normalizedResult: TPostFrontmatter = {
title: titleCase(frontmatter.title),
subtitle: nullifyEmptyString(frontmatter.subtitle),
coverURL: nullifyEmptyString(frontmatter.coverURL),

View File

@@ -1,4 +1,4 @@
import type { TTOCItem } from "@/types/toc.type";
import type { TTOCItem } from "@/types/docs.type";
import { JSDOM } from "jsdom";
/**

View File

@@ -1,4 +1,3 @@
import type { NonEmptyArray } from "@/types/utils.type";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
@@ -84,11 +83,11 @@ export function isEmptyArray(value: any[] | null | undefined): boolean {
* @param value - The array value to be nullified if empty.
* @returns The nullified array if it is empty, otherwise returns the original array.
*/
export function nullifyEmptyArray<T>(value: T[] | null | undefined): NonEmptyArray<T> | null {
export function nullifyEmptyArray<T>(value: T[] | null | undefined): T[] | null {
if (isEmptyArray(value)) {
return null;
}
return value as NonEmptyArray<T>;
return value!;
}
/**