Skip to content

Commit 4fc350d

Browse files
committed
feat: remove useless code
1 parent e332b67 commit 4fc350d

1 file changed

Lines changed: 32 additions & 24 deletions

File tree

src/components/Search.svelte

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
3-
import { url } from '@utils/url-utils.ts'
43
import Icon from '@iconify/svelte'
4+
55
let keywordDesktop = ''
66
let keywordMobile = ''
7-
let result = []
8-
const fakeResult = [
9-
{
10-
url: url('/'),
11-
meta: {
12-
title: 'This Is a Fake Search Result',
13-
},
14-
excerpt:
15-
'Because the search cannot work in the <mark>dev</mark> environment.',
16-
},
17-
{
18-
url: url('/'),
19-
meta: {
20-
title: 'If You Want to Test the Search',
21-
},
22-
excerpt: 'Try running <mark>npm build && npm preview</mark> instead.',
23-
},
24-
]
7+
8+
interface PagefindResult {
9+
url: string;
10+
meta: {
11+
title: string;
12+
};
13+
excerpt: string;
14+
}
15+
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+
// ]
2535
2636
let search = (keyword: string, isDesktop: boolean) => {}
2737
@@ -37,16 +47,14 @@ onMount(() => {
3747
return
3848
}
3949
40-
let arr = []
50+
// 如果是开发环境,暂停使用 pagefind 搜索
51+
const arr = []
52+
// 如果是生产环境,使用 pagefind 搜索
4153
if (import.meta.env.PROD) {
4254
const ret = await pagefind.search(keyword)
4355
for (const item of ret.results) {
4456
arr.push(await item.data())
4557
}
46-
} else {
47-
// Mock data for non-production environment
48-
// arr = JSON.parse('[{"url":"/","content":"Simple Guides for Fuwari. Cover image source: Source. This blog template is built with Astro. For the things that are not mentioned in this guide, you may find the answers in the Astro Docs. Front-matter of Posts. --- title: My First Blog Post published: 2023-09-09 description: This is the first post of my new Astro blog. image: ./cover.jpg tags: [Foo, Bar] category: Front-end draft: false ---AttributeDescription title. The title of the post. published. The date the post was published. description. A short description of the post. Displayed on index page. image. The cover image path of the post. 1. Start with http:// or https://: Use web image 2. Start with /: For image in public dir 3. With none of the prefixes: Relative to the markdown file. tags. The tags of the post. category. The category of the post. draft. If this post is still a draft, which won’t be displayed. Where to Place the Post Files. Your post files should be placed in src/content/posts/ directory. You can also create sub-directories to better organize your posts and assets. src/content/posts/ ├── post-1.md └── post-2/ ├── cover.png └── index.md.","word_count":187,"filters":{},"meta":{"title":"This Is a Fake Search Result"},"anchors":[{"element":"h2","id":"front-matter-of-posts","text":"Front-matter of Posts","location":34},{"element":"h2","id":"where-to-place-the-post-files","text":"Where to Place the Post Files","location":151}],"weighted_locations":[{"weight":10,"balanced_score":57600,"location":3}],"locations":[3],"raw_content":"Simple Guides for Fuwari. Cover image source: Source. This blog template is built with Astro. For the things that are not mentioned in this guide, you may find the answers in the Astro Docs. Front-matter of Posts. --- title: My First Blog Post published: 2023-09-09 description: This is the first post of my new Astro blog. image: ./cover.jpg tags: [Foo, Bar] category: Front-end draft: false ---AttributeDescription title. The title of the post. published. The date the post was published. description. A short description of the post. Displayed on index page. image. The cover image path of the post. 1. Start with http:// or https://: Use web image 2. Start with /: For image in public dir 3. With none of the prefixes: Relative to the markdown file. tags. The tags of the post. category. The category of the post. draft. If this post is still a draft, which won’t be displayed. Where to Place the Post Files. Your post files should be placed in src/content/posts/ directory. You can also create sub-directories to better organize your posts and assets. src/content/posts/ ├── post-1.md └── post-2/ ├── cover.png └── index.md.","raw_url":"/posts/guide/","excerpt":"Because the search cannot work in the <mark>dev</mark> environment.","sub_results":[{"title":"Simple Guides for Fuwari - Fuwari","url":"/posts/guide/","weighted_locations":[{"weight":10,"balanced_score":57600,"location":3}],"locations":[3],"excerpt":"Simple Guides for <mark>Fuwari.</mark> Cover image source: Source. This blog template is built with Astro. For the things that are not mentioned in this guide, you may find the answers"}]},{"url":"/","content":"About. This is the demo site for Fuwari. Sources of images used in this site. Unsplash. 星と少女 by Stella. Rabbit - v1.4 Showcase by Rabbit_YourMajesty.","word_count":25,"filters":{},"meta":{"title":"If You Want to Test the Search"},"anchors":[{"element":"h1","id":"about","text":"About","location":0},{"element":"h3","id":"sources-of-images-used-in-this-site","text":"Sources of images used in this site","location":8}],"weighted_locations":[{"weight":1,"balanced_score":576,"location":7}],"locations":[7],"raw_content":"About. This is the demo site for Fuwari. Sources of images used in this site. Unsplash. 星と少女 by Stella. Rabbit - v1.4 Showcase by Rabbit_YourMajesty.","raw_url":"/about/","excerpt":"Try running <mark>npm build && npm preview</mark> instead.","sub_results":[{"title":"About","url":"/about/#about","anchor":{"element":"h1","id":"about","text":"About","location":0},"weighted_locations":[{"weight":1,"balanced_score":576,"location":7}],"locations":[7],"excerpt":"About. This is the demo site for <mark>Fuwari.</mark>"}]}]')
49-
arr = fakeResult
5058
}
5159
5260
if (!arr.length && isDesktop) {

0 commit comments

Comments
 (0)