Skip to content

Commit 2e56580

Browse files
committed
perf: 优化
1 parent ddf76a3 commit 2e56580

5 files changed

Lines changed: 37 additions & 40 deletions

File tree

astro.config.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,25 @@ export default defineConfig({
4646
}),
4747
icon({
4848
include: {
49-
"preprocess: vitePreprocess(),": ["*"],
50-
"fa6-brands": ["*"],
51-
"fa6-regular": ["*"],
52-
"fa6-solid": ["*"],
49+
"material-symbols": [
50+
"calendar-today-outline-rounded",
51+
"edit-calendar-outline-rounded",
52+
"book-2-outline-rounded",
53+
"tag-rounded",
54+
"notes-rounded",
55+
"schedule-outline-rounded",
56+
"chevron-left-rounded",
57+
"chevron-right-rounded",
58+
"keyboard-arrow-up-rounded",
59+
"more-horiz",
60+
"home-outline-rounded",
61+
"palette-outline",
62+
"menu-rounded",
63+
"copyright-outline-rounded",
64+
],
65+
"fa6-brands": ["creative-commons", "github"],
66+
"fa6-regular": ["address-card"],
67+
"fa6-solid": ["arrow-up-right-from-square"],
5368
},
5469
}),
5570
svelte(),

src/components/Search.svelte

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { onMount } from 'svelte'
33
import Icon from '@iconify/svelte'
44
5-
let keywordDesktop = ''
6-
let keywordMobile = ''
5+
let keywordDesktop = $state('')
6+
let keywordMobile = $state('')
77
88
interface PagefindResult {
99
url: string
@@ -13,25 +13,7 @@ interface PagefindResult {
1313
excerpt: string
1414
}
1515
16-
let result: PagefindResult[] = []
17-
18-
// const fakeResult: PagefindResult[] = [
19-
// {
20-
// url: url('/'),
21-
// meta: {
22-
// title: 'This Is a Fake Search Result',
23-
// },
24-
// excerpt:
25-
// 'Because the search cannot work in the <mark>dev</mark> environment.',
26-
// },
27-
// {
28-
// url: url('/'),
29-
// meta: {
30-
// title: 'If You Want to Test the Search',
31-
// },
32-
// excerpt: 'Try running <mark>npm build && npm preview</mark> instead.',
33-
// },
34-
// ]
16+
let result: PagefindResult[] = $state([])
3517
3618
let search = (keyword: string, isDesktop: boolean) => {}
3719
@@ -74,8 +56,8 @@ const togglePanel = () => {
7456
panel?.classList.toggle('float-panel-closed')
7557
}
7658
77-
$: search(keywordDesktop, true)
78-
$: search(keywordMobile, false)
59+
$effect(() => { search(keywordDesktop, true) })
60+
$effect(() => { search(keywordMobile, false) })
7961
</script>
8062

8163
<!-- search bar for desktop view -->
@@ -84,14 +66,14 @@ $: search(keywordMobile, false)
8466
dark:bg-white/5 dark:hover:bg-white/10 dark:focus-within:bg-white/10
8567
">
8668
<Icon icon="material-symbols:search" class="absolute text-[1.25rem] pointer-events-none ml-3 transition my-auto text-black/30 dark:text-white/30"></Icon>
87-
<input placeholder="搜索" bind:value={keywordDesktop} on:focus={() => search(keywordDesktop, true)}
69+
<input placeholder="搜索" bind:value={keywordDesktop} onfocus={() => search(keywordDesktop, true)}
8870
class="transition-all pl-10 text-sm bg-transparent outline-0
8971
h-full w-40 active:w-60 focus:w-60 text-black/50 dark:text-white/50"
9072
>
9173
</div>
9274

9375
<!-- toggle btn for phone/tablet view -->
94-
<button on:click={togglePanel} aria-label="Search Panel" id="search-switch"
76+
<button onclick={togglePanel} aria-label="Search Panel" id="search-switch"
9577
class="btn-plain scale-animation lg:!hidden rounded-lg w-11 h-11 active:scale-90">
9678
<Icon icon="material-symbols:search" class="text-[1.25rem]"></Icon>
9779
</button>

src/components/widget/DisplaySettings.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
import { getDefaultHue, getHue, setHue } from '@utils/setting-utils'
33
import Icon from '@iconify/svelte'
44
5-
let hue = getHue()
5+
let hue = $state(getHue())
66
const defaultHue = getDefaultHue()
77
88
function resetHue() {
99
hue = getDefaultHue()
1010
}
1111
12-
$: if (hue || hue === 0) {
13-
setHue(hue)
14-
}
12+
$effect(() => {
13+
if (hue || hue === 0) {
14+
setHue(hue)
15+
}
16+
})
1517
</script>
1618

1719
<div id="display-setting" class="float-panel float-panel-closed absolute transition-all w-80 right-4 px-4 py-4">
@@ -22,7 +24,7 @@ $: if (hue || hue === 0) {
2224
>
2325
主题色
2426
<button aria-label="Reset to Default" class="btn-regular w-7 h-7 rounded-md active:scale-90"
25-
class:opacity-0={hue === defaultHue} class:pointer-events-none={hue === defaultHue} on:click={resetHue}>
27+
class:opacity-0={hue === defaultHue} class:pointer-events-none={hue === defaultHue} onclick={resetHue}>
2628
<div class="text-[var(--btn-content)]">
2729
<Icon icon="fa6-solid:arrow-rotate-left" class="text-[0.875rem]"></Icon>
2830
</div>

src/pages/posts/[...slug].astro

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ export async function getStaticPaths() {
2424
}
2525
2626
const { entry } = Astro.props
27-
const { Content, headings } = await entry.render()
28-
29-
const { remarkPluginFrontmatter } = await entry.render()
27+
const { Content, headings, remarkPluginFrontmatter } = await entry.render()
3028
3129
const jsonLd = {
3230
'@context': 'https://schema.org',

src/utils/content-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export type Tag = {
4444
export async function getTagList(): Promise<Tag[]> {
4545
const allBlogPosts = await getAllBlogPosts()
4646
const countMap: { [key: string]: number } = {}
47-
allBlogPosts.map((post: { data: { tags: string[] } }) => {
48-
post.data.tags.map((tag: string) => {
47+
allBlogPosts.forEach((post: { data: { tags: string[] } }) => {
48+
post.data.tags.forEach((tag: string) => {
4949
if (!countMap[tag]) countMap[tag] = 0
5050
countMap[tag]++
5151
})
@@ -67,7 +67,7 @@ export type Category = {
6767
export async function getCategoryList(): Promise<Category[]> {
6868
const allBlogPosts = await getAllBlogPosts()
6969
const count: { [key: string]: number } = {}
70-
allBlogPosts.map((post: { data: { category: string | number } }) => {
70+
allBlogPosts.forEach((post: { data: { category: string | number } }) => {
7171
if (!post.data.category) {
7272
const ucKey = '未分类'
7373
count[ucKey] = count[ucKey] ? count[ucKey] + 1 : 1

0 commit comments

Comments
 (0)