feat: add FrontMatter CMS, biome, translation, etc.

* add Frontmatter CMS

* add biome

* update

* update

* fixed & add docs

* fix translation.ts

* fix translation
This commit is contained in:
L4Ph
2024-01-21 13:54:41 +09:00
committed by GitHub
parent f9a78b3e3b
commit 197d524b53
42 changed files with 2714 additions and 12795 deletions

View File

@@ -1,74 +1,74 @@
import {CollectionEntry, getCollection} from "astro:content";
import { getCollection } from 'astro:content'
export async function getSortedPosts() {
const allBlogPosts = await getCollection("posts");
const sorted = allBlogPosts.sort((a, b) => {
const dateA = new Date(a.data.published);
const dateB = new Date(b.data.published);
return dateA > dateB ? -1 : 1;
});
const allBlogPosts = await getCollection('posts')
const sorted = allBlogPosts.sort((a, b) => {
const dateA = new Date(a.data.published)
const dateB = new Date(b.data.published)
return dateA > dateB ? -1 : 1
})
for (let i = 1; i < sorted.length; i++) {
sorted[i].data.nextSlug = sorted[i - 1].slug;
sorted[i].data.nextTitle = sorted[i - 1].data.title;
}
for (let i = 0; i < sorted.length - 1; i++) {
sorted[i].data.prevSlug = sorted[i + 1].slug;
sorted[i].data.prevTitle = sorted[i + 1].data.title;
}
for (let i = 1; i < sorted.length; i++) {
sorted[i].data.nextSlug = sorted[i - 1].slug
sorted[i].data.nextTitle = sorted[i - 1].data.title
}
for (let i = 0; i < sorted.length - 1; i++) {
sorted[i].data.prevSlug = sorted[i + 1].slug
sorted[i].data.prevTitle = sorted[i + 1].data.title
}
return sorted;
return sorted
}
export type Tag = {
name: string;
count: number;
name: string
count: number
}
export async function getTagList(): Promise<Tag[]> {
const allBlogPosts = await getCollection("posts");
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 countMap: { [key: string]: number } = {}
allBlogPosts.map(post => {
post.data.tags.map((tag: string) => {
if (!countMap[tag]) countMap[tag] = 0
countMap[tag]++
})
})
// sort tags
const keys: string[] = Object.keys(countMap).sort((a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
// sort tags
const keys: string[] = Object.keys(countMap).sort((a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase())
})
return keys.map((key) => ({name: key, count: countMap[key]}));
return keys.map(key => ({ name: key, count: countMap[key] }))
}
export type Category = {
name: string;
count: number;
name: string
count: number
}
export async function getCategoryList(): Promise<Category[]> {
const allBlogPosts = await getCollection("posts");
let count : {[key: string]: number} = {};
allBlogPosts.map((post) => {
if (!post.data.category) {
return;
}
if (!count[post.data.category]) {
count[post.data.category] = 0;
}
count[post.data.category]++;
});
let lst = Object.keys(count).sort((a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
let ret : Category[] = [];
for (const c of lst) {
ret.push({name: c, count: count[c]});
const allBlogPosts = await getCollection('posts')
const count: { [key: string]: number } = {}
allBlogPosts.map(post => {
if (!post.data.category) {
return
}
return ret;
}
if (!count[post.data.category]) {
count[post.data.category] = 0
}
count[post.data.category]++
})
const lst = Object.keys(count).sort((a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase())
})
const ret: Category[] = []
for (const c of lst) {
ret.push({ name: c, count: count[c] })
}
return ret
}

View File

@@ -1,7 +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');
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}`;
return `${year}-${month}-${day}`
}

View File

@@ -1,24 +1,20 @@
export function pathsEqual(path1: string, path2: string) {
const normalizedPath1 = path1.replace(/^\/|\/$/g, '').toLowerCase();
const normalizedPath2 = path2.replace(/^\/|\/$/g, '').toLowerCase();
return normalizedPath1 === normalizedPath2;
const normalizedPath1 = path1.replace(/^\/|\/$/g, '').toLowerCase()
const normalizedPath2 = path2.replace(/^\/|\/$/g, '').toLowerCase()
return normalizedPath1 === normalizedPath2
}
function joinUrl(...parts: string[]): string {
const joined = parts.join('/');
return joined.replace(/([^:]\/)\/+/g, '$1');
const joined = parts.join('/')
return joined.replace(/([^:]\/)\/+/g, '$1')
}
export function getPostUrlBySlug(slug: string): string | null {
if (!slug)
return null;
return `/posts/${slug}`;
if (!slug) return null
return `/posts/${slug}`
}
export function getCategoryUrl(category: string): string | null {
if (!category)
return null;
return `/archive/category/${category}`;
if (!category) return null
return `/archive/category/${category}`
}