Skip to content

Commit 73caa13

Browse files
author
CMSZ
committed
style: 清理代码格式并移除未使用的分类字段
- 修复多个文件末尾缺少换行符的问题 - 移除文章中的分类字段,统一使用标签系统 - 简化代码中的多行字符串和条件判断 - 重新组织导入语句的顺序 - 改进导航菜单面板的响应式设计和交互逻辑
1 parent d99865c commit 73caa13

File tree

13 files changed

+155
-63
lines changed

13 files changed

+155
-63
lines changed

src/components/Search.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import fa6Icons from "@iconify-json/fa6-solid/icons.json";
66
import materialIcons from "@iconify-json/material-symbols/icons.json";
77
88
// Preload icons to avoid CDN requests
9-
if (materialIcons.icons["search"]) {
9+
if (materialIcons.icons.search) {
1010
addIcon("material-symbols:search", {
11-
body: materialIcons.icons["search"].body,
11+
body: materialIcons.icons.search.body,
1212
width: materialIcons.width,
1313
height: materialIcons.height,
1414
});
Lines changed: 138 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import { Icon } from "astro-icon/components";
3+
import { LinkPresets } from "../../constants/link-presets";
34
import { type NavBarLink } from "../../types/config";
45
import { url } from "../../utils/url-utils";
56
@@ -8,25 +9,143 @@ interface Props {
89
}
910
1011
const links = Astro.props.links;
12+
13+
function resolveChildren(link: NavBarLink): NavBarLink[] {
14+
return (
15+
link.children?.map((child) =>
16+
typeof child === "number" ? LinkPresets[child] : child,
17+
) ?? []
18+
);
19+
}
20+
21+
const maxLabelLength = Math.max(
22+
...links.flatMap((link) => [
23+
link.name.length,
24+
...resolveChildren(link).map((child) => child.name.length),
25+
]),
26+
);
1127
---
12-
<div id="nav-menu-panel" class:list={["float-panel float-panel-closed absolute transition-all fixed right-4 px-2 py-2"]}>
13-
{links.map((link) => (
14-
<a href={link.external ? link.url : url(link.url)} class="group flex justify-between items-center py-2 pl-3 pr-1 rounded-lg gap-8
15-
hover:bg-[var(--btn-plain-bg-hover)] active:bg-[var(--btn-plain-bg-active)] transition
16-
"
17-
target={link.external ? "_blank" : null}
18-
>
19-
<div class="transition text-black/75 dark:text-white/75 font-bold group-hover:text-[var(--primary)] group-active:text-[var(--primary)]">
20-
{link.name}
28+
<div
29+
id="nav-menu-panel"
30+
style={`--nav-menu-max-label-length: ${Math.max(6, maxLabelLength)}`}
31+
class:list={["float-panel float-panel-closed absolute transition-all fixed right-4 px-2 py-2 overflow-hidden"]}
32+
>
33+
{links.map((link) => {
34+
const children = resolveChildren(link);
35+
const hasChildren = children.length > 0;
36+
37+
if (!hasChildren) {
38+
return (
39+
<a href={link.external ? link.url : url(link.url)} class="group flex justify-between items-center py-2 pl-3 pr-1 rounded-lg gap-3 min-w-0
40+
hover:bg-[var(--btn-plain-bg-hover)] active:bg-[var(--btn-plain-bg-active)] transition
41+
"
42+
target={link.external ? "_blank" : null}
43+
>
44+
<div class="transition text-black/75 dark:text-white/75 font-bold group-hover:text-[var(--primary)] group-active:text-[var(--primary)] truncate">
45+
{link.name}
46+
</div>
47+
{!link.external && <Icon name="material-symbols:chevron-right-rounded"
48+
class="transition text-[1.25rem] text-[var(--primary)]"
49+
>
50+
</Icon>}
51+
{link.external && <Icon name="fa6-solid:arrow-up-right-from-square"
52+
class="transition text-[0.75rem] text-black/25 dark:text-white/25 -translate-x-1"
53+
>
54+
</Icon>}
55+
</a>
56+
);
57+
}
58+
59+
return (
60+
<div class="flex flex-col">
61+
<button
62+
type="button"
63+
class="group flex w-full justify-between items-center py-2 pl-3 pr-1 rounded-lg gap-3 min-w-0
64+
hover:bg-[var(--btn-plain-bg-hover)] active:bg-[var(--btn-plain-bg-active)] transition"
65+
data-nav-parent
66+
aria-expanded="false"
67+
>
68+
<div class="transition text-black/75 dark:text-white/75 font-bold group-hover:text-[var(--primary)] group-active:text-[var(--primary)] truncate">
69+
{link.name}
70+
</div>
71+
<Icon
72+
name="material-symbols:keyboard-arrow-down-rounded"
73+
class="transition text-[1.25rem] text-[var(--primary)] -translate-x-0.5"
74+
data-nav-arrow
75+
/>
76+
</button>
77+
<div class="hidden pl-3" data-nav-submenu>
78+
{children.map((child) => (
79+
<a
80+
href={child.external ? child.url : url(child.url)}
81+
target={child.external ? "_blank" : null}
82+
rel={child.external ? "noopener noreferrer" : null}
83+
class="group flex justify-between items-center py-2 pl-3 pr-1 rounded-lg gap-3 min-w-0
84+
hover:bg-[var(--btn-plain-bg-hover)] active:bg-[var(--btn-plain-bg-active)] transition"
85+
>
86+
<div class="transition text-black/75 dark:text-white/75 font-medium group-hover:text-[var(--primary)] group-active:text-[var(--primary)] truncate">
87+
{child.name}
88+
</div>
89+
{!child.external && (
90+
<Icon
91+
name="material-symbols:chevron-right-rounded"
92+
class="transition text-[1.25rem] text-[var(--primary)]"
93+
/>
94+
)}
95+
{child.external && (
96+
<Icon
97+
name="fa6-solid:arrow-up-right-from-square"
98+
class="transition text-[0.75rem] text-black/25 dark:text-white/25 -translate-x-1"
99+
/>
100+
)}
101+
</a>
102+
))}
103+
</div>
21104
</div>
22-
{!link.external && <Icon name="material-symbols:chevron-right-rounded"
23-
class="transition text-[1.25rem] text-[var(--primary)]"
24-
>
25-
</Icon>}
26-
{link.external && <Icon name="fa6-solid:arrow-up-right-from-square"
27-
class="transition text-[0.75rem] text-black/25 dark:text-white/25 -translate-x-1"
28-
>
29-
</Icon>}
30-
</a>
31-
))}
105+
);
106+
})}
32107
</div>
108+
109+
<script>
110+
function initNavMenuPanel() {
111+
const panel = document.getElementById("nav-menu-panel");
112+
if (!panel) return;
113+
114+
const parents = panel.querySelectorAll("[data-nav-parent]");
115+
parents.forEach((btn) => {
116+
if (!(btn instanceof HTMLButtonElement)) return;
117+
if (btn.dataset.bound === "1") return;
118+
btn.dataset.bound = "1";
119+
120+
btn.addEventListener("click", (e) => {
121+
e.preventDefault();
122+
const container = btn.parentElement;
123+
const submenu = container?.querySelector("[data-nav-submenu]");
124+
if (!(submenu instanceof HTMLElement)) return;
125+
126+
const expanded = btn.getAttribute("aria-expanded") === "true";
127+
btn.setAttribute("aria-expanded", String(!expanded));
128+
submenu.classList.toggle("hidden", expanded);
129+
130+
const arrow = btn.querySelector("[data-nav-arrow]");
131+
if (arrow instanceof HTMLElement) {
132+
arrow.classList.toggle("rotate-180", !expanded);
133+
}
134+
});
135+
});
136+
}
137+
138+
initNavMenuPanel();
139+
document.addEventListener("content:replace", initNavMenuPanel);
140+
document.addEventListener("astro:after-swap", initNavMenuPanel);
141+
</script>
142+
143+
<style>
144+
#nav-menu-panel {
145+
width: clamp(
146+
10rem,
147+
calc(var(--nav-menu-max-label-length) * 1.1ch + 4.75rem),
148+
calc(100vw - 2rem)
149+
);
150+
}
151+
</style>

src/config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type {
2+
CommentConfig,
23
ExpressiveCodeConfig,
34
LicenseConfig,
45
NavBarConfig,
56
ProfileConfig,
67
SiteConfig,
78
UmamiConfig,
8-
CommentConfig,
99
} from "./types/config";
1010
import { LinkPreset } from "./types/config";
1111

@@ -47,7 +47,7 @@ export const navBarConfig: NavBarConfig = {
4747
LinkPreset.Archive,
4848
{
4949
name: "我的",
50-
url: "#",
50+
url: "",
5151
children: [
5252
LinkPreset.About,
5353
{
@@ -113,7 +113,6 @@ export const umamiConfig: UmamiConfig = {
113113
timezone: "Asia/Shanghai",
114114
};
115115

116-
117116
export const commentConfig: CommentConfig = {
118117
enable: true,
119118
type: "waline",
@@ -128,4 +127,4 @@ export const commentConfig: CommentConfig = {
128127
requiredMeta: ["nick", "mail"],
129128
whiteList: [],
130129
},
131-
};
130+
};

src/content/posts/guide/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ published: 2025-08-05
44
description: ''
55
image: ''
66
tags: ["Fuwari","Astro"]
7-
category: '记录'
87
draft: false
98
lang: ''
109

src/content/posts/record/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ published: 1999-01-01
44
description: ''
55
image: ''
66
tags: [记录]
7-
category: '记录'
87
draft: false
98
lang: ''
109
---

src/content/posts/umami-serverless/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ image: ""
66
tags:
77
- Serverless
88
- Umami
9-
category: 教程
109
draft: true
1110
lang: ''
1211

src/data/diary.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ export interface DiaryItem {
1111
tags?: string[];
1212
}
1313

14-
// 示例日记数据
1514
const diaryData: DiaryItem[] = [
1615
{
1716
id: 1,
18-
content:
19-
"删库跑路!",
17+
content: "删库跑路!",
2018
date: "2026-02-09T08:40:00Z",
2119
},
2220
];

src/pages/[...page].astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { PAGE_SIZE } from "../constants/constants";
66
import MainGridLayout from "../layouts/MainGridLayout.astro";
77
import { getSortedPosts } from "../utils/content-utils";
88
9-
109
export const getStaticPaths = (async ({ paginate }) => {
1110
const allBlogPosts = await getSortedPosts();
1211
return paginate(allBlogPosts, { pageSize: PAGE_SIZE });

src/pages/atom.xml.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ export async function GET(context: APIContext) {
6262
const prefixRemoved = src.slice(2);
6363
// Check if this post is in a subdirectory (like bestimageapi/index.md)
6464
const postPath = post.id; // This gives us the full path like "bestimageapi/index.md"
65-
const postDir = postPath.includes("/")
66-
? postPath.split("/")[0]
67-
: "";
65+
const postDir = postPath.includes("/") ? postPath.split("/")[0] : "";
6866

6967
if (postDir) {
7068
// For posts in subdirectories
@@ -80,9 +78,7 @@ export async function GET(context: APIContext) {
8078
} else {
8179
// Handle direct filename (no ./ prefix) - assume it's in the same directory as the post
8280
const postPath = post.id; // This gives us the full path like "bestimageapi/index.md"
83-
const postDir = postPath.includes("/")
84-
? postPath.split("/")[0]
85-
: "";
81+
const postDir = postPath.includes("/") ? postPath.split("/")[0] : "";
8682

8783
if (postDir) {
8884
// For posts in subdirectories
@@ -98,10 +94,7 @@ export async function GET(context: APIContext) {
9894
);
9995
if (imageMod) {
10096
const optimizedImg = await getImage({ src: imageMod });
101-
img.setAttribute(
102-
"src",
103-
new URL(optimizedImg.src, context.site).href,
104-
);
97+
img.setAttribute("src", new URL(optimizedImg.src, context.site).href);
10598
} else {
10699
// Debug: log the failed import path
107100
console.log(
@@ -132,13 +125,6 @@ export async function GET(context: APIContext) {
132125
<author>
133126
<name>${profileConfig.name}</name>
134127
</author>`;
135-
136-
// 添加分类标签
137-
if (post.data.category) {
138-
atomFeed += `
139-
<category term="${post.data.category}"></category>`;
140-
}
141-
142128
atomFeed += `
143129
</entry>`;
144130
}

src/pages/diary.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import I18nKey from "../i18n/i18nKey";
55
import { i18n } from "../i18n/translation";
66
import MainGridLayout from "../layouts/MainGridLayout.astro";
77
8-
98
// 获取日记数据
109
const moments = getDiaryList();
1110
const diaryStats = getDiaryStats();

0 commit comments

Comments
 (0)