From 0ad144add3689e81841165c8249e1d8f26eeb18d Mon Sep 17 00:00:00 2001 From: saicaca Date: Sat, 3 Aug 2024 16:40:20 +0800 Subject: [PATCH] fix: fix errors and reformat code --- biome.json | 2 +- src/components/ArchivePanel.astro | 83 +++++++------- src/components/ConfigCarrier.astro | 3 +- src/components/Footer.astro | 5 +- src/components/LightDarkSwitch.svelte | 42 +++---- src/components/Navbar.astro | 33 +++--- src/components/PostCard.astro | 57 ++++++---- src/components/PostMeta.astro | 24 ++-- src/components/PostPage.astro | 6 +- src/components/Search.svelte | 81 +++++++------- src/components/control/BackToTop.astro | 2 +- src/components/control/ButtonLink.astro | 6 +- src/components/control/ButtonTag.astro | 10 +- src/components/control/Pagination.astro | 70 ++++++------ src/components/misc/ImageWrapper.astro | 51 +++++---- src/components/misc/License.astro | 29 +++-- src/components/misc/Markdown.astro | 11 +- src/components/widget/Categories.astro | 25 ++--- src/components/widget/DisplaySettings.svelte | 10 +- src/components/widget/NavMenuPanel.astro | 10 +- src/components/widget/Profile.astro | 10 +- src/components/widget/SideBar.astro | 8 +- src/components/widget/Tags.astro | 23 ++-- src/components/widget/WidgetLayout.astro | 29 ++--- src/constants/constants.ts | 6 +- src/constants/icon.ts | 77 +++++++------ src/content/config.ts | 14 +-- src/i18n/translation.ts | 2 +- src/layouts/Layout.astro | 3 +- src/layouts/MainGridLayout.astro | 9 +- src/pages/about.astro | 9 +- src/pages/archive/category/[category].astro | 29 +++-- .../archive/category/uncategorized.astro | 10 +- src/pages/archive/index.astro | 8 +- src/pages/archive/tag/[tag].astro | 39 ++++--- src/pages/robots.txt.ts | 8 +- src/pages/rss.xml.ts | 36 +++--- src/plugins/rehype-component-admonition.mjs | 27 ++--- src/plugins/rehype-component-github-card.mjs | 103 +++++++----------- src/plugins/remark-directive-rehype.js | 47 ++++---- src/plugins/remark-excerpt.js | 24 ++-- src/types/config.ts | 7 +- src/utils/setting-utils.ts | 10 +- src/utils/url-utils.ts | 4 +- 44 files changed, 547 insertions(+), 555 deletions(-) diff --git a/biome.json b/biome.json index f2af6561f..a917d3479 100644 --- a/biome.json +++ b/biome.json @@ -8,7 +8,7 @@ "formatter": { "enabled": true, "formatWithErrors": false, - "ignore": [], + "ignore": ["src/config.ts"], "indentStyle": "space", "indentWidth": 2, "lineWidth": 80 diff --git a/src/components/ArchivePanel.astro b/src/components/ArchivePanel.astro index c82dbf50a..b08bfdda6 100644 --- a/src/components/ArchivePanel.astro +++ b/src/components/ArchivePanel.astro @@ -1,63 +1,68 @@ --- -import {getSortedPosts} from "../utils/content-utils"; -import {getPostUrlBySlug} from "../utils/url-utils"; -import {i18n} from "../i18n/translation"; -import I18nKey from "../i18n/i18nKey"; -import {UNCATEGORIZED} from "@constants/constants"; +import { getSortedPosts } from '../utils/content-utils' +import { getPostUrlBySlug } from '../utils/url-utils' +import { i18n } from '../i18n/translation' +import I18nKey from '../i18n/i18nKey' +import { UNCATEGORIZED } from '@constants/constants' interface Props { - keyword?: string; - tags?: string[]; - categories?: string[]; + keyword?: string + tags?: string[] + categories?: string[] } -const { keyword, tags, categories} = Astro.props; +const { keyword, tags, categories } = Astro.props let posts = await getSortedPosts() if (Array.isArray(tags) && tags.length > 0) { - posts = posts.filter(post => - Array.isArray(post.data.tags) && post.data.tags.some(tag => tags.includes(tag)) - ); + posts = posts.filter( + post => + Array.isArray(post.data.tags) && + post.data.tags.some(tag => tags.includes(tag)), + ) } if (Array.isArray(categories) && categories.length > 0) { - posts = posts.filter(post => - (post.data.category && categories.includes(post.data.category)) || - (!post.data.category && categories.includes(UNCATEGORIZED)) - ); + posts = posts.filter( + post => + (post.data.category && categories.includes(post.data.category)) || + (!post.data.category && categories.includes(UNCATEGORIZED)), + ) } -const groups: {year: number, posts: typeof posts}[] = function () { - const groupedPosts = posts.reduce((grouped: {[year: number]: typeof posts}, post) => { - const year = post.data.published.getFullYear() - if (!grouped[year]) { - grouped[year] = [] - } - grouped[year].push(post) - return grouped - }, {}) +const groups: { year: number; posts: typeof posts }[] = (function () { + const groupedPosts = posts.reduce( + (grouped: { [year: number]: typeof posts }, post) => { + const year = post.data.published.getFullYear() + if (!grouped[year]) { + grouped[year] = [] + } + grouped[year].push(post) + return grouped + }, + {}, + ) - // convert the object to an array - const groupedPostsArray = Object.keys(groupedPosts).map(key => ({ - year: parseInt(key), - posts: groupedPosts[parseInt(key)] - })) + // convert the object to an array + const groupedPostsArray = Object.keys(groupedPosts).map(key => ({ + year: parseInt(key), + posts: groupedPosts[parseInt(key)], + })) - // sort years by latest first - groupedPostsArray.sort((a, b) => b.year - a.year) - return groupedPostsArray; -}(); + // sort years by latest first + groupedPostsArray.sort((a, b) => b.year - a.year) + return groupedPostsArray +})() function formatDate(date: Date) { - const month = (date.getMonth() + 1).toString().padStart(2, '0'); - const day = date.getDate().toString().padStart(2, '0'); - return `${month}-${day}`; + const month = (date.getMonth() + 1).toString().padStart(2, '0') + const day = date.getDate().toString().padStart(2, '0') + return `${month}-${day}` } function formatTag(tag: string[]) { - return tag.map(t => `#${t}`).join(' '); + return tag.map(t => `#${t}`).join(' ') } - ---
diff --git a/src/components/ConfigCarrier.astro b/src/components/ConfigCarrier.astro index 445be0f38..3cecd5b0c 100644 --- a/src/components/ConfigCarrier.astro +++ b/src/components/ConfigCarrier.astro @@ -1,7 +1,6 @@ --- -import {siteConfig} from "../config"; - +import { siteConfig } from '../config' ---
diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 82814a9ff..14c535b20 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,8 +1,7 @@ --- -import {profileConfig} from "../config"; -import {url} from "../utils/url-utils"; - +import { profileConfig } from '../config' +import { url } from '../utils/url-utils' ---
diff --git a/src/components/LightDarkSwitch.svelte b/src/components/LightDarkSwitch.svelte index 9b443851c..6aacfff28 100644 --- a/src/components/LightDarkSwitch.svelte +++ b/src/components/LightDarkSwitch.svelte @@ -1,10 +1,6 @@ diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 2fb47ee78..fd563cce0 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -1,22 +1,23 @@ --- -import { Icon } from 'astro-icon/components'; -import DisplaySettings from "./widget/DisplaySettings.svelte"; -import {LinkPreset, type NavBarLink} from "../types/config"; -import {navBarConfig, siteConfig} from "../config"; -import NavMenuPanel from "./widget/NavMenuPanel.astro"; -import Search from "./Search.svelte"; -import {LinkPresets} from "../constants/link-presets"; -import LightDarkSwitch from "./LightDarkSwitch.svelte"; -import {url} from "../utils/url-utils"; -const className = Astro.props.class; +import { Icon } from 'astro-icon/components' +import DisplaySettings from './widget/DisplaySettings.svelte' +import { LinkPreset, type NavBarLink } from '../types/config' +import { navBarConfig, siteConfig } from '../config' +import NavMenuPanel from './widget/NavMenuPanel.astro' +import Search from './Search.svelte' +import { LinkPresets } from '../constants/link-presets' +import LightDarkSwitch from './LightDarkSwitch.svelte' +import { url } from '../utils/url-utils' +const className = Astro.props.class -let links: NavBarLink[] = navBarConfig.links.map((item: NavBarLink | LinkPreset): NavBarLink => { - if (typeof item === "number") { - return LinkPresets[item] +let links: NavBarLink[] = navBarConfig.links.map( + (item: NavBarLink | LinkPreset): NavBarLink => { + if (typeof item === 'number') { + return LinkPresets[item] } - return item; -}); - + return item + }, +) ---