@astrojs/starlight 0.25.3 → 0.25.5
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/Icons.ts +3 -0
- package/components/TableOfContents/starlight-toc.ts +10 -5
- package/package.json +6 -6
- package/schemas/social.ts +2 -0
- package/user-components/FileTree.astro +2 -1
- package/utils/i18n.ts +3 -3
- package/utils/localizedUrl.ts +2 -1
- package/utils/navigation.ts +7 -4
- package/utils/slugs.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.25.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2171](https://github.com/withastro/starlight/pull/2171) [`c8258d7`](https://github.com/withastro/starlight/commit/c8258d7ef9264a0f85710d463a83d16013dc1934) Thanks [@delucis](https://github.com/delucis)! - Improves build performance slightly for bigger sites
|
|
8
|
+
|
|
9
|
+
- [#2199](https://github.com/withastro/starlight/pull/2199) [`91557fd`](https://github.com/withastro/starlight/commit/91557fd73a43ab596f0fefb7c9aa0218b9a0b208) Thanks [@connorjs](https://github.com/connorjs)! - Adds Azure DevOps (`azureDevOps`) icon for use in social links.
|
|
10
|
+
|
|
11
|
+
## 0.25.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#2155](https://github.com/withastro/starlight/pull/2155) [`8bed886`](https://github.com/withastro/starlight/commit/8bed88674c732040cf66d392372386a8917a2eeb) Thanks [@delucis](https://github.com/delucis)! - Improves page load performance on slower devices
|
|
16
|
+
|
|
17
|
+
- [#2167](https://github.com/withastro/starlight/pull/2167) [`9ac7725`](https://github.com/withastro/starlight/commit/9ac7725dbe84f3fab9b191452471d8eaffd55048) Thanks [@delucis](https://github.com/delucis)! - Fixes an issue detecting the built-in locale when running Starlight in a web container environment on Firefox
|
|
18
|
+
|
|
19
|
+
- [#2166](https://github.com/withastro/starlight/pull/2166) [`4f12049`](https://github.com/withastro/starlight/commit/4f120490e914fb308e909b97890a11bb95ae964c) Thanks [@delucis](https://github.com/delucis)! - Updates `@astrojs/mdx`, `@astrojs/sitemap`, `astro-expressive-code`, `unified`, and `vfile` dependencies to the latest version
|
|
20
|
+
|
|
3
21
|
## 0.25.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/components/Icons.ts
CHANGED
|
@@ -92,6 +92,9 @@ export const BuiltInIcons = {
|
|
|
92
92
|
'<path d="M20.47 2H3.53a1.45 1.45 0 0 0-1.47 1.43v17.14A1.45 1.45 0 0 0 3.53 22h16.94a1.45 1.45 0 0 0 1.47-1.43V3.43A1.45 1.45 0 0 0 20.47 2ZM8.09 18.74h-3v-9h3v9ZM6.59 8.48a1.56 1.56 0 0 1 0-3.12 1.57 1.57 0 1 1 0 3.12Zm12.32 10.26h-3v-4.83c0-1.21-.43-2-1.52-2A1.65 1.65 0 0 0 12.85 13a2 2 0 0 0-.1.73v5h-3v-9h3V11a3 3 0 0 1 2.71-1.5c2 0 3.45 1.29 3.45 4.06v5.18Z"/>',
|
|
93
93
|
twitch:
|
|
94
94
|
'<path d="M2.5 1 1 4.8v15.4h5.5V23h3.1l3-2.8H17l6-5.7V1H2.6ZM21 13.5l-3.4 3.3H12l-3 2.8v-2.8H4.5V3H21v10.5Zm-3.4-6.8v5.8h-2V6.7h2Zm-5.5 0v5.8h-2V6.7h2Z"/>',
|
|
95
|
+
azureDevOps:
|
|
96
|
+
'<path d="M17,4v9.74l-4,3.28-6.2-2.26V17L3.29,12.41l10.23.8V4.44Zm-3.41.49L7.85,1V3.29L2.58,4.84,1,6.87v4.61l2.26,1V6.57Z"/>',
|
|
97
|
+
|
|
95
98
|
microsoftTeams:
|
|
96
99
|
'<path d="M13.78 7.2a3.63 3.63 0 1 0-4.3-3.68h1.78a2.52 2.52 0 0 1 2.52 2.53V7.2zM7.34 18.8h3.92a2.52 2.52 0 0 0 2.52-2.52V8.37h4.17c.58.01 1.04.5 1.03 1.07v6.45a6.3 6.3 0 0 1-6.14 6.43 6.3 6.3 0 0 1-5.5-3.52zm16.1-14.06a2.51 2.51 0 1 1-5.02 0 2.51 2.51 0 0 1 5.02 0zm-3.36 14.24h-.17c.4-1 .59-2.05.57-3.11V9.46c0-.38-.07-.75-.23-1.09h2.69c.58 0 1.06.48 1.06 1.06v5.65a3.9 3.9 0 0 1-3.9 3.9h-.02z"/><path d="M1.02 5.02h10.24c.56 0 1.02.46 1.02 1.03v10.23a1.02 1.02 0 0 1-1.02 1.02H1.02A1.02 1.02 0 0 1 0 16.28V6.04c0-.56.46-1.02 1.02-1.02zm7.81 3.9V7.84H3.45v1.08h2.03v5.57h1.3V8.92h2.05z"/>',
|
|
97
100
|
instagram:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PAGE_TITLE_ID } from '../../constants';
|
|
2
2
|
|
|
3
3
|
export class StarlightTOC extends HTMLElement {
|
|
4
|
-
private _current = this.querySelector('a[aria-current="true"]')
|
|
4
|
+
private _current = this.querySelector<HTMLAnchorElement>('a[aria-current="true"]');
|
|
5
5
|
private minH = parseInt(this.dataset.minH || '2', 10);
|
|
6
6
|
private maxH = parseInt(this.dataset.maxH || '3', 10);
|
|
7
7
|
|
|
@@ -12,9 +12,15 @@ export class StarlightTOC extends HTMLElement {
|
|
|
12
12
|
this._current = link;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
private onIdle = (cb: IdleRequestCallback) =>
|
|
16
|
+
(window.requestIdleCallback || ((cb) => setTimeout(cb, 1)))(cb);
|
|
17
|
+
|
|
15
18
|
constructor() {
|
|
16
19
|
super();
|
|
20
|
+
this.onIdle(() => this.init());
|
|
21
|
+
}
|
|
17
22
|
|
|
23
|
+
private init = (): void => {
|
|
18
24
|
/** All the links in the table of contents. */
|
|
19
25
|
const links = [...this.querySelectorAll('a')];
|
|
20
26
|
|
|
@@ -73,21 +79,20 @@ export class StarlightTOC extends HTMLElement {
|
|
|
73
79
|
|
|
74
80
|
let observer: IntersectionObserver | undefined;
|
|
75
81
|
const observe = () => {
|
|
76
|
-
if (observer)
|
|
82
|
+
if (observer) return;
|
|
77
83
|
observer = new IntersectionObserver(setCurrent, { rootMargin: this.getRootMargin() });
|
|
78
84
|
toObserve.forEach((h) => observer!.observe(h));
|
|
79
85
|
};
|
|
80
86
|
observe();
|
|
81
87
|
|
|
82
|
-
const onIdle = window.requestIdleCallback || ((cb) => setTimeout(cb, 1));
|
|
83
88
|
let timeout: NodeJS.Timeout;
|
|
84
89
|
window.addEventListener('resize', () => {
|
|
85
90
|
// Disable intersection observer while window is resizing.
|
|
86
91
|
if (observer) observer.disconnect();
|
|
87
92
|
clearTimeout(timeout);
|
|
88
|
-
timeout = setTimeout(() => onIdle(observe), 200);
|
|
93
|
+
timeout = setTimeout(() => this.onIdle(observe), 200);
|
|
89
94
|
});
|
|
90
|
-
}
|
|
95
|
+
};
|
|
91
96
|
|
|
92
97
|
private getRootMargin(): `-${number}px 0% ${number}px` {
|
|
93
98
|
const navBarHeight = document.querySelector('header')?.getBoundingClientRect().height || 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.5",
|
|
4
4
|
"description": "Build beautiful, high-performance documentation websites with Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -182,12 +182,12 @@
|
|
|
182
182
|
"vitest": "^1.6.0"
|
|
183
183
|
},
|
|
184
184
|
"dependencies": {
|
|
185
|
-
"@astrojs/mdx": "^3.1.
|
|
186
|
-
"@astrojs/sitemap": "^3.1.
|
|
185
|
+
"@astrojs/mdx": "^3.1.3",
|
|
186
|
+
"@astrojs/sitemap": "^3.1.6",
|
|
187
187
|
"@pagefind/default-ui": "^1.0.3",
|
|
188
188
|
"@types/hast": "^3.0.4",
|
|
189
189
|
"@types/mdast": "^4.0.4",
|
|
190
|
-
"astro-expressive-code": "^0.35.
|
|
190
|
+
"astro-expressive-code": "^0.35.6",
|
|
191
191
|
"bcp-47": "^2.1.0",
|
|
192
192
|
"hast-util-from-html": "^2.0.1",
|
|
193
193
|
"hast-util-select": "^6.0.2",
|
|
@@ -200,9 +200,9 @@
|
|
|
200
200
|
"rehype": "^13.0.1",
|
|
201
201
|
"rehype-format": "^5.0.0",
|
|
202
202
|
"remark-directive": "^3.0.0",
|
|
203
|
-
"unified": "^11.0.
|
|
203
|
+
"unified": "^11.0.5",
|
|
204
204
|
"unist-util-visit": "^5.0.0",
|
|
205
|
-
"vfile": "^6.0.
|
|
205
|
+
"vfile": "^6.0.2"
|
|
206
206
|
},
|
|
207
207
|
"scripts": {
|
|
208
208
|
"test": "vitest",
|
package/schemas/social.ts
CHANGED
|
@@ -14,6 +14,7 @@ export const socialLinks = [
|
|
|
14
14
|
'threads',
|
|
15
15
|
'linkedin',
|
|
16
16
|
'twitch',
|
|
17
|
+
'azureDevOps',
|
|
17
18
|
'microsoftTeams',
|
|
18
19
|
'instagram',
|
|
19
20
|
'stackOverflow',
|
|
@@ -62,6 +63,7 @@ export const SocialLinksSchema = () =>
|
|
|
62
63
|
threads: 'Threads',
|
|
63
64
|
linkedin: 'LinkedIn',
|
|
64
65
|
twitch: 'Twitch',
|
|
66
|
+
azureDevOps: 'Azure DevOps',
|
|
65
67
|
microsoftTeams: 'Microsoft Teams',
|
|
66
68
|
instagram: 'Instagram',
|
|
67
69
|
stackOverflow: 'Stack Overflow',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
---
|
|
2
|
+
import { stripLeadingAndTrailingSlashes } from '../utils/path';
|
|
2
3
|
import { slugToLocaleData } from '../utils/slugs';
|
|
3
4
|
import { useTranslations } from '../utils/translations';
|
|
4
5
|
import { processFileTree } from './rehype-file-tree';
|
|
5
6
|
|
|
6
|
-
const slug = Astro.url.pathname
|
|
7
|
+
const slug = stripLeadingAndTrailingSlashes(Astro.url.pathname);
|
|
7
8
|
const t = useTranslations(slugToLocaleData(slug).locale);
|
|
8
9
|
|
|
9
10
|
const fileTreeHtml = await Astro.slots.render('default');
|
package/utils/i18n.ts
CHANGED
|
@@ -2,9 +2,6 @@ import type { AstroConfig } from 'astro';
|
|
|
2
2
|
import { AstroError } from 'astro/errors';
|
|
3
3
|
import type { StarlightConfig } from './user-config';
|
|
4
4
|
|
|
5
|
-
/** Informations about the built-in default locale used as a fallback when no locales are defined. */
|
|
6
|
-
export const BuiltInDefaultLocale = { ...getLocaleInfo('en'), lang: 'en' };
|
|
7
|
-
|
|
8
5
|
/**
|
|
9
6
|
* A list of well-known right-to-left languages used as a fallback when determining the text
|
|
10
7
|
* direction of a locale is not supported by the `Intl.Locale` API in the current environment.
|
|
@@ -14,6 +11,9 @@ export const BuiltInDefaultLocale = { ...getLocaleInfo('en'), lang: 'en' };
|
|
|
14
11
|
*/
|
|
15
12
|
const wellKnownRTL = ['ar', 'fa', 'he', 'prs', 'ps', 'syc', 'ug', 'ur'];
|
|
16
13
|
|
|
14
|
+
/** Informations about the built-in default locale used as a fallback when no locales are defined. */
|
|
15
|
+
export const BuiltInDefaultLocale = { ...getLocaleInfo('en'), lang: 'en' };
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Processes the Astro and Starlight i18n configurations to generate/update them accordingly:
|
|
19
19
|
*
|
package/utils/localizedUrl.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from 'virtual:starlight/user-config';
|
|
2
|
+
import { stripTrailingSlash } from './path';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Get the equivalent of the passed URL for the passed locale.
|
|
@@ -12,7 +13,7 @@ export function localizedUrl(url: URL, locale: string | undefined): URL {
|
|
|
12
13
|
}
|
|
13
14
|
if (locale === 'root') locale = '';
|
|
14
15
|
/** Base URL with trailing `/` stripped. */
|
|
15
|
-
const base = import.meta.env.BASE_URL
|
|
16
|
+
const base = stripTrailingSlash(import.meta.env.BASE_URL);
|
|
16
17
|
const hasBase = url.pathname.startsWith(base);
|
|
17
18
|
// Temporarily remove base to simplify
|
|
18
19
|
if (hasBase) url.pathname = url.pathname.replace(base, '');
|
package/utils/navigation.ts
CHANGED
|
@@ -139,10 +139,10 @@ function linkFromInternalSidebarLinkItem(
|
|
|
139
139
|
locale: string | undefined,
|
|
140
140
|
currentPathname: string
|
|
141
141
|
) {
|
|
142
|
-
let slugWithLocale = locale ? locale + '/' + item.slug : item.slug;
|
|
143
142
|
// Astro passes root `index.[md|mdx]` entries with a slug of `index`
|
|
144
|
-
|
|
145
|
-
const
|
|
143
|
+
const slug = item.slug === 'index' ? '' : item.slug;
|
|
144
|
+
const localizedSlug = locale ? (slug ? locale + '/' + slug : locale) : slug;
|
|
145
|
+
const entry = routes.find((entry) => localizedSlug === entry.slug);
|
|
146
146
|
if (!entry) {
|
|
147
147
|
const hasExternalSlashes = item.slug.at(0) === '/' || item.slug.at(-1) === '/';
|
|
148
148
|
if (hasExternalSlashes) {
|
|
@@ -410,4 +410,7 @@ function applyPrevNextLinkConfig(
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
/** Remove the extension from a path. */
|
|
413
|
-
|
|
413
|
+
function stripExtension(path: string) {
|
|
414
|
+
const periodIndex = path.lastIndexOf('.');
|
|
415
|
+
return path.slice(0, periodIndex > -1 ? periodIndex : undefined);
|
|
416
|
+
}
|
package/utils/slugs.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import config from 'virtual:starlight/user-config';
|
|
2
2
|
import { BuiltInDefaultLocale } from './i18n';
|
|
3
|
+
import { stripTrailingSlash } from './path';
|
|
3
4
|
|
|
4
5
|
export interface LocaleData {
|
|
5
6
|
/** Writing direction. */
|
|
@@ -52,7 +53,7 @@ export function slugToParam(slug: string): string | undefined {
|
|
|
52
53
|
return slug === 'index' || slug === ''
|
|
53
54
|
? undefined
|
|
54
55
|
: slug.endsWith('/index')
|
|
55
|
-
? slug.
|
|
56
|
+
? slug.slice(0, -6)
|
|
56
57
|
: slug;
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -77,7 +78,7 @@ export function localizedSlug(slug: string, locale: string | undefined): string
|
|
|
77
78
|
locale = locale || '';
|
|
78
79
|
if (slugLocale === slug) return locale;
|
|
79
80
|
if (slugLocale) {
|
|
80
|
-
return slug.replace(slugLocale + '/', locale ? locale + '/' : '')
|
|
81
|
+
return stripTrailingSlash(slug.replace(slugLocale + '/', locale ? locale + '/' : ''));
|
|
81
82
|
}
|
|
82
83
|
return slug ? locale + '/' + slug : locale;
|
|
83
84
|
}
|
|
@@ -106,7 +107,7 @@ export function localizedId(id: string, locale: string | undefined): string {
|
|
|
106
107
|
/** Extract the slug from a URL. */
|
|
107
108
|
export function urlToSlug(url: URL): string {
|
|
108
109
|
let pathname = url.pathname;
|
|
109
|
-
const base = import.meta.env.BASE_URL
|
|
110
|
+
const base = stripTrailingSlash(import.meta.env.BASE_URL);
|
|
110
111
|
if (pathname.startsWith(base)) pathname = pathname.replace(base, '');
|
|
111
112
|
const segments = pathname.split('/');
|
|
112
113
|
const htmlExt = '.html';
|