Skip to content

Commit daae7bf

Browse files
committed
feat(工具页): 添加工具搜索功能并定义CSS自定义属性
- 在工具页面添加搜索框和对应的JavaScript逻辑,实现按标题和描述过滤工具卡片 - 定义全局CSS自定义属性(包括深色模式变量)以统一样式管理 - 为搜索组件添加样式,包括输入框、图标和分隔线
1 parent d389316 commit daae7bf

4 files changed

Lines changed: 100 additions & 1 deletion

File tree

assets/js/tools/search.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
document.addEventListener('DOMContentLoaded', function () {
2+
const searchInput = document.getElementById('tool-search');
3+
if (!searchInput) return;
4+
5+
const toolCards = document.querySelectorAll('.tools-grid .tool-card');
6+
7+
searchInput.addEventListener('input', function (e) {
8+
const searchTerm = e.target.value.toLowerCase();
9+
10+
toolCards.forEach(function (card) {
11+
const title = card.querySelector('.tool-title').textContent.toLowerCase();
12+
const desc = card.querySelector('.tool-desc').textContent.toLowerCase();
13+
const isVisible = title.includes(searchTerm) || desc.includes(searchTerm);
14+
card.style.display = isVisible ? '' : 'none';
15+
});
16+
});
17+
});

assets/scss/custom.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/**
2+
* Custom variables
3+
*/
4+
:root {
5+
--primary-color: #007bff;
6+
--primary-color-rgb: 0, 123, 255;
7+
8+
--content-bg: #ffffff;
9+
--content-color: #212529;
10+
--content-h-color: #343a40;
11+
--content-border-color: #dee2e6;
12+
13+
--border-radius: 0.75rem;
14+
}
15+
16+
[data-scheme="dark"] {
17+
--primary-color: #0088ff;
18+
--primary-color-rgb: 0, 136, 255;
19+
20+
--content-bg: #1a1a1a;
21+
--content-color: #d8d8d8;
22+
--content-h-color: #c2c2c2;
23+
--content-border-color: #3a3a3a;
24+
}
25+
126
/*
227
You can add your own custom styles here.
328
*/

assets/scss/tools.scss

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,52 @@
1+
.search-wrapper {
2+
position: relative;
3+
4+
#tool-search {
5+
width: 100%;
6+
padding: 0.75rem 1rem 0.75rem 5rem;
7+
border-radius: var(--border-radius);
8+
border: 1px solid var(--content-border-color);
9+
background-color: var(--content-bg);
10+
color: var(--content-color);
11+
font-size: 2rem;
12+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
13+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
14+
15+
&::placeholder {
16+
color: var(--content-h-color);
17+
opacity: 0.5;
18+
}
19+
20+
&:focus {
21+
outline: none;
22+
transform: translateY(-1px);
23+
}
24+
}
25+
26+
.icon-tabler-search {
27+
position: absolute;
28+
left: 1.2rem;
29+
top: 50%;
30+
transform: translateY(-50%);
31+
color: var(--content-h-color);
32+
width: 20px;
33+
height: 20px;
34+
pointer-events: none;
35+
transition: color 0.3s;
36+
}
37+
38+
}
39+
40+
.search-divider {
41+
border: none;
42+
border-top: 1.5px solid var(--content-border-color);
43+
margin: 1px 0;
44+
}
45+
146
.tools-grid {
247
display: grid;
348
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
449
gap: 2rem;
5-
padding: 2rem 0;
650

751
.tool-card {
852
background: var(--card-background);

layouts/tools.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ <h1 class="title">{{ .Title }}</h1>
88
</div>
99
</header>
1010

11+
<div class="search-wrapper">
12+
<input type="search" id="tool-search" placeholder="搜索工具...">
13+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-search">
14+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15+
<circle cx="10" cy="10" r="7"></circle>
16+
<line x1="21" y1="21" x2="15" y2="15"></line>
17+
</svg>
18+
</div>
19+
20+
<hr class="search-divider">
21+
1122
<div class="tools-grid">
1223
{{ range .Pages }}
1324
<a href="{{ .RelPermalink }}" class="tool-card">
@@ -35,4 +46,6 @@ <h3 class="tool-title">{{ .Title }}</h3>
3546
<div class="article-content">
3647
{{ .Content }}
3748
</div>
49+
{{ $searchJS := resources.Get "js/tools/search.js" | resources.Minify }}
50+
<script src="{{ $searchJS.RelPermalink }}" defer></script>
3851
{{ end }}

0 commit comments

Comments
 (0)