mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
refactor: update imports and frontmatter types
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { slufigyAll } from "./slugify";
|
||||
import type { MarkdownInstance } from "astro";
|
||||
import type { Frontmatter } from "../types";
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
|
||||
const getPostsByTag = (posts: MarkdownInstance<Frontmatter>[], tag: string) =>
|
||||
posts.filter(post => slufigyAll(post.frontmatter.tags).includes(tag));
|
||||
const getPostsByTag = (posts: CollectionEntry<"blog">[], tag: string) =>
|
||||
posts.filter(post => slufigyAll(post.data.tags).includes(tag));
|
||||
|
||||
export default getPostsByTag;
|
||||
|
||||
@@ -5,8 +5,8 @@ const getSortedPosts = (posts: CollectionEntry<"blog">[]) =>
|
||||
.filter(({ data }) => !data.draft)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
Math.floor(new Date(b.data.publishDatetime).getTime() / 1000) -
|
||||
Math.floor(new Date(a.data.publishDatetime).getTime() / 1000)
|
||||
Math.floor(new Date(b.data.pubDatetime).getTime() / 1000) -
|
||||
Math.floor(new Date(a.data.pubDatetime).getTime() / 1000)
|
||||
);
|
||||
|
||||
export default getSortedPosts;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { slugifyStr } from "./slugify";
|
||||
import type { MarkdownInstance } from "astro";
|
||||
import type { Frontmatter } from "../types";
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
|
||||
const getUniqueTags = (posts: MarkdownInstance<Frontmatter>[]) => {
|
||||
const getUniqueTags = (posts: CollectionEntry<"blog">[]) => {
|
||||
let tags: string[] = [];
|
||||
const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft);
|
||||
const filteredPosts = posts.filter(({ data }) => !data.draft);
|
||||
filteredPosts.forEach(post => {
|
||||
tags = [...tags, ...post.frontmatter.tags]
|
||||
tags = [...tags, ...post.data.tags]
|
||||
.map(tag => slugifyStr(tag))
|
||||
.filter(
|
||||
(value: string, index: number, self: string[]) =>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { slug as slugger } from "github-slugger";
|
||||
import type { BlogFrontmatter } from "@content/_schemas";
|
||||
|
||||
export const slugifyStr = (str: string) => slugger(str);
|
||||
|
||||
const slugify = (post: CollectionEntry<"blog">) =>
|
||||
post.data.slug ? slugger(post.data.slug) : post.slug;
|
||||
const slugify = (post: BlogFrontmatter) =>
|
||||
post.postSlug ? slugger(post.postSlug) : slugger(post.title);
|
||||
|
||||
export const slufigyAll = (arr: string[]) => arr.map(str => slugifyStr(str));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user