@astrojs/starlight 0.17.1 → 0.17.3
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 +20 -0
- package/components/Header.astro +6 -1
- package/components/SiteTitle.astro +0 -3
- package/components/TableOfContents/starlight-toc.ts +2 -2
- package/expressive-code.d.ts +37 -0
- package/expressive-code.mjs +21 -0
- package/integrations/expressive-code/index.ts +1 -2
- package/internal.ts +5 -0
- package/package.json +7 -4
- package/translations/zh-CN.json +1 -1
- package/utils/localizedUrl.ts +17 -5
- package/utils/translations.ts +18 -11
- package/integrations/expressive-code/exports.ts +0 -70
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.17.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1461](https://github.com/withastro/starlight/pull/1461) [`2e17880`](https://github.com/withastro/starlight/commit/2e17880957d1aae2a84c77500afa9b66e5292a6a) Thanks [@liruifengv](https://github.com/liruifengv)! - Improves the table of contents title translation in Simplified Chinese
|
|
8
|
+
|
|
9
|
+
- [#1462](https://github.com/withastro/starlight/pull/1462) [`4741ccc`](https://github.com/withastro/starlight/commit/4741cccc8adbef500bcaf95416a1c61a90761c06) Thanks [@delucis](https://github.com/delucis)! - Fixes overflow of very long site titles on narrow viewports
|
|
10
|
+
|
|
11
|
+
- [#1459](https://github.com/withastro/starlight/pull/1459) [`9a8e0ec`](https://github.com/withastro/starlight/commit/9a8e0ec59cba0e088512ea9b6d17224085f3a178) Thanks [@delucis](https://github.com/delucis)! - Fixes a bug where table of contents highlighting could break given very specific combinations of content and viewport size
|
|
12
|
+
|
|
13
|
+
- [#1458](https://github.com/withastro/starlight/pull/1458) [`8c88642`](https://github.com/withastro/starlight/commit/8c88642875e8344396074a780e28fb0860b249f8) Thanks [@delucis](https://github.com/delucis)! - Silences i18n content collection warnings for projects without custom translations.
|
|
14
|
+
|
|
15
|
+
## 0.17.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#1442](https://github.com/withastro/starlight/pull/1442) [`1a642e4`](https://github.com/withastro/starlight/commit/1a642e4d74ee4c30e85bce37b41888b1eae0544a) Thanks [@delucis](https://github.com/delucis)! - Fixes URLs in language picker for sites with `build.format: 'file'`
|
|
20
|
+
|
|
21
|
+
- [#1440](https://github.com/withastro/starlight/pull/1440) [`2ea1e88`](https://github.com/withastro/starlight/commit/2ea1e883186660b48f0ea8c4da7fead5fb74e313) Thanks [@hippotastic](https://github.com/hippotastic)! - Adds JS support to the `@astrojs/starlight/expressive-code` export to allow importing from non-TS environments.
|
|
22
|
+
|
|
3
23
|
## 0.17.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/components/Header.astro
CHANGED
|
@@ -16,7 +16,7 @@ const shouldRenderSearch =
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
<div class="header sl-flex">
|
|
19
|
-
<div class="sl-flex">
|
|
19
|
+
<div class="title-wrapper sl-flex">
|
|
20
20
|
<SiteTitle {...Astro.props} />
|
|
21
21
|
</div>
|
|
22
22
|
<div class="sl-flex">
|
|
@@ -39,6 +39,11 @@ const shouldRenderSearch =
|
|
|
39
39
|
height: 100%;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
.title-wrapper {
|
|
43
|
+
/* Prevent long titles overflowing and covering the search and menu buttons on narrow viewports. */
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
.right-group,
|
|
43
48
|
.social-icons {
|
|
44
49
|
gap: 1rem;
|
|
@@ -95,8 +95,8 @@ export class StarlightTOC extends HTMLElement {
|
|
|
95
95
|
const mobileTocHeight = this.querySelector('summary')?.getBoundingClientRect().height || 0;
|
|
96
96
|
/** Start intersections at nav height + 2rem padding. */
|
|
97
97
|
const top = navBarHeight + mobileTocHeight + 32;
|
|
98
|
-
/** End intersections
|
|
99
|
-
const bottom = top +
|
|
98
|
+
/** End intersections `53px` later. This is slightly more than the maximum `margin-top` in Markdown content. */
|
|
99
|
+
const bottom = top + 53;
|
|
100
100
|
const height = document.documentElement.clientHeight;
|
|
101
101
|
return `-${top}px 0% ${bottom - height}px`;
|
|
102
102
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file This file provides the types for Starlight's `@astrojs/starlight/expressive-code` export.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from 'astro-expressive-code';
|
|
6
|
+
|
|
7
|
+
import type { StarlightExpressiveCodeOptions } from './integrations/expressive-code';
|
|
8
|
+
|
|
9
|
+
export type { StarlightExpressiveCodeOptions };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A utility function that helps you define an Expressive Code configuration object. It is meant
|
|
13
|
+
* to be used inside the optional config file `ec.config.mjs` located in the root directory
|
|
14
|
+
* of your Starlight project, and its return value to be exported as the default export.
|
|
15
|
+
*
|
|
16
|
+
* Expressive Code will automatically detect this file and use the exported configuration object
|
|
17
|
+
* to override its own default settings.
|
|
18
|
+
*
|
|
19
|
+
* Using this function is recommended, but not required. It just passes through the given object,
|
|
20
|
+
* but it also provides type information for your editor's auto-completion and type checking.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```js
|
|
24
|
+
* // ec.config.mjs
|
|
25
|
+
* import { defineEcConfig } from '@astrojs/starlight/expressive-code'
|
|
26
|
+
*
|
|
27
|
+
* export default defineEcConfig({
|
|
28
|
+
* themes: ['starlight-dark', 'github-light'],
|
|
29
|
+
* styleOverrides: {
|
|
30
|
+
* borderRadius: '0.5rem',
|
|
31
|
+
* },
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function defineEcConfig(
|
|
36
|
+
config: StarlightExpressiveCodeOptions
|
|
37
|
+
): StarlightExpressiveCodeOptions;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file This file is exported by Starlight as `@astrojs/starlight/expressive-code`.
|
|
3
|
+
*
|
|
4
|
+
* It is required by the `<Code>` component to access the same configuration preprocessor
|
|
5
|
+
* function as the one used by the integration.
|
|
6
|
+
*
|
|
7
|
+
* It also provides access to all of the Expressive Code classes and functions without having
|
|
8
|
+
* to install `astro-expressive-code` as an additional dependency into a user's project
|
|
9
|
+
* (and thereby risiking version conflicts).
|
|
10
|
+
*
|
|
11
|
+
* Note: This file is intentionally not a TypeScript module to allow access to all exported
|
|
12
|
+
* functionality even if TypeScript is not available, e.g. from the `ec.config.mjs` file
|
|
13
|
+
* that does not get processed by Vite.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export * from 'astro-expressive-code';
|
|
17
|
+
|
|
18
|
+
// @ts-ignore - Types are provided by the separate `expressive-code.d.ts` file
|
|
19
|
+
export function defineEcConfig(config) {
|
|
20
|
+
return config;
|
|
21
|
+
}
|
|
@@ -179,8 +179,7 @@ export const starlightExpressiveCode = ({
|
|
|
179
179
|
}),
|
|
180
180
|
preprocessComponentConfig: `
|
|
181
181
|
import starlightConfig from 'virtual:starlight/user-config'
|
|
182
|
-
import { useTranslations } from '@astrojs/starlight/internal'
|
|
183
|
-
import { getStarlightEcConfigPreprocessor } from '@astrojs/starlight/expressive-code'
|
|
182
|
+
import { useTranslations, getStarlightEcConfigPreprocessor } from '@astrojs/starlight/internal'
|
|
184
183
|
|
|
185
184
|
export default getStarlightEcConfigPreprocessor({ starlightConfig, useTranslations })
|
|
186
185
|
`,
|
package/internal.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/starlight",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"description": "Build beautiful, high-performance documentation websites with Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -154,7 +154,10 @@
|
|
|
154
154
|
"./props": "./props.ts",
|
|
155
155
|
"./schema": "./schema.ts",
|
|
156
156
|
"./types": "./types.ts",
|
|
157
|
-
"./expressive-code":
|
|
157
|
+
"./expressive-code": {
|
|
158
|
+
"types": "./expressive-code.d.ts",
|
|
159
|
+
"default": "./expressive-code.mjs"
|
|
160
|
+
},
|
|
158
161
|
"./index.astro": "./index.astro",
|
|
159
162
|
"./404.astro": "./404.astro",
|
|
160
163
|
"./style/markdown.css": "./style/markdown.css"
|
|
@@ -165,9 +168,9 @@
|
|
|
165
168
|
"devDependencies": {
|
|
166
169
|
"@astrojs/markdown-remark": "^4.0.1",
|
|
167
170
|
"@types/node": "^18.16.19",
|
|
168
|
-
"@vitest/coverage-v8": "^
|
|
171
|
+
"@vitest/coverage-v8": "^1.2.2",
|
|
169
172
|
"astro": "^4.2.1",
|
|
170
|
-
"vitest": "^
|
|
173
|
+
"vitest": "^1.2.2"
|
|
171
174
|
},
|
|
172
175
|
"dependencies": {
|
|
173
176
|
"@astrojs/mdx": "^2.0.4",
|
package/translations/zh-CN.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"languageSelect.accessibleLabel": "选择语言",
|
|
12
12
|
"menuButton.accessibleLabel": "菜单",
|
|
13
13
|
"sidebarNav.accessibleLabel": "主要",
|
|
14
|
-
"tableOfContents.onThisPage": "
|
|
14
|
+
"tableOfContents.onThisPage": "本页内容",
|
|
15
15
|
"tableOfContents.overview": "概述",
|
|
16
16
|
"i18n.untranslatedContent": "此内容尚不支持你的语言。",
|
|
17
17
|
"page.editLink": "编辑此页",
|
package/utils/localizedUrl.ts
CHANGED
|
@@ -17,14 +17,26 @@ export function localizedUrl(url: URL, locale: string | undefined): URL {
|
|
|
17
17
|
// Temporarily remove base to simplify
|
|
18
18
|
if (hasBase) url.pathname = url.pathname.replace(base, '');
|
|
19
19
|
const [_leadingSlash, baseSegment] = url.pathname.split('/');
|
|
20
|
-
|
|
20
|
+
// Strip .html extension to handle file output builds where URL might be e.g. `/en.html`
|
|
21
|
+
const htmlExt = '.html';
|
|
22
|
+
const isRootHtml = baseSegment?.endsWith(htmlExt);
|
|
23
|
+
const baseSlug = isRootHtml ? baseSegment?.slice(0, -1 * htmlExt.length) : baseSegment;
|
|
24
|
+
if (baseSlug && baseSlug in config.locales) {
|
|
21
25
|
// We’re in a localized route, substitute the new locale (or strip for root lang).
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
if (locale) {
|
|
27
|
+
url.pathname = url.pathname.replace(baseSlug, locale);
|
|
28
|
+
} else if (isRootHtml) {
|
|
29
|
+
url.pathname = '/index.html';
|
|
30
|
+
} else {
|
|
31
|
+
url.pathname = url.pathname.replace('/' + baseSlug, '');
|
|
32
|
+
}
|
|
25
33
|
} else if (locale) {
|
|
26
34
|
// We’re in the root language. Inject the new locale if we have one.
|
|
27
|
-
|
|
35
|
+
if (baseSegment === 'index.html') {
|
|
36
|
+
url.pathname = '/' + locale + '.html';
|
|
37
|
+
} else {
|
|
38
|
+
url.pathname = '/' + locale + url.pathname;
|
|
39
|
+
}
|
|
28
40
|
}
|
|
29
41
|
// Restore base
|
|
30
42
|
if (hasBase) url.pathname = base + url.pathname;
|
package/utils/translations.ts
CHANGED
|
@@ -3,16 +3,23 @@ import config from 'virtual:starlight/user-config';
|
|
|
3
3
|
import type { i18nSchemaOutput } from '../schemas/i18n';
|
|
4
4
|
import { createTranslationSystem } from './createTranslationSystem';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
/** Get all translation data from the i18n collection, keyed by `id`, which matches locale. */
|
|
7
|
+
async function loadTranslations() {
|
|
8
|
+
let userTranslations: Record<string, i18nSchemaOutput> = {};
|
|
9
|
+
// Briefly override `console.warn()` to silence logging when a project has no i18n collection.
|
|
10
|
+
const warn = console.warn;
|
|
11
|
+
console.warn = () => {};
|
|
12
|
+
try {
|
|
13
|
+
// Load the user’s i18n collection and ignore the error if it doesn’t exist.
|
|
14
|
+
userTranslations = Object.fromEntries(
|
|
15
|
+
// @ts-ignore — may be an error in projects without an i18n collection
|
|
16
|
+
(await getCollection('i18n')).map(({ id, data }) => [id, data] as const)
|
|
17
|
+
);
|
|
18
|
+
} catch {}
|
|
19
|
+
// Restore the original warn implementation.
|
|
20
|
+
console.warn = warn;
|
|
21
|
+
return userTranslations;
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
25
|
* Generate a utility function that returns UI strings for the given `locale`.
|
|
@@ -21,4 +28,4 @@ try {
|
|
|
21
28
|
* const t = useTranslations('en');
|
|
22
29
|
* const label = t('search.label'); // => 'Search'
|
|
23
30
|
*/
|
|
24
|
-
export const useTranslations = createTranslationSystem(
|
|
31
|
+
export const useTranslations = createTranslationSystem(await loadTranslations(), config);
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file This file is exported by Starlight as `@astrojs/starlight/expressive-code`
|
|
3
|
-
* and can be used in your site's configuration to customize Expressive Code.
|
|
4
|
-
*
|
|
5
|
-
* It provides access to all of the Expressive Code classes and functions without having
|
|
6
|
-
* to install `astro-expressive-code` as an additional dependency into your project
|
|
7
|
-
* (and thereby risiking version conflicts).
|
|
8
|
-
*
|
|
9
|
-
* For example, you can use this to load custom themes from a JSONC file (JSON with comments)
|
|
10
|
-
* that would otherwise be difficult to import, and pass them to the `themes` option:
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```js
|
|
14
|
-
* // astro.config.mjs
|
|
15
|
-
* import fs from 'node:fs';
|
|
16
|
-
* import { defineConfig } from 'astro/config';
|
|
17
|
-
* import starlight from '@astrojs/starlight';
|
|
18
|
-
* import { ExpressiveCodeTheme } from '@astrojs/starlight/expressive-code';
|
|
19
|
-
*
|
|
20
|
-
* const jsoncString = fs.readFileSync(new URL(`./my-theme.jsonc`, import.meta.url), 'utf-8');
|
|
21
|
-
* const myTheme = ExpressiveCodeTheme.fromJSONString(jsoncString);
|
|
22
|
-
*
|
|
23
|
-
* export default defineConfig({
|
|
24
|
-
* integrations: [
|
|
25
|
-
* starlight({
|
|
26
|
-
* title: 'My Starlight site',
|
|
27
|
-
* expressiveCode: {
|
|
28
|
-
* themes: [myTheme],
|
|
29
|
-
* },
|
|
30
|
-
* }),
|
|
31
|
-
* ],
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
export * from 'astro-expressive-code';
|
|
37
|
-
|
|
38
|
-
import type { StarlightExpressiveCodeOptions } from './index';
|
|
39
|
-
|
|
40
|
-
export type { StarlightExpressiveCodeOptions };
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A utility function that helps you define an Expressive Code configuration object. It is meant
|
|
44
|
-
* to be used inside the optional config file `ec.config.mjs` located in the root directory
|
|
45
|
-
* of your Starlight project, and its return value to be exported as the default export.
|
|
46
|
-
*
|
|
47
|
-
* Expressive Code will automatically detect this file and use the exported configuration object
|
|
48
|
-
* to override its own default settings.
|
|
49
|
-
*
|
|
50
|
-
* Using this function is recommended, but not required. It just passes through the given object,
|
|
51
|
-
* but it also provides type information for your editor's auto-completion and type checking.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```js
|
|
55
|
-
* // ec.config.mjs
|
|
56
|
-
* import { defineEcConfig } from '@astrojs/starlight/expressive-code'
|
|
57
|
-
*
|
|
58
|
-
* export default defineEcConfig({
|
|
59
|
-
* themes: ['starlight-dark', 'github-light'],
|
|
60
|
-
* styleOverrides: {
|
|
61
|
-
* borderRadius: '0.5rem',
|
|
62
|
-
* },
|
|
63
|
-
* })
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export function defineEcConfig(config: StarlightExpressiveCodeOptions) {
|
|
67
|
-
return config;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { getStarlightEcConfigPreprocessor } from './index';
|