mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 23:32:53 +01:00
feat: initial commit
(cherry picked from commit 44c4d7b9521fe449e61edc614446195861932f8c)
This commit is contained in:
37
src/utils/config-utils.ts
Normal file
37
src/utils/config-utils.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import _config from '../../vivia.config.yml';
|
||||
|
||||
interface ViviaConfig {
|
||||
menu: {
|
||||
[key: string]: string;
|
||||
};
|
||||
appearance: {
|
||||
hue: number;
|
||||
};
|
||||
favicon: string;
|
||||
banner: {
|
||||
enable: boolean;
|
||||
url: string;
|
||||
position: string;
|
||||
onAllPages: boolean;
|
||||
};
|
||||
sidebar: {
|
||||
widgets: {
|
||||
normal: string | string[];
|
||||
sticky: string | string[];
|
||||
};
|
||||
};
|
||||
profile: {
|
||||
avatar: string;
|
||||
author: string;
|
||||
subtitle: string;
|
||||
links: {
|
||||
name: string;
|
||||
icon: string;
|
||||
url: string;
|
||||
}[];
|
||||
}
|
||||
}
|
||||
|
||||
const config: ViviaConfig = _config;
|
||||
|
||||
export const getConfig = () => config;
|
||||
32
src/utils/content-utils.ts
Normal file
32
src/utils/content-utils.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {getCollection} from "astro:content";
|
||||
|
||||
export async function getSortedPosts() {
|
||||
const allBlogPosts = await getCollection("posts");
|
||||
return allBlogPosts.sort((a, b) => {
|
||||
const dateA = new Date(a.data.pubDate);
|
||||
const dateB = new Date(b.data.pubDate);
|
||||
return dateA > dateB ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
export function getPostUrlBySlug(slug: string): string {
|
||||
return `/posts/${slug}`;
|
||||
}
|
||||
|
||||
export async function getTagList(): Promise<{ name: string; count: number }[]> {
|
||||
const allBlogPosts = await getCollection("posts");
|
||||
|
||||
const countMap: { [key: string]: number } = {};
|
||||
allBlogPosts.map((post) => {
|
||||
post.data.tags.map((tag: string) => {
|
||||
if (!countMap[tag]) countMap[tag] = 0;
|
||||
countMap[tag]++;
|
||||
})
|
||||
});
|
||||
|
||||
// 获取对象的所有键并按字典顺序排序
|
||||
const keys: string[] = Object.keys(countMap).sort();
|
||||
|
||||
// 使用排序后的键构建包含 key 和 value 的数组
|
||||
return keys.map((key) => ({name: key, count: countMap[key]}));
|
||||
}
|
||||
7
src/utils/date-utils.ts
Normal file
7
src/utils/date-utils.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function formatDateToYYYYMMDD(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = date.getDate().toString().padStart(2, '0');
|
||||
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
5
src/utils/url-utils.ts
Normal file
5
src/utils/url-utils.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function pathsEqual(path1: string, path2: string) {
|
||||
const normalizedPath1 = path1.replace(/^\/|\/$/g, '').toLowerCase();
|
||||
const normalizedPath2 = path2.replace(/^\/|\/$/g, '').toLowerCase();
|
||||
return normalizedPath1 === normalizedPath2;
|
||||
}
|
||||
Reference in New Issue
Block a user