Skip to content

Commit 5e2788d

Browse files
committed
fix(theme): sidebar is taken from the filename when the first letter is capitalized.
1 parent 14f12c7 commit 5e2788d

File tree

23 files changed

+45
-189
lines changed

23 files changed

+45
-189
lines changed

__tests__/e2e/.vitepress/config.mts

-28
This file was deleted.

__tests__/e2e/.vitepress/config.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { ThemeConfig } from 'vitepress-theme-mild';
2+
import { defineConfigWithTheme } from 'vitepress';
3+
import baseConfig from 'vitepress-theme-mild/config';
4+
5+
export default defineConfigWithTheme<ThemeConfig>({
6+
title: 'My Awesome Project',
7+
description: 'A VitePress Site',
8+
extends: baseConfig,
9+
themeConfig: {
10+
nav: [
11+
{ text: 'Home', link: '/' },
12+
{ text: 'Examples', link: '/markdown-examples' }
13+
],
14+
sidebar: {
15+
'/posts/category/': 'auto'
16+
},
17+
socialLinks: [
18+
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
19+
]
20+
}
21+
});
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import MildTheme from 'vitepress-theme-mild';
2+
3+
export default MildTheme;

__tests__/e2e/api-examples.md

-55
This file was deleted.

__tests__/e2e/index.md

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
---
22
# https://vitepress.dev/reference/default-theme-home-page
3-
layout: home
3+
layout: blog
44

5-
hero:
6-
name: "My Awesome Project"
7-
text: "A VitePress Site"
8-
tagline: My great project tagline
9-
actions:
10-
- theme: brand
11-
text: Markdown Examples
12-
link: /markdown-examples
13-
- theme: alt
14-
text: API Examples
15-
link: /api-examples
16-
17-
features:
18-
- title: Feature A
19-
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
20-
- title: Feature B
21-
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
22-
- title: Feature C
23-
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
245
---

__tests__/e2e/markdown-examples.md

-85
This file was deleted.

__tests__/e2e/posts/category/bar/a.md

Whitespace-only changes.

__tests__/e2e/posts/category/bar/b.md

Whitespace-only changes.

__tests__/e2e/posts/category/bar/c.md

Whitespace-only changes.

__tests__/e2e/posts/category/bar/d.md

Whitespace-only changes.

__tests__/e2e/posts/category/framework/preact.md

Whitespace-only changes.

__tests__/e2e/posts/category/framework/react.md

Whitespace-only changes.

__tests__/e2e/posts/category/framework/vue.md

Whitespace-only changes.

__tests__/e2e/posts/category/front-end/css.md

Whitespace-only changes.

__tests__/e2e/posts/category/front-end/html.md

Whitespace-only changes.

__tests__/e2e/posts/category/front-end/js.md

Whitespace-only changes.

__tests__/e2e/posts/fruit/1.md

Whitespace-only changes.

__tests__/e2e/posts/fruit/2.md

Whitespace-only changes.

__tests__/e2e/posts/fruit/3.md

Whitespace-only changes.

__tests__/e2e/posts/fruit/4.md

Whitespace-only changes.

package.json

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
"vitepress",
1717
"vitepress-theme"
1818
],
19+
"exports": {
20+
".": {
21+
"types": "./types/index.d.ts",
22+
"import": "./index.js"
23+
},
24+
"./config": {
25+
"types": "./config/index.d.ts",
26+
"import": "./config/index.js"
27+
}
28+
},
29+
"main": "./index.js",
1930
"module": "./index.js",
2031
"types": "./types/index.d.ts",
2132
"files": [

src/client/utils/loader/auto.sidebar.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import { isObject } from '@vueuse/core';
44
import directoryTree from 'directory-tree';
55
import matter from 'gray-matter';
6+
import { capitalizeFirstFormat } from '../../../shared/utils';
67
import { ensureIndexMd, normalizePath } from '../node/path';
78

89
// sidebar排序, 越小越靠前
@@ -94,7 +95,8 @@ export function formatSidebarItems(item: any, PATH: string, config: SiteConfig,
9495
normalizePath(path.relative(config.srcDir, PATH))
9596
.replace(/(^|\/)index\.md$/, '$1')
9697
.replace(/\.md$/, config.cleanUrls ? '' : '.html')}`;
97-
const filename = link.split('/')[link.split('/').length - 1].split('.')[0];
98+
const originFilename = link.split('/')[link.split('/').length - 1].split('.')[0];
99+
const filename = capitalizeFirstFormat(originFilename);
98100
const article = data.get(ensureIndexMd(PATH));
99101
const content = matter(article?.src || '').content;
100102
const match = content.match(/^(#+)\s+(.+)/m);

src/shared/utils/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ export function isString(value?: any): value is string {
66
return false;
77
}
88
}
9+
10+
export function capitalizeFirstFormat(str: string | undefined) {
11+
if (typeof str !== 'string' || !str.length)
12+
return str;
13+
return str[0].toUpperCase() + str.slice(1).toLowerCase();
14+
}

0 commit comments

Comments
 (0)