mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
refactor: use astro generated CollectionEntry type
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
import { slugifyStr } from "@utils/slugify";
|
import { slugifyStr } from "@utils/slugify";
|
||||||
import Datetime from "./Datetime";
|
import Datetime from "./Datetime";
|
||||||
import type { BlogFrontmatter } from "@content/_schemas";
|
import type { CollectionEntry } from "astro:content";
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
href?: string;
|
href?: string;
|
||||||
frontmatter: BlogFrontmatter;
|
frontmatter: CollectionEntry<"blog">["data"];
|
||||||
secHeading?: boolean;
|
secHeading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import Fuse from "fuse.js";
|
|||||||
import { useEffect, useRef, useState, useMemo } from "react";
|
import { useEffect, useRef, useState, useMemo } from "react";
|
||||||
import Card from "@components/Card";
|
import Card from "@components/Card";
|
||||||
import slugify from "@utils/slugify";
|
import slugify from "@utils/slugify";
|
||||||
import type { BlogFrontmatter } from "@content/_schemas";
|
import type { CollectionEntry } from "astro:content";
|
||||||
|
|
||||||
export type SearchItem = {
|
export type SearchItem = {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
data: BlogFrontmatter;
|
data: CollectionEntry<"blog">["data"];
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|||||||
@@ -14,5 +14,3 @@ export const blogSchema = z
|
|||||||
canonicalURL: z.string().optional(),
|
canonicalURL: z.string().optional(),
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export type BlogFrontmatter = z.infer<typeof blogSchema>;
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { slug as slugger } from "github-slugger";
|
import { slug as slugger } from "github-slugger";
|
||||||
import type { BlogFrontmatter } from "@content/_schemas";
|
import type { CollectionEntry } from "astro:content";
|
||||||
|
|
||||||
export const slugifyStr = (str: string) => slugger(str);
|
export const slugifyStr = (str: string) => slugger(str);
|
||||||
|
|
||||||
const slugify = (post: BlogFrontmatter) =>
|
const slugify = (post: CollectionEntry<"blog">["data"]) =>
|
||||||
post.postSlug ? slugger(post.postSlug) : slugger(post.title);
|
post.postSlug ? slugger(post.postSlug) : slugger(post.title);
|
||||||
|
|
||||||
export const slugifyAll = (arr: string[]) => arr.map(str => slugifyStr(str));
|
export const slugifyAll = (arr: string[]) => arr.map(str => slugifyStr(str));
|
||||||
|
|||||||
Reference in New Issue
Block a user