[fix] reorganize the typing files
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { TTOCItem } from "@/types/toc.type";
|
||||
import type { TTOCItem } from "@/types/docs.type";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
/**
|
||||
|
||||
@@ -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!;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user