@astrojs/starlight 0.41.9 → 0.41.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/components-internals/Icons.ts +3 -0
- package/package.json +4 -1
- package/style/anchor-links.css +13 -1
- package/translations/ar.json +3 -0
- package/translations/hi.json +3 -0
- package/translations/it.json +3 -0
- package/translations/ja.json +3 -0
- package/translations/ko.json +3 -0
- package/translations/pt.json +3 -0
- package/translations/zh-CN.json +3 -0
- package/translations/zh-TW.json +3 -0
- package/utils/navigation.ts +28 -20
- package/utils/routing/index.ts +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.41.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4167](https://github.com/withastro/starlight/pull/4167) [`32a5e29`](https://github.com/withastro/starlight/commit/32a5e29127c13946ce746c36d7cb194f35d11952) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a layout issue and anchor links appearing for hidden headings, e.g. footnote headings, when `markdown.headingLinks` is enabled or the `<AnchorHeading>` component is used.
|
|
8
|
+
|
|
9
|
+
- [#4148](https://github.com/withastro/starlight/pull/4148) [`cdfafd8`](https://github.com/withastro/starlight/commit/cdfafd8eedbbd6653cd6a1d3b1542b44ed1ba19e) Thanks [@ematipico](https://github.com/ematipico)! - Optimizes sidebar data generation logic to speed up sites with large sidebars
|
|
10
|
+
|
|
11
|
+
## 0.41.10
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#4160](https://github.com/withastro/starlight/pull/4160) [`88442c3`](https://github.com/withastro/starlight/commit/88442c333612058cb1b2c56ef689053a5994e31e) Thanks [@ArmandPhilippot](https://github.com/ArmandPhilippot)! - Adds the missing translations for Expressive Code in the following locales: `ar`, `hi`, `it`, `ja`, `ko`, `pt`, `zh-CN`, and `zh-TW`.
|
|
16
|
+
|
|
17
|
+
- [#4156](https://github.com/withastro/starlight/pull/4156) [`57af92d`](https://github.com/withastro/starlight/commit/57af92d91f9a9d0936a06efb4387898aded62aa9) Thanks [@pyxelr](https://github.com/pyxelr)! - Adds 1 new icon: `hypothesis`
|
|
18
|
+
|
|
19
|
+
- [#4159](https://github.com/withastro/starlight/pull/4159) [`a0e0ba2`](https://github.com/withastro/starlight/commit/a0e0ba263c93bab214222b798b52a759fb799ba7) Thanks [@trueberryless](https://github.com/trueberryless)! - Adds 1 new icon: `npmx`
|
|
20
|
+
|
|
3
21
|
## 0.41.9
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -176,6 +176,8 @@ export const BuiltInIcons = {
|
|
|
176
176
|
'<path d="M12.525.02c1.31-.02 2.61-.01 3.91-.02.08 1.53.63 3.09 1.75 4.17 1.12 1.11 2.7 1.62 4.24 1.79v4.03c-1.44-.05-2.89-.35-4.2-.97-.57-.26-1.1-.59-1.62-.93-.01 2.92.01 5.84-.02 8.75-.08 1.4-.54 2.79-1.35 3.94-1.31 1.92-3.58 3.17-5.91 3.21-1.43.08-2.86-.31-4.08-1.03-2.02-1.19-3.44-3.37-3.65-5.71-.02-.5-.03-1-.01-1.49.18-1.9 1.12-3.72 2.58-4.96 1.66-1.44 3.98-2.13 6.15-1.72.02 1.48-.04 2.96-.04 4.44-.99-.32-2.15-.23-3.02.37-.63.41-1.11 1.04-1.36 1.75-.21.51-.15 1.07-.14 1.61.24 1.64 1.82 3.02 3.5 2.87 1.12-.01 2.19-.66 2.77-1.61.19-.33.4-.67.41-1.06.1-1.79.06-3.57.07-5.36.01-4.03-.01-8.05.02-12.07z"/>',
|
|
177
177
|
goodreads:
|
|
178
178
|
'<path d="M17.35.03c.42-.09.85.03 1.17.32q.54.45.56 1.15c-.02.46-.25.88-.61 1.16l-2.18 1.75a.6.6 0 0 0-.26.43.5.5 0 0 0 .11.42 5.9 5.9 0 0 1 .84 6.58 5.96 5.96 0 0 1-7.5 2.93 1 1 0 0 0-.5-.01c-.23.07-.3.18-.46.38l-.01.02-.94 1.26s-.8.98.45.93a40 40 0 0 1 5.44 0c2.64.17 3.8 1.9 3.8 3.27 0 1.62-1.03 3.38-3.8 3.38a118 118 0 0 0-5.52-.03l-.83.02-.52.01c-.71 0-1.65-.19-1.66-1.07-.01-.73.62-1.12 1.1-1.17.44-.05.82 0 1.25.06l.81.1q.28 0 .56.03c.53.04 1.1.08 1.92.09l1.03.01c.7.01.94.02 1.28-.01 1.24-.12 1.83-.61 1.83-1.38q-.02-1.2-1.7-1.41c-1.56-.22-2.33-.17-3.72-.08l-1.67.1c-.6.03-2.45.02-2.68-1.5-.05-.41-.07-1.11.8-2.32l.76-1c.36-.5.58-.9.05-1.56 0 0-.4-.47-.52-.64a5.9 5.9 0 0 1-.45-6.11 6.14 6.14 0 0 1 8.37-2.58c.25.14.44.2.66.16.2-.03.27-.17.36-.35l.07-.12.53-1.03.73-1.4a1.5 1.5 0 0 1 1.05-.8M9.19 13.25c1.86.9 3.92.21 5.26-2.47 1.35-2.7.82-5.1-1.04-6.02C10.9 3.54 8.8 5.83 8 7.41c-1.35 2.7-.71 4.89 1.15 5.82Z"/>',
|
|
179
|
+
hypothesis:
|
|
180
|
+
'<path d="M3.43 0C2.49 0 1.7.77 1.7 1.72v17.14c0 .94.78 1.71 1.72 1.71h5.95L11.99 24l2.63-3.43h5.95c.93 0 1.72-.77 1.72-1.71V1.72c0-.95-.8-1.72-1.72-1.72zm1.7 3.43h2.59v6s.86-1.71 2.56-1.71c1.72 0 3.46.85 3.46 3.52v5.9h-2.59V12c0-1.39-.88-1.93-1.73-1.71-.86.21-1.7 1.12-1.7 3v3.85h-2.6zM18 13.72c.95 0 1.72.78 1.72 1.7A1.7 1.7 0 0 1 18 17.13a1.7 1.7 0 0 1-1.7-1.71c0-.92.75-1.71 1.7-1.71z"/>',
|
|
179
181
|
astro:
|
|
180
182
|
'<path d="M7.233 15.856c-.456 1.5-.132 3.586.948 4.57v-.036l.036-.096c.132-.636.648-1.032 1.309-1.008.612.012.96.336 1.044 1.044.036.264.036.528.048.803v.084c0 .6.168 1.176.504 1.68.3.48.72.851 1.284 1.103l-.024-.048-.024-.096c-.42-1.26-.12-2.135.984-2.879l.336-.227.745-.492a3.647 3.647 0 0 0 1.536-2.603c.06-.456 0-.9-.132-1.331l-.18.12c-1.668.887-3.577 1.2-5.425.84-1.117-.169-2.197-.48-3-1.416l.011-.012ZM2 15.592s3.205-1.559 6.421-1.559l2.437-7.508c.084-.36.348-.6.648-.6.3 0 .552.24.648.612l2.425 7.496c3.816 0 6.421 1.56 6.421 1.56L15.539.72c-.144-.444-.42-.72-.768-.72H8.24c-.348 0-.6.276-.768.72L2 15.592Z"/>',
|
|
181
183
|
solidjs:
|
|
@@ -224,6 +226,7 @@ export const BuiltInIcons = {
|
|
|
224
226
|
sketch:
|
|
225
227
|
'<path d="m.29 8.99 4.8-6.53a.6.6 0 0 1 .42-.24l6.42-.71a.6.6 0 0 1 .14 0l6.42.71a.6.6 0 0 1 .42.24L23.7 9a.6.6 0 0 1-.02.75L12.34 22.86a.45.45 0 0 1-.68 0L.31 9.74a.6.6 0 0 1-.02-.75Zm13.36-5.55a.15.15 0 0 0-.21.2l3.04 3.75a.3.3 0 0 1-.23.49h-8.5a.3.3 0 0 1-.23-.5l3.05-3.74a.15.15 0 0 0-.22-.2L5.8 7.72a.3.3 0 0 1-.5-.24l.21-3.04a.15.15 0 0 0-.3-.05l-.99 3.48a.75.75 0 0 1-.48.5l-2.19.71a.15.15 0 0 0 .05.3h2.1a.75.75 0 0 1 .64.34l5.56 8.74a.23.23 0 0 0 .39-.22L6.3 10.02a.45.45 0 0 1 .4-.64h10.57a.45.45 0 0 1 .4.64l-3.98 8.22a.22.22 0 0 0 .4.22l5.55-8.74a.75.75 0 0 1 .64-.34h2.04a.15.15 0 0 0 .04-.3l-2.12-.7a.75.75 0 0 1-.48-.51l-1-3.48a.15.15 0 0 0-.17-.1.15.15 0 0 0-.12.15l.22 3.04a.3.3 0 0 1-.51.24l-4.54-4.28Z"/>',
|
|
226
228
|
npm: '<path d="M1.76 0h20.48a1.76 1.76 0 0 1 1.76 1.76v20.48a1.76 1.76 0 0 1-1.76 1.76H1.76A1.76 1.76 0 0 1 0 22.24V1.76A1.76 1.76 0 0 1 1.76 0zM5.11 19.16h6.93V8.8h3.47v10.36h3.47V5.34H5.13v13.82z"></path>',
|
|
229
|
+
npmx: '<path d="M2.77 16.81h3.77v3.72H2.77zM18.8.12l-.57 1.6-7.27 20.55-.56 1.61h2.43l.57-1.6 1.84-5.2 6-16.96z"/>',
|
|
227
230
|
sourcehut:
|
|
228
231
|
'<path d="M12 20a8 8 0 0 1-8-8 8 8 0 0 1 8-8 8 8 0 0 1 8 8 8 8 0 0 1-8 8m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2"/>',
|
|
229
232
|
substack:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.11",
|
|
4
4
|
"description": "Build beautiful, high-performance documentation websites with Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@astrojs/markdown-remark": "^7.2.2",
|
|
55
55
|
"@playwright/test": "^1.61.1",
|
|
56
|
+
"@codspeed/vitest-plugin": "^5.7.1",
|
|
56
57
|
"@types/node": "^22.19.17",
|
|
57
58
|
"@vitest/coverage-v8": "^4.1.5",
|
|
58
59
|
"astro": "^7.1.6",
|
|
@@ -96,6 +97,8 @@
|
|
|
96
97
|
"scripts": {
|
|
97
98
|
"test": "VITE_CONFIG_NATIVE_IGNORE_WARNING=true vitest",
|
|
98
99
|
"test:coverage": "VITE_CONFIG_NATIVE_IGNORE_WARNING=true vitest run --coverage",
|
|
100
|
+
"bench": "pnpm bench:functional",
|
|
101
|
+
"bench:functional": "VITE_CONFIG_NATIVE_IGNORE_WARNING=true vitest bench --run --config vitest.functional.bench.config.ts __bench_fn__/*.bench.ts",
|
|
99
102
|
"test:e2e": "playwright install --with-deps chromium && playwright test",
|
|
100
103
|
"test:e2e:ci": "playwright test"
|
|
101
104
|
}
|
package/style/anchor-links.css
CHANGED
|
@@ -45,6 +45,11 @@ how we do it.
|
|
|
45
45
|
line-height: var(--sl-line-height-headings);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/* If the heading is hidden, remove the wrapper's box to avoid unwanted spacing. */
|
|
49
|
+
.sl-markdown-content .sl-heading-wrapper:has(> :first-child:is(.sr-only, [hidden])) {
|
|
50
|
+
display: contents;
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
/* We need to apply the same rule we use for heading spacing to the parent wrapper. */
|
|
49
54
|
.sl-markdown-content
|
|
50
55
|
:not(h1, h2, h3, h4, h5, h6, .sl-heading-wrapper)
|
|
@@ -75,7 +80,7 @@ how we do it.
|
|
|
75
80
|
/* ======================================================
|
|
76
81
|
HEADING
|
|
77
82
|
====================================================== */
|
|
78
|
-
.sl-markdown-content .sl-heading-wrapper > :first-child {
|
|
83
|
+
.sl-markdown-content .sl-heading-wrapper > :first-child:not([hidden]) {
|
|
79
84
|
display: inline;
|
|
80
85
|
/* Apply end-of-line padding to the heading element. */
|
|
81
86
|
padding-inline-end: var(--sl-anchor-icon-space);
|
|
@@ -96,6 +101,13 @@ how we do it.
|
|
|
96
101
|
display: inline-flex;
|
|
97
102
|
}
|
|
98
103
|
|
|
104
|
+
/* Hide anchor links for headings that are hidden. */
|
|
105
|
+
.sl-markdown-content
|
|
106
|
+
.sl-heading-wrapper:has(> :first-child:is(.sr-only, [hidden]))
|
|
107
|
+
> .sl-anchor-link {
|
|
108
|
+
display: none;
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
/* Increase clickable area for anchor links with a pseudo element that doesn’t impact layout. */
|
|
100
112
|
.sl-markdown-content .sl-anchor-link::after {
|
|
101
113
|
content: '';
|
package/translations/ar.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "نصيحة",
|
|
25
25
|
"aside.caution": "تنبيه",
|
|
26
26
|
"aside.danger": "تحذير",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "نافذة طرفيّة",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "نسخ إلى الحافظة",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "تم النسخ!",
|
|
27
30
|
"fileTree.directory": "Directory",
|
|
28
31
|
"builtWithStarlight.label": "طوِّر بواسطة Starlight",
|
|
29
32
|
"heading.anchorLabel": "Section titled “{{title}}”"
|
package/translations/hi.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "संकेत",
|
|
25
25
|
"aside.caution": "सावधानी",
|
|
26
26
|
"aside.danger": "खतरा",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "टर्मिनल विंडो",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "क्लिपबोर्ड पर कॉपी करें",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "कॉपी हो गया!",
|
|
27
30
|
"fileTree.directory": "Directory",
|
|
28
31
|
"builtWithStarlight.label": "Starlight द्वारा निर्मित",
|
|
29
32
|
"heading.anchorLabel": "Section titled “{{title}}”"
|
package/translations/it.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "Consiglio",
|
|
25
25
|
"aside.caution": "Attenzione",
|
|
26
26
|
"aside.danger": "Pericolo",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "Finestra del terminale",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "Copia",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "Copiato!",
|
|
27
30
|
"fileTree.directory": "Directory",
|
|
28
31
|
"builtWithStarlight.label": "Built with Starlight",
|
|
29
32
|
"heading.anchorLabel": "Sezione intitolata “{{title}}”"
|
package/translations/ja.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "ヒント",
|
|
25
25
|
"aside.caution": "注意",
|
|
26
26
|
"aside.danger": "危険",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "ターミナルウィンドウ",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "クリップボードにコピー",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "コピーしました!",
|
|
27
30
|
"fileTree.directory": "ディレクトリ",
|
|
28
31
|
"builtWithStarlight.label": "Starlightで作成",
|
|
29
32
|
"heading.anchorLabel": "Section titled “{{title}}”"
|
package/translations/ko.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "팁",
|
|
25
25
|
"aside.caution": "주의",
|
|
26
26
|
"aside.danger": "위험",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "터미널 창",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "클립보드로 복사",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "복사 완료!",
|
|
27
30
|
"fileTree.directory": "디렉터리",
|
|
28
31
|
"builtWithStarlight.label": "이 웹사이트는 Starlight로 제작되었습니다.",
|
|
29
32
|
"heading.anchorLabel": "섹션 제목: “{{title}}”"
|
package/translations/pt.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "Dica",
|
|
25
25
|
"aside.caution": "Cuidado",
|
|
26
26
|
"aside.danger": "Perigo",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "Janela do terminal",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "Copiar para área de transferência",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "Copiado!",
|
|
27
30
|
"fileTree.directory": "Directory",
|
|
28
31
|
"builtWithStarlight.label": "Feito com Starlight",
|
|
29
32
|
"heading.anchorLabel": "Seção intitulada “{{title}}”"
|
package/translations/zh-CN.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "提示",
|
|
25
25
|
"aside.caution": "警告",
|
|
26
26
|
"aside.danger": "危险",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "终端窗口",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "复制到剪贴板",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "复制成功!",
|
|
27
30
|
"fileTree.directory": "文件夹",
|
|
28
31
|
"builtWithStarlight.label": "基于 Starlight 构建",
|
|
29
32
|
"heading.anchorLabel": "Section titled “{{title}}”"
|
package/translations/zh-TW.json
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"aside.tip": "提示",
|
|
25
25
|
"aside.caution": "警告",
|
|
26
26
|
"aside.danger": "危險",
|
|
27
|
+
"expressiveCode.terminalWindowFallbackTitle": "終端機視窗",
|
|
28
|
+
"expressiveCode.copyButtonTooltip": "複製到剪貼簿",
|
|
29
|
+
"expressiveCode.copyButtonCopied": "複製成功!",
|
|
27
30
|
"fileTree.directory": "目錄",
|
|
28
31
|
"builtWithStarlight.label": "Built with Starlight",
|
|
29
32
|
"heading.anchorLabel": "Section titled “{{title}}”"
|
package/utils/navigation.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
stripExtension,
|
|
21
21
|
stripLeadingAndTrailingSlashes,
|
|
22
22
|
} from './path';
|
|
23
|
-
import { getLocaleRoutes,
|
|
23
|
+
import { getLocaleRoutes, getRouteById } from './routing';
|
|
24
24
|
import type {
|
|
25
25
|
SidebarGroup,
|
|
26
26
|
SidebarLink,
|
|
@@ -42,6 +42,7 @@ const SlugKey = Symbol('SlugKey');
|
|
|
42
42
|
const rootAutogenerate: SidebarAutogenerateRouteData = { directory: '' };
|
|
43
43
|
|
|
44
44
|
const neverPathFormatter = createPathFormatter({ trailingSlash: 'never' });
|
|
45
|
+
const sidebarCollator = new Intl.Collator(localeToLang(undefined));
|
|
45
46
|
|
|
46
47
|
const docsCollectionPathFromRoot = getCollectionPathFromRoot('docs', project);
|
|
47
48
|
|
|
@@ -142,7 +143,7 @@ function linkFromInternalSidebarLinkItem(
|
|
|
142
143
|
// Astro passes root `index.[md|mdx]` entries with a slug of `index`
|
|
143
144
|
const slug = item.slug === 'index' ? '' : item.slug;
|
|
144
145
|
const localizedSlug = locale ? (slug ? locale + '/' + slug : locale) : slug;
|
|
145
|
-
const route =
|
|
146
|
+
const route = getRouteById(localizedSlug);
|
|
146
147
|
if (!route) {
|
|
147
148
|
const hasExternalSlashes = item.slug.at(0) === '/' || item.slug.at(-1) === '/';
|
|
148
149
|
if (hasExternalSlashes) {
|
|
@@ -206,11 +207,6 @@ function makeLink({ attrs = {}, badge, autogenerate, ...opts }: MakeLinkOptions)
|
|
|
206
207
|
};
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
/** Test if two paths are equivalent even if formatted differently. */
|
|
210
|
-
function pathsMatch(pathA: string, pathB: string) {
|
|
211
|
-
return neverPathFormatter(pathA) === neverPathFormatter(pathB);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
210
|
/** Get the segments leading to a page. */
|
|
215
211
|
function getBreadcrumbs(path: string, baseDir: string): string[] {
|
|
216
212
|
// Strip extension from path.
|
|
@@ -294,21 +290,26 @@ function linkFromRoute(
|
|
|
294
290
|
* Directories have the weight of the lowest weighted route they contain.
|
|
295
291
|
*/
|
|
296
292
|
function getOrder(routeOrDir: Route | Dir): number {
|
|
297
|
-
|
|
293
|
+
const cachedOrder = orderByEntry.get(routeOrDir);
|
|
294
|
+
if (cachedOrder !== undefined) return cachedOrder;
|
|
295
|
+
const order = isDir(routeOrDir)
|
|
298
296
|
? Math.min(...Object.values(routeOrDir).flatMap(getOrder))
|
|
299
297
|
: // If no order value is found, set it to the largest number possible.
|
|
300
298
|
(routeOrDir.entry.data.sidebar.order ?? Number.MAX_VALUE);
|
|
299
|
+
orderByEntry.set(routeOrDir, order);
|
|
300
|
+
return order;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
const orderByEntry = new WeakMap<Dir | Route, number>();
|
|
304
|
+
|
|
303
305
|
/** Sort a directory’s entries by user-specified order or alphabetically if no order specified. */
|
|
304
306
|
function sortDirEntries(dir: [string, Dir | Route][]): [string, Dir | Route][] {
|
|
305
|
-
const collator = new Intl.Collator(localeToLang(undefined));
|
|
306
307
|
return dir.sort(([_keyA, a], [_keyB, b]) => {
|
|
307
308
|
const [aOrder, bOrder] = [getOrder(a), getOrder(b)];
|
|
308
309
|
// Pages are sorted by order in ascending order.
|
|
309
310
|
if (aOrder !== bOrder) return aOrder < bOrder ? -1 : 1;
|
|
310
311
|
// If two pages have the same order value they will be sorted by their slug.
|
|
311
|
-
return
|
|
312
|
+
return sidebarCollator.compare(isDir(a) ? a[SlugKey] : a.id, isDir(b) ? b[SlugKey] : b.id);
|
|
312
313
|
});
|
|
313
314
|
}
|
|
314
315
|
|
|
@@ -435,19 +436,20 @@ function setIntermediateSidebarCurrentEntry(
|
|
|
435
436
|
|
|
436
437
|
/** Finds the current page in a sidebar. */
|
|
437
438
|
function getSidebarCurrentEntry(sidebar: SidebarEntry[], pathname: string): SidebarLink | null {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const currentEntry = getSidebarCurrentEntry(entry.entries, pathname);
|
|
445
|
-
if (currentEntry) return currentEntry;
|
|
439
|
+
let entriesByPath = sidebarEntriesByPath.get(sidebar);
|
|
440
|
+
if (!entriesByPath) {
|
|
441
|
+
entriesByPath = new Map();
|
|
442
|
+
for (const entry of flattenSidebar(sidebar)) {
|
|
443
|
+
const path = neverPathFormatter(encodeURI(entry.href));
|
|
444
|
+
if (!entriesByPath.has(path)) entriesByPath.set(path, entry);
|
|
446
445
|
}
|
|
446
|
+
sidebarEntriesByPath.set(sidebar, entriesByPath);
|
|
447
447
|
}
|
|
448
|
-
return null;
|
|
448
|
+
return entriesByPath.get(neverPathFormatter(pathname)) ?? null;
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
+
const sidebarEntriesByPath = new WeakMap<SidebarEntry[], Map<string, SidebarLink>>();
|
|
452
|
+
|
|
451
453
|
/** Generates a deterministic string based on the content of the passed sidebar. */
|
|
452
454
|
export function getSidebarHash(sidebar: SidebarEntry[]): string {
|
|
453
455
|
let hash = 0;
|
|
@@ -472,11 +474,17 @@ function recursivelyBuildSidebarIdentity(sidebar: SidebarEntry[]): string {
|
|
|
472
474
|
|
|
473
475
|
/** Turn the nested tree structure of a sidebar into a flat list of all the links. */
|
|
474
476
|
export function flattenSidebar(sidebar: SidebarEntry[]): SidebarLink[] {
|
|
475
|
-
|
|
477
|
+
const cachedSidebar = flattenedSidebars.get(sidebar);
|
|
478
|
+
if (cachedSidebar) return cachedSidebar;
|
|
479
|
+
const flattenedSidebar = sidebar.flatMap((entry) =>
|
|
476
480
|
entry.type === 'group' ? flattenSidebar(entry.entries) : entry
|
|
477
481
|
);
|
|
482
|
+
flattenedSidebars.set(sidebar, flattenedSidebar);
|
|
483
|
+
return flattenedSidebar;
|
|
478
484
|
}
|
|
479
485
|
|
|
486
|
+
const flattenedSidebars = new WeakMap<SidebarEntry[], SidebarLink[]>();
|
|
487
|
+
|
|
480
488
|
/** Get previous/next pages in the sidebar or the ones from the frontmatter if any. */
|
|
481
489
|
export function getPrevNextLinks(
|
|
482
490
|
sidebar: SidebarEntry[],
|
package/utils/routing/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ validateLogoImports();
|
|
|
12
12
|
|
|
13
13
|
interface Path extends GetStaticPathsItem {
|
|
14
14
|
params: { slug: string | undefined };
|
|
15
|
-
props: Route;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -61,10 +60,10 @@ function getRoutes(): Route[] {
|
|
|
61
60
|
if (!localeConfig) continue;
|
|
62
61
|
const locale = key === 'root' ? undefined : key;
|
|
63
62
|
const localeDocs = getLocaleDocs(locale);
|
|
63
|
+
const localeDocIds = new Set(localeDocs.map(({ id }) => id));
|
|
64
64
|
for (const fallback of defaultLocaleDocs) {
|
|
65
65
|
const id = localizedSlug(fallback.id, locale);
|
|
66
|
-
|
|
67
|
-
if (doesNotNeedFallback) continue;
|
|
66
|
+
if (localeDocIds.has(id)) continue;
|
|
68
67
|
routes.push({
|
|
69
68
|
entry: fallback,
|
|
70
69
|
id,
|
|
@@ -82,6 +81,12 @@ function getRoutes(): Route[] {
|
|
|
82
81
|
}
|
|
83
82
|
export const routes = getRoutes();
|
|
84
83
|
|
|
84
|
+
const routesById = new Map(routes.map((route) => [route.id, route]));
|
|
85
|
+
|
|
86
|
+
export function getRouteById(id: string): Route | undefined {
|
|
87
|
+
return routesById.get(id);
|
|
88
|
+
}
|
|
89
|
+
|
|
85
90
|
function getParamRouteMapping(): ReadonlyMap<string | undefined, Route> {
|
|
86
91
|
const map = new Map<string | undefined, Route>();
|
|
87
92
|
for (const route of routes) {
|
|
@@ -98,7 +103,6 @@ export function getRouteBySlugParam(slugParam: string | undefined): Route | unde
|
|
|
98
103
|
function getPaths(): Path[] {
|
|
99
104
|
return routes.map((route) => ({
|
|
100
105
|
params: { slug: slugToParam(route.id) },
|
|
101
|
-
props: route,
|
|
102
106
|
}));
|
|
103
107
|
}
|
|
104
108
|
export const paths = getPaths();
|