mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 15:22:52 +01:00
feat: make 'uncategorized' a category
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { getCollection } from 'astro:content'
|
||||
import {UNCATEGORIZED} from "@constants/constants.ts";
|
||||
import {i18n} from "@i18n/translation.ts";
|
||||
import I18nKey from "@i18n/i18nKey.ts";
|
||||
|
||||
export async function getSortedPosts() {
|
||||
const allBlogPosts = await getCollection('posts', ({ data }) => {
|
||||
@@ -60,12 +63,11 @@ export async function getCategoryList(): Promise<Category[]> {
|
||||
const count: { [key: string]: number } = {}
|
||||
allBlogPosts.map(post => {
|
||||
if (!post.data.category) {
|
||||
const ucKey = i18n(I18nKey.uncategorized);
|
||||
count[ucKey] = count[ucKey] ? count[ucKey] + 1 : 1
|
||||
return
|
||||
}
|
||||
if (!count[post.data.category]) {
|
||||
count[post.data.category] = 0
|
||||
}
|
||||
count[post.data.category]++
|
||||
count[post.data.category] = count[post.data.category] ? count[post.data.category] + 1 : 1
|
||||
})
|
||||
|
||||
const lst = Object.keys(count).sort((a, b) => {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {i18n} from "@i18n/translation.ts";
|
||||
import i18nKey from "@i18n/i18nKey.ts";
|
||||
|
||||
export function pathsEqual(path1: string, path2: string) {
|
||||
const normalizedPath1 = path1.replace(/^\/|\/$/g, '').toLowerCase()
|
||||
const normalizedPath2 = path2.replace(/^\/|\/$/g, '').toLowerCase()
|
||||
@@ -15,7 +18,10 @@ export function getPostUrlBySlug(slug: string): string | null {
|
||||
}
|
||||
|
||||
export function getCategoryUrl(category: string): string | null {
|
||||
if (!category) return null
|
||||
if (!category)
|
||||
return null
|
||||
if (category === i18n(i18nKey.uncategorized))
|
||||
return '/archive/category/uncategorized'
|
||||
return `/archive/category/${category}`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user