@astrojs/starlight 0.0.6 → 0.0.7
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 +12 -0
- package/components/Header.astro +3 -11
- package/components/RightSidebar.astro +2 -2
- package/components/SiteTitle.astro +74 -0
- package/index.astro +14 -0
- package/index.ts +6 -0
- package/package.json +1 -1
- package/schemas/logo.ts +28 -0
- package/utils/routing.ts +23 -5
- package/utils/slugs.ts +9 -11
- package/utils/user-config.ts +4 -0
- package/virtual.d.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @astrojs/starlight
|
|
2
2
|
|
|
3
|
+
## 0.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#55](https://github.com/withastro/starlight/pull/55) [`8597b9c`](https://github.com/withastro/starlight/commit/8597b9c1002f8c5073d25ae5cacd4060ded2f8c8) Thanks [@delucis](https://github.com/delucis)! - Fix routing logic to handle `index.md` slug differences between docs collection root and nested directories.
|
|
8
|
+
|
|
9
|
+
- [#54](https://github.com/withastro/starlight/pull/54) [`db728d6`](https://github.com/withastro/starlight/commit/db728d61afa5cea060c66f746a4cc4ab3e1c3bcd) Thanks [@TheOtterlord](https://github.com/TheOtterlord)! - Add padding to scroll preventing headings being obscured by nav
|
|
10
|
+
|
|
11
|
+
- [#51](https://github.com/withastro/starlight/pull/51) [`3adbdbb`](https://github.com/withastro/starlight/commit/3adbdbbb71a4b3648984fa1028fa116d0aff9a7d) Thanks [@delucis](https://github.com/delucis)! - Support displaying a custom logo in the nav bar.
|
|
12
|
+
|
|
13
|
+
- [#51](https://github.com/withastro/starlight/pull/51) [`3adbdbb`](https://github.com/withastro/starlight/commit/3adbdbbb71a4b3648984fa1028fa116d0aff9a7d) Thanks [@delucis](https://github.com/delucis)! - All Starlight projects now use Astro’s experimental optimized asset support.
|
|
14
|
+
|
|
3
15
|
## 0.0.6
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/components/Header.astro
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
import config from 'virtual:starlight/user-config';
|
|
3
2
|
import LanguageSelect from './LanguageSelect.astro';
|
|
4
3
|
import Search from './Search.astro';
|
|
5
|
-
import
|
|
4
|
+
import SiteTitle from './SiteTitle.astro';
|
|
6
5
|
import SocialIcons from './SocialIcons.astro';
|
|
6
|
+
import ThemeSelect from './ThemeSelect.astro';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
9
|
locale: string | undefined;
|
|
@@ -11,7 +11,7 @@ interface Props {
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
<div class="header">
|
|
14
|
-
<
|
|
14
|
+
<SiteTitle />
|
|
15
15
|
<Search />
|
|
16
16
|
<div class="hidden md:flex right-group">
|
|
17
17
|
<SocialIcons />
|
|
@@ -29,14 +29,6 @@ interface Props {
|
|
|
29
29
|
height: 100%;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
.site-title {
|
|
33
|
-
font-size: var(--sl-text-h4);
|
|
34
|
-
font-weight: 600;
|
|
35
|
-
color: var(--sl-color-text-accent);
|
|
36
|
-
text-decoration: none;
|
|
37
|
-
white-space: nowrap;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
32
|
.right-group {
|
|
41
33
|
gap: 1rem;
|
|
42
34
|
align-items: center;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { MarkdownHeading } from 'astro';
|
|
3
|
-
import type { CollectionEntry } from 'astro:content';
|
|
4
3
|
import config from 'virtual:starlight/user-config';
|
|
4
|
+
import type { StarlightDocsEntry } from '../utils/routing';
|
|
5
5
|
import EditLink from './EditLink.astro';
|
|
6
6
|
import RightSidebarPanel from './RightSidebarPanel.astro';
|
|
7
7
|
import TableOfContents from './TableOfContents.astro';
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
|
-
entry:
|
|
10
|
+
entry: StarlightDocsEntry;
|
|
11
11
|
headings: MarkdownHeading[];
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { logos } from 'virtual:starlight/user-images';
|
|
3
|
+
import config from 'virtual:starlight/user-config';
|
|
4
|
+
|
|
5
|
+
if (config.logo) {
|
|
6
|
+
let err: string | undefined;
|
|
7
|
+
if ('src' in config.logo) {
|
|
8
|
+
if (!logos.dark || !logos.light) {
|
|
9
|
+
err = `Could not resolve logo import for "${config.logo.src}" (logo.src)`;
|
|
10
|
+
}
|
|
11
|
+
} else {
|
|
12
|
+
if (!logos.dark) {
|
|
13
|
+
err = `Could not resolve logo import for "${config.logo.dark}" (logo.dark)`;
|
|
14
|
+
} else if (!logos.light) {
|
|
15
|
+
err = `Could not resolve logo import for "${config.logo.light}" (logo.light)`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (err) throw new Error(err);
|
|
19
|
+
}
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<a href={import.meta.env.BASE_URL} class="site-title flex">
|
|
23
|
+
{
|
|
24
|
+
config.logo && logos.dark && (
|
|
25
|
+
<>
|
|
26
|
+
<img
|
|
27
|
+
class:list={{ 'dark-only': !('src' in config.logo) }}
|
|
28
|
+
alt={config.logo.alt}
|
|
29
|
+
src={logos.dark.src}
|
|
30
|
+
width={logos.dark.width}
|
|
31
|
+
height={logos.dark.height}
|
|
32
|
+
/>
|
|
33
|
+
{/* Show light alternate if a user configure both light and dark logos. */}
|
|
34
|
+
{!('src' in config.logo) && (
|
|
35
|
+
<img
|
|
36
|
+
class="light-only"
|
|
37
|
+
alt={config.logo.alt}
|
|
38
|
+
src={logos.light?.src}
|
|
39
|
+
width={logos.light?.width}
|
|
40
|
+
height={logos.light?.height}
|
|
41
|
+
/>
|
|
42
|
+
)}
|
|
43
|
+
</>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
<span class:list={{ 'sr-only': config.logo?.replacesTitle }}>
|
|
47
|
+
{config.title}
|
|
48
|
+
</span>
|
|
49
|
+
</a>
|
|
50
|
+
|
|
51
|
+
<style>
|
|
52
|
+
.site-title {
|
|
53
|
+
align-items: center;
|
|
54
|
+
gap: var(--sl-nav-gap);
|
|
55
|
+
font-size: var(--sl-text-h4);
|
|
56
|
+
font-weight: 600;
|
|
57
|
+
color: var(--sl-color-text-accent);
|
|
58
|
+
text-decoration: none;
|
|
59
|
+
white-space: nowrap;
|
|
60
|
+
}
|
|
61
|
+
img {
|
|
62
|
+
height: calc(var(--sl-nav-height) - 2 * var(--sl-nav-pad-y));
|
|
63
|
+
width: auto;
|
|
64
|
+
max-width: 100%;
|
|
65
|
+
object-fit: contain;
|
|
66
|
+
object-position: 0 50%;
|
|
67
|
+
}
|
|
68
|
+
:global([data-theme='light']) .dark-only {
|
|
69
|
+
display: none;
|
|
70
|
+
}
|
|
71
|
+
:global([data-theme='dark']) .light-only {
|
|
72
|
+
display: none;
|
|
73
|
+
}
|
|
74
|
+
</style>
|
package/index.astro
CHANGED
|
@@ -47,6 +47,20 @@ const prevNextLinks = getPrevNextLinks(sidebar);
|
|
|
47
47
|
<html lang={lang} dir={dir}>
|
|
48
48
|
<head>
|
|
49
49
|
<HeadSEO data={entry.data} lang={lang} />
|
|
50
|
+
<style>
|
|
51
|
+
/* Add scroll padding to ensure anchor headings aren't obscured by nav */
|
|
52
|
+
html {
|
|
53
|
+
/* Additional padding is needed to account for the mobile TOC */
|
|
54
|
+
scroll-padding-top: calc(
|
|
55
|
+
1.5rem + var(--sl-nav-height) + var(--sl-mobile-toc-height)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
@media (min-width: 72em) {
|
|
59
|
+
html {
|
|
60
|
+
scroll-padding-top: calc(1.5rem + var(--sl-nav-height));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
50
64
|
</head>
|
|
51
65
|
<body>
|
|
52
66
|
<ThemeProvider />
|
package/index.ts
CHANGED
|
@@ -45,6 +45,7 @@ export default function StarlightIntegration(
|
|
|
45
45
|
? {}
|
|
46
46
|
: { theme: 'css-variables' },
|
|
47
47
|
},
|
|
48
|
+
experimental: { assets: true },
|
|
48
49
|
};
|
|
49
50
|
updateConfig(newConfig);
|
|
50
51
|
},
|
|
@@ -84,6 +85,11 @@ function vitePluginStarlightUserConfig(
|
|
|
84
85
|
'virtual:starlight/user-css': opts.customCss
|
|
85
86
|
.map((id) => `import "${id}";`)
|
|
86
87
|
.join(''),
|
|
88
|
+
'virtual:starlight/user-images': opts.logo
|
|
89
|
+
? 'src' in opts.logo
|
|
90
|
+
? `import src from "${opts.logo.src}"; export const logos = { dark: src, light: src };`
|
|
91
|
+
: `import dark from "${opts.logo.dark}"; import light from "${opts.logo.light}"; export const logos = { dark, light };`
|
|
92
|
+
: 'export const logos = {};',
|
|
87
93
|
};
|
|
88
94
|
const resolutionMap = Object.fromEntries(
|
|
89
95
|
(Object.keys(modules) as (keyof typeof modules)[]).map((key) => [
|
package/package.json
CHANGED
package/schemas/logo.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'astro/zod';
|
|
2
|
+
|
|
3
|
+
export const LogoConfigSchema = () =>
|
|
4
|
+
z
|
|
5
|
+
.union([
|
|
6
|
+
z.object({
|
|
7
|
+
/** Source of the image file to use. */
|
|
8
|
+
src: z.string(),
|
|
9
|
+
/** Alternative text description of the logo. */
|
|
10
|
+
alt: z.string().default(''),
|
|
11
|
+
/** Set to `true` to hide the site title text and only show the logo. */
|
|
12
|
+
replacesTitle: z.boolean().default(false),
|
|
13
|
+
}),
|
|
14
|
+
z.object({
|
|
15
|
+
/** Source of the image file to use in dark mode. */
|
|
16
|
+
dark: z.string(),
|
|
17
|
+
/** Source of the image file to use in light mode. */
|
|
18
|
+
light: z.string(),
|
|
19
|
+
/** Alternative text description of the logo. */
|
|
20
|
+
alt: z.string().default(''),
|
|
21
|
+
/** Set to `true` to hide the site title text and only show the logo. */
|
|
22
|
+
replacesTitle: z.boolean().default(false),
|
|
23
|
+
}),
|
|
24
|
+
])
|
|
25
|
+
.optional();
|
|
26
|
+
|
|
27
|
+
export type LogoUserConfig = z.input<ReturnType<typeof LogoConfigSchema>>;
|
|
28
|
+
export type LogoConfig = z.output<ReturnType<typeof LogoConfigSchema>>;
|
package/utils/routing.ts
CHANGED
|
@@ -8,8 +8,12 @@ import {
|
|
|
8
8
|
slugToParam,
|
|
9
9
|
} from './slugs';
|
|
10
10
|
|
|
11
|
+
export type StarlightDocsEntry = Omit<CollectionEntry<'docs'>, 'slug'> & {
|
|
12
|
+
slug: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
11
15
|
export interface Route extends LocaleData {
|
|
12
|
-
entry:
|
|
16
|
+
entry: StarlightDocsEntry;
|
|
13
17
|
entryMeta: LocaleData;
|
|
14
18
|
slug: string;
|
|
15
19
|
isFallback?: true;
|
|
@@ -21,8 +25,17 @@ interface Path extends GetStaticPathsItem {
|
|
|
21
25
|
props: Route;
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Astro is inconsistent in its `index.md` slug generation. In most cases,
|
|
30
|
+
* `index` is stripped, but in the root of a collection, we get a slug of `index`.
|
|
31
|
+
* We map that to an empty string for consistent behaviour.
|
|
32
|
+
*/
|
|
33
|
+
const normalizeIndexSlug = (slug: string) => (slug === 'index' ? '' : slug);
|
|
34
|
+
|
|
24
35
|
/** All entries in the docs content collection. */
|
|
25
|
-
const docs = await getCollection('docs')
|
|
36
|
+
const docs: StarlightDocsEntry[] = (await getCollection('docs')).map(
|
|
37
|
+
({ slug, ...entry }) => ({ ...entry, slug: normalizeIndexSlug(slug) })
|
|
38
|
+
);
|
|
26
39
|
|
|
27
40
|
function getRoutes(): Route[] {
|
|
28
41
|
const routes: Route[] = docs.map((entry) => ({
|
|
@@ -87,7 +100,7 @@ export function getLocaleRoutes(locale: string | undefined): Route[] {
|
|
|
87
100
|
* Get all entries in the docs content collection for a specific locale.
|
|
88
101
|
* A locale of `undefined` is treated as the “root” locale, if configured.
|
|
89
102
|
*/
|
|
90
|
-
function getLocaleDocs(locale: string | undefined):
|
|
103
|
+
function getLocaleDocs(locale: string | undefined): StarlightDocsEntry[] {
|
|
91
104
|
return filterByLocale(docs, locale);
|
|
92
105
|
}
|
|
93
106
|
|
|
@@ -98,11 +111,16 @@ function filterByLocale<T extends { slug: string }>(
|
|
|
98
111
|
): T[] {
|
|
99
112
|
if (config.locales) {
|
|
100
113
|
if (locale && locale in config.locales) {
|
|
101
|
-
return items.filter(
|
|
114
|
+
return items.filter(
|
|
115
|
+
(i) => i.slug === locale || i.slug.startsWith(locale + '/')
|
|
116
|
+
);
|
|
102
117
|
} else if (config.locales.root) {
|
|
103
118
|
const langKeys = Object.keys(config.locales).filter((k) => k !== 'root');
|
|
119
|
+
const isLangIndex = new RegExp(`^(${langKeys.join('|')})$`);
|
|
104
120
|
const isLangDir = new RegExp(`^(${langKeys.join('|')})/`);
|
|
105
|
-
return items.filter(
|
|
121
|
+
return items.filter(
|
|
122
|
+
(i) => !isLangIndex.test(i.slug) && !isLangDir.test(i.slug)
|
|
123
|
+
);
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
return items;
|
package/utils/slugs.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { CollectionEntry } from 'astro:content';
|
|
2
1
|
import config from 'virtual:starlight/user-config';
|
|
3
2
|
|
|
4
3
|
export interface LocaleData {
|
|
@@ -16,9 +15,7 @@ export interface LocaleData {
|
|
|
16
15
|
* Root locale slugs will return `undefined`.
|
|
17
16
|
* @param slug A collection entry slug
|
|
18
17
|
*/
|
|
19
|
-
function slugToLocale(
|
|
20
|
-
slug: CollectionEntry<'docs'>['slug']
|
|
21
|
-
): string | undefined {
|
|
18
|
+
function slugToLocale(slug: string): string | undefined {
|
|
22
19
|
const locales = Object.keys(config.locales || {});
|
|
23
20
|
const baseSegment = slug.split('/')[0];
|
|
24
21
|
if (baseSegment && locales.includes(baseSegment)) return baseSegment;
|
|
@@ -26,9 +23,7 @@ function slugToLocale(
|
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
/** Get locale information for a given slug. */
|
|
29
|
-
export function slugToLocaleData(
|
|
30
|
-
slug: CollectionEntry<'docs'>['slug']
|
|
31
|
-
): LocaleData {
|
|
26
|
+
export function slugToLocaleData(slug: string): LocaleData {
|
|
32
27
|
const locale = slugToLocale(slug);
|
|
33
28
|
return { dir: localeToDir(locale), lang: localeToLang(locale), locale };
|
|
34
29
|
}
|
|
@@ -56,7 +51,7 @@ function localeToDir(locale: string | undefined): 'ltr' | 'rtl' {
|
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
export function slugToParam(slug: string): string | undefined {
|
|
59
|
-
return slug === 'index'
|
|
54
|
+
return slug === 'index' || slug === ''
|
|
60
55
|
? undefined
|
|
61
56
|
: slug.endsWith('/index')
|
|
62
57
|
? slug.replace('/index', '')
|
|
@@ -79,13 +74,16 @@ export function slugToPathname(slug: string): string {
|
|
|
79
74
|
* localizedSlug('en/home', undefined) // => 'home'
|
|
80
75
|
*/
|
|
81
76
|
export function localizedSlug(
|
|
82
|
-
slug:
|
|
77
|
+
slug: string,
|
|
83
78
|
locale: string | undefined
|
|
84
79
|
): string {
|
|
85
80
|
const slugLocale = slugToLocale(slug);
|
|
86
81
|
if (slugLocale === locale) return slug;
|
|
82
|
+
locale = locale || '';
|
|
87
83
|
if (slugLocale) {
|
|
88
|
-
return slug
|
|
84
|
+
return slug
|
|
85
|
+
.replace(slugLocale + '/', locale ? locale + '/' : '')
|
|
86
|
+
.replace(/\/$/, '');
|
|
89
87
|
}
|
|
90
|
-
return locale + '/' + slug;
|
|
88
|
+
return slug ? locale + '/' + slug : locale;
|
|
91
89
|
}
|
package/utils/user-config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'astro/zod';
|
|
2
2
|
import { parse as bcpParse, stringify as bcpStringify } from 'bcp-47';
|
|
3
3
|
import { HeadConfigSchema } from '../schemas/head';
|
|
4
|
+
import { LogoConfigSchema } from '../schemas/logo';
|
|
4
5
|
|
|
5
6
|
const LocaleSchema = z.object({
|
|
6
7
|
/** The label for this language to show in UI, e.g. `"English"`, `"العربية"`, or `"简体中文"`. */
|
|
@@ -101,6 +102,9 @@ const UserConfigSchema = z.object({
|
|
|
101
102
|
'Description metadata for your website. Can be used in page metadata.'
|
|
102
103
|
),
|
|
103
104
|
|
|
105
|
+
/** Set a logo image to show in the navigation bar alongside or instead of the site title. */
|
|
106
|
+
logo: LogoConfigSchema(),
|
|
107
|
+
|
|
104
108
|
/** Optional details about the social media accounts for this site. */
|
|
105
109
|
social: z
|
|
106
110
|
.object({
|
package/virtual.d.ts
CHANGED
|
@@ -7,3 +7,11 @@ declare module 'virtual:starlight/project-context' {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
declare module 'virtual:starlight/user-css' {}
|
|
10
|
+
|
|
11
|
+
declare module 'virtual:starlight/user-images' {
|
|
12
|
+
type ImageMetadata = import('astro').ImageMetadata;
|
|
13
|
+
export const logos: {
|
|
14
|
+
dark?: ImageMetadata;
|
|
15
|
+
light?: ImageMetadata;
|
|
16
|
+
};
|
|
17
|
+
}
|