mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
refactor: replace postSlug with Astro content slug
* refactor: replace postSlug with Astro content slug Remove postSlug from blog schema. Refactor articles that use postSlug. Remove slugify function from slugify util file. Replace slugify logic with Astro's content collections slug logic. Closes: #186 * docs: update docs for removed slugify contents * refactor: remove unused import
This commit is contained in:
@@ -8,7 +8,6 @@ import Hr from "@components/Hr.astro";
|
||||
import Card from "@components/Card";
|
||||
import Socials from "@components/Socials.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import slugify from "@utils/slugify";
|
||||
import { SOCIALS } from "@config";
|
||||
|
||||
const posts = await getCollection("blog");
|
||||
@@ -49,7 +48,7 @@ const socialCount = SOCIALS.filter(social => social.active).length;
|
||||
<p>
|
||||
Read the blog posts or check
|
||||
<LinkButton
|
||||
className="hover:text-skin-accent underline underline-offset-4 decoration-dashed"
|
||||
className="underline decoration-dashed underline-offset-4 hover:text-skin-accent"
|
||||
href="https://github.com/satnaing/astro-paper#readme"
|
||||
>
|
||||
README
|
||||
@@ -74,9 +73,9 @@ const socialCount = SOCIALS.filter(social => social.active).length;
|
||||
<section id="featured">
|
||||
<h2>Featured</h2>
|
||||
<ul>
|
||||
{featuredPosts.map(({ data }) => (
|
||||
{featuredPosts.map(({ data, slug }) => (
|
||||
<Card
|
||||
href={`/posts/${slugify(data)}`}
|
||||
href={`/posts/${slug}`}
|
||||
frontmatter={data}
|
||||
secHeading={false}
|
||||
/>
|
||||
@@ -95,10 +94,10 @@ const socialCount = SOCIALS.filter(social => social.active).length;
|
||||
sortedPosts
|
||||
.filter(({ data }) => !data.featured)
|
||||
.map(
|
||||
({ data }, index) =>
|
||||
({ data, slug }, index) =>
|
||||
index < 4 && (
|
||||
<Card
|
||||
href={`/posts/${slugify(data)}`}
|
||||
href={`/posts/${slug}`}
|
||||
frontmatter={data}
|
||||
secHeading={false}
|
||||
/>
|
||||
|
||||
@@ -4,7 +4,6 @@ import Posts from "@layouts/Posts.astro";
|
||||
import PostDetails from "@layouts/PostDetails.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import getPageNumbers from "@utils/getPageNumbers";
|
||||
import slugify from "@utils/slugify";
|
||||
import { SITE } from "@config";
|
||||
|
||||
export interface Props {
|
||||
@@ -15,7 +14,7 @@ export async function getStaticPaths() {
|
||||
const posts = await getCollection("blog", ({ data }) => !data.draft);
|
||||
|
||||
const postResult = posts.map(post => ({
|
||||
params: { slug: slugify(post.data) },
|
||||
params: { slug: post.slug },
|
||||
props: { post },
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import rss from "@astrojs/rss";
|
||||
import { getCollection } from "astro:content";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import slugify from "@utils/slugify";
|
||||
import { SITE } from "@config";
|
||||
|
||||
export async function GET() {
|
||||
@@ -11,8 +10,8 @@ export async function GET() {
|
||||
title: SITE.title,
|
||||
description: SITE.desc,
|
||||
site: SITE.website,
|
||||
items: sortedPosts.map(({ data }) => ({
|
||||
link: `posts/${slugify(data)}`,
|
||||
items: sortedPosts.map(({ data, slug }) => ({
|
||||
link: `posts/${slug}`,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
pubDate: new Date(data.pubDatetime),
|
||||
|
||||
@@ -11,10 +11,11 @@ import SearchBar from "@components/Search";
|
||||
const posts = await getCollection("blog", ({ data }) => !data.draft);
|
||||
|
||||
// List of items to search in
|
||||
const searchList = posts.map(({ data }) => ({
|
||||
const searchList = posts.map(({ data, slug }) => ({
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
data,
|
||||
slug,
|
||||
}));
|
||||
---
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import Footer from "@components/Footer.astro";
|
||||
import Card from "@components/Card";
|
||||
import getUniqueTags from "@utils/getUniqueTags";
|
||||
import getPostsByTag from "@utils/getPostsByTag";
|
||||
import slugify from "@utils/slugify";
|
||||
import { SITE } from "@config";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
|
||||
@@ -48,8 +47,8 @@ const sortTagsPost = getSortedPosts(tagPosts);
|
||||
<h1 slot="title" transition:name={tag}>{`Tag:${tag}`}</h1>
|
||||
<ul>
|
||||
{
|
||||
sortTagsPost.map(({ data }) => (
|
||||
<Card href={`/posts/${slugify(data)}`} frontmatter={data} />
|
||||
sortTagsPost.map(({ data, slug }) => (
|
||||
<Card href={`/posts/${slug}`} frontmatter={data} />
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user