Skip to content

Commit 436909a

Browse files
committed
feat(Navigator): 优化面包屑导航逻辑并支持GitHub Pages部署
- 移除resolve函数依赖,直接使用githubUrl变量处理路径 - 重构pathName_items计算逻辑,正确处理GitHub Pages基础路径 - 添加对githubUrl的特殊处理,确保首页链接正确指向 - 在svelte.config.js中动态设置base路径,开发环境为空字符串
1 parent 49aed1b commit 436909a

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/lib/components/my/Navigator.svelte

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<script>
22
import { page } from '$app/state';
33
import * as Breadcrumb from '$lib/components/ui/breadcrumb/index.js';
4-
import { resolve } from '$app/paths';
5-
6-
let base = resolve('').replaceAll('/', '');
7-
if (base === '') base = '/';
4+
const githubUrl = 'vhtmui.github.io';
85
96
let pathName_items = $derived.by(() => {
10-
let pn_array = ['/'].concat(page.url.pathname.split('/').filter(Boolean));
7+
let pn_array = page.url.pathname.split('/').filter(Boolean);
118
12-
if (base in pn_array) {
13-
pn_array = [base].concat(pn_array.splice(0, pn_array.indexOf(base) + 1));
9+
let hasGithubUrl = false;
10+
if (pn_array.includes(githubUrl)) {
11+
pn_array = pn_array.splice(pn_array.indexOf(githubUrl));
12+
hasGithubUrl = true;
1413
}
1514
16-
return pn_array.map((pathname, index) => {
17-
let name = pathname === '/' ? 'Home' : pathname;
18-
let href = pn_array
19-
.map((v) => (v === '/' ? '' : v))
20-
.slice(0, index + 1)
21-
.join('/');
22-
if (href === '') href = '/';
23-
// 该href无需格式化或拼接
15+
const pn = pn_array.map((pathname, index) => {
16+
let name = pathname;
17+
let href = '/' + pn_array.slice(0, index + 1).join('/');
2418
return { name, href };
2519
});
20+
21+
if (hasGithubUrl) {
22+
pn[0] = { name: 'Home', href: '/' + githubUrl };
23+
} else {
24+
pn.unshift({ name: 'Home', href: '/' });
25+
}
26+
27+
return pn;
2628
});
2729
</script>
2830

svelte.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import adapter from '@sveltejs/adapter-static';
22

3-
// const base = process.argv.includes('dev') ? '' : '/vhtmui.github.io';
4-
export const base = '/vhtmui.github.io';
3+
const base = process.argv.includes('dev') ? '' : '/vhtmui.github.io';
54

65
/** @type {import('@sveltejs/kit').Config} */
76
const config = {

0 commit comments

Comments
 (0)