@astrojs/starlight 0.0.7 → 0.0.9

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/404.astro CHANGED
@@ -17,6 +17,7 @@ import ThemeProvider from './components/ThemeProvider.astro';
17
17
 
18
18
  // Important that this is the last import so it can override built-in styles.
19
19
  import 'virtual:starlight/user-css';
20
+ import { withBase } from './utils/base';
20
21
 
21
22
  const { lang = 'en', dir = 'ltr', locale } = config.defaultLocale || {};
22
23
  ---
@@ -37,7 +38,7 @@ const { lang = 'en', dir = 'ltr', locale } = config.defaultLocale || {};
37
38
  <p>Houston, we have a problem.</p>
38
39
  <p>
39
40
  We couldn’t find that link. Check the address or <a
40
- href={import.meta.env.BASE_URL}>head back home</a
41
+ href={withBase('/')}>head back home</a
41
42
  >.
42
43
  </p>
43
44
  </MarkdownContent>
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#72](https://github.com/withastro/starlight/pull/72) [`3dc1d0c`](https://github.com/withastro/starlight/commit/3dc1d0c342c6db4e30b016035fa446101b1805a2) Thanks [@delucis](https://github.com/delucis)! - Fix vertical alignment of social icons in site header
8
+
9
+ - [#63](https://github.com/withastro/starlight/pull/63) [`823e351`](https://github.com/withastro/starlight/commit/823e351e1c1fc68ca3c20ab35c9a7d9b13760a70) Thanks [@liruifengv](https://github.com/liruifengv)! - Make sidebar groups to collapsible
10
+
11
+ - [#72](https://github.com/withastro/starlight/pull/72) [`3dc1d0c`](https://github.com/withastro/starlight/commit/3dc1d0c342c6db4e30b016035fa446101b1805a2) Thanks [@delucis](https://github.com/delucis)! - Fix image aspect ratio in Markdown content
12
+
13
+ ## 0.0.8
14
+
15
+ ### Patch Changes
16
+
17
+ - [#62](https://github.com/withastro/starlight/pull/62) [`a91191e`](https://github.com/withastro/starlight/commit/a91191e8308ffa746a3eadeea61e39412f32f926) Thanks [@delucis](https://github.com/delucis)! - Make `base` support consistent, including when `trailingSlash: 'never'` is set.
18
+
19
+ - [#61](https://github.com/withastro/starlight/pull/61) [`608f34c`](https://github.com/withastro/starlight/commit/608f34cbbe485c39730f33828971397f9c8a3534) Thanks [@liruifengv](https://github.com/liruifengv)! - Fix toc headingsObserver rootMargin
20
+
21
+ - [#66](https://github.com/withastro/starlight/pull/66) [`9ca67d8`](https://github.com/withastro/starlight/commit/9ca67d8984f76c22e5411d7352aa8e0bd4514f42) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Make site title width fit the content
22
+
23
+ - [#64](https://github.com/withastro/starlight/pull/64) [`4460e55`](https://github.com/withastro/starlight/commit/4460e55de210fd9a23a762fe76f5c32297d68d76) Thanks [@delucis](https://github.com/delucis)! - Fix table of contents intersection observer for all possible viewport sizes.
24
+
25
+ - [#67](https://github.com/withastro/starlight/pull/67) [`38c2c1f`](https://github.com/withastro/starlight/commit/38c2c1f1ed25d6efe6ab2637ca2d9fbcdafcd240) Thanks [@TheOtterlord](https://github.com/TheOtterlord)! - Fix background color on select component
26
+
27
+ - [#57](https://github.com/withastro/starlight/pull/57) [`5b6cccb`](https://github.com/withastro/starlight/commit/5b6cccb7f9ee5810c75fbbb45496e2a1d022f7dd) Thanks [@BryceRussell](https://github.com/BryceRussell)! - Update site title link to include locale
28
+
3
29
  ## 0.0.7
4
30
 
5
31
  ### Patch Changes
@@ -4,6 +4,7 @@ import config from 'virtual:starlight/user-config';
4
4
  import type { HeadConfigSchema } from '../schemas/head';
5
5
  import { createHead } from '../utils/head';
6
6
  import { localizedUrl } from '../utils/localizedUrl';
7
+ import { withBase } from '../utils/base';
7
8
 
8
9
  interface Props {
9
10
  data: CollectionEntry<'docs'>['data'];
@@ -32,7 +33,7 @@ const headDefaults: z.input<ReturnType<typeof HeadConfigSchema>> = [
32
33
  tag: 'link',
33
34
  attrs: {
34
35
  rel: 'shortcut icon',
35
- href: import.meta.env.BASE_URL + 'favicon.svg',
36
+ href: withBase('/favicon.svg'),
36
37
  type: 'image/svg+xml',
37
38
  },
38
39
  },
@@ -80,7 +81,7 @@ if (Astro.site) {
80
81
  tag: 'link',
81
82
  attrs: {
82
83
  rel: 'sitemap',
83
- href: import.meta.env.BASE_URL + 'sitemap-index.xml',
84
+ href: withBase('/sitemap-index.xml'),
84
85
  },
85
86
  });
86
87
  }
@@ -8,15 +8,17 @@ import ThemeSelect from './ThemeSelect.astro';
8
8
  interface Props {
9
9
  locale: string | undefined;
10
10
  }
11
+
12
+ const { locale } = Astro.props
11
13
  ---
12
14
 
13
15
  <div class="header">
14
- <SiteTitle />
16
+ <SiteTitle {locale} />
15
17
  <Search />
16
18
  <div class="hidden md:flex right-group">
17
19
  <SocialIcons />
18
20
  <ThemeSelect />
19
- <LanguageSelect locale={Astro.props.locale} />
21
+ <LanguageSelect {locale}/>
20
22
  </div>
21
23
  </div>
22
24
 
@@ -44,6 +44,7 @@
44
44
  .content :global(:is(img, picture, video, canvas, svg, iframe)) {
45
45
  display: block;
46
46
  max-width: 100%;
47
+ height: auto;
47
48
  }
48
49
 
49
50
  .content :global(h1) {
@@ -72,6 +72,10 @@ interface Props {
72
72
  appearance: none;
73
73
  }
74
74
 
75
+ option {
76
+ background-color: var(--sl-color-bg-nav);
77
+ }
78
+
75
79
  @media (min-width: 50rem) {
76
80
  select {
77
81
  font-size: var(--sl-text-sm);
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  import type { SidebarEntry } from '../utils/navigation';
3
+ import Icon from './Icon.astro';
3
4
 
4
5
  interface Props {
5
6
  sublist: SidebarEntry[];
@@ -15,10 +16,13 @@ interface Props {
15
16
  {entry.label}
16
17
  </a>
17
18
  ) : (
18
- <>
19
- <h2>{entry.label}</h2>
19
+ <details open>
20
+ <summary>
21
+ <h2>{entry.label}</h2>
22
+ <Icon name="right-caret" class="caret" size="1.25rem" />
23
+ </summary>
20
24
  <Astro.self sublist={entry.entries} />
21
- </>
25
+ </details>
22
26
  )}
23
27
  </li>
24
28
  ))
@@ -36,13 +40,35 @@ interface Props {
36
40
  font-size: var(--sl-text-lg);
37
41
  font-weight: 600;
38
42
  color: var(--sl-color-white);
39
- padding-inline: var(--sl-sidebar-item-padding-inline);
40
43
  }
41
44
 
42
45
  .sidebar-group + .sidebar-group {
43
46
  margin-top: 0.75rem;
44
47
  }
45
48
 
49
+ summary {
50
+ display: flex;
51
+ align-items: center;
52
+ justify-content: space-between;
53
+ padding-inline: var(--sl-sidebar-item-padding-inline);
54
+ cursor: pointer;
55
+ user-select: none;
56
+ }
57
+ summary::marker,
58
+ summary::-webkit-details-marker {
59
+ display: none;
60
+ }
61
+
62
+ .caret {
63
+ transition: transform 0.2s ease-in-out;
64
+ }
65
+ :global([dir='rtl']) .caret {
66
+ transform: rotateZ(180deg);
67
+ }
68
+ [open] .caret {
69
+ transform: rotateZ(90deg);
70
+ }
71
+
46
72
  a {
47
73
  display: block;
48
74
  border-radius: 0.25rem;
@@ -1,6 +1,11 @@
1
1
  ---
2
2
  import { logos } from 'virtual:starlight/user-images';
3
3
  import config from 'virtual:starlight/user-config';
4
+ import { withBase } from '../utils/base';
5
+
6
+ interface Props {
7
+ locale: string | undefined;
8
+ }
4
9
 
5
10
  if (config.logo) {
6
11
  let err: string | undefined;
@@ -17,9 +22,11 @@ if (config.logo) {
17
22
  }
18
23
  if (err) throw new Error(err);
19
24
  }
25
+
26
+ const href = withBase(Astro.props.locale || '/');
20
27
  ---
21
28
 
22
- <a href={import.meta.env.BASE_URL} class="site-title flex">
29
+ <a {href} class="site-title flex">
23
30
  {
24
31
  config.logo && logos.dark && (
25
32
  <>
@@ -50,6 +57,7 @@ if (config.logo) {
50
57
 
51
58
  <style>
52
59
  .site-title {
60
+ justify-self: flex-start;
53
61
  align-items: center;
54
62
  gap: var(--sl-nav-gap);
55
63
  font-size: var(--sl-text-h4);
@@ -32,6 +32,7 @@ const links = Object.entries(config.social || {}).filter(([, url]) =>
32
32
 
33
33
  <style>
34
34
  a {
35
+ display: flex;
35
36
  color: var(--sl-color-text-accent);
36
37
  }
37
38
  a:hover {
@@ -121,7 +121,7 @@ const toc = generateToC(Astro.props.headings, config.tableOfContents);
121
121
  }
122
122
 
123
123
  constructor() {
124
- super();
124
+ super({ smallViewport: true });
125
125
  const details = this.querySelector('details');
126
126
  if (!details) return;
127
127
  const closeToC = () => {
@@ -12,7 +12,7 @@ export class StarlightTOC extends HTMLElement {
12
12
  this._current = link;
13
13
  }
14
14
 
15
- constructor() {
15
+ constructor({ smallViewport = false } = {}) {
16
16
  super();
17
17
 
18
18
  /** All the links in the table of contents. */
@@ -68,17 +68,35 @@ export class StarlightTOC extends HTMLElement {
68
68
  }
69
69
  };
70
70
 
71
- const headingsObserver = new IntersectionObserver(setCurrent, {
72
- rootMargin: '5% 0% -85%',
73
- });
74
-
75
71
  // Observe elements with an `id` (most likely headings) and their siblings.
76
72
  // Also observe direct children of `.content` to include elements before
77
73
  // the first heading.
78
74
  const toObserve = document.querySelectorAll(
79
75
  'main [id], main [id] ~ *, main .content > *'
80
76
  );
81
- toObserve.forEach((h) => headingsObserver.observe(h));
77
+ /** Start intersections at nav height + 2rem padding. */
78
+ const top = (smallViewport ? 104 : 64) + 32;
79
+ /** End intersections 1.5rem later. */
80
+ const bottom = top + 24;
81
+
82
+ let observer: IntersectionObserver | undefined;
83
+ function observe() {
84
+ if (observer) observer.disconnect();
85
+ const height = document.documentElement.clientHeight;
86
+ const rootMargin = `-${top}px 0% ${bottom - height}px`;
87
+ observer = new IntersectionObserver(setCurrent, { rootMargin });
88
+ toObserve.forEach((h) => observer!.observe(h));
89
+ }
90
+ observe();
91
+
92
+ const onIdle = window.requestIdleCallback || ((cb) => setTimeout(cb, 1));
93
+ let timeout: NodeJS.Timeout;
94
+ window.addEventListener('resize', () => {
95
+ // Disable intersection observer while window is resizing.
96
+ if (observer) observer.disconnect();
97
+ clearTimeout(timeout);
98
+ timeout = setTimeout(() => onIdle(observe), 200);
99
+ });
82
100
  }
83
101
  }
84
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
package/utils/base.ts ADDED
@@ -0,0 +1,14 @@
1
+ const base = stripTrailingSlash(import.meta.env.BASE_URL);
2
+
3
+ /** Get the a root-relative URL path with the site’s `base` prefixed. */
4
+ export function withBase(path: string) {
5
+ path = stripLeadingSlash(stripTrailingSlash(path));
6
+ return path ? base + '/' + path + '/' : base + '/';
7
+ }
8
+
9
+ function stripLeadingSlash(path: string) {
10
+ return path.replace(/^\//, '');
11
+ }
12
+ function stripTrailingSlash(path: string) {
13
+ return path.replace(/\/$/, '');
14
+ }
@@ -1,7 +1,8 @@
1
1
  import { basename, dirname } from 'node:path';
2
2
  import config from 'virtual:starlight/user-config';
3
- import { slugToPathname } from './slugs';
3
+ import { withBase } from './base';
4
4
  import { Route, getLocaleRoutes, routes } from './routing';
5
+ import { slugToPathname } from './slugs';
5
6
  import type {
6
7
  AutoSidebarGroup,
7
8
  SidebarItem,
@@ -100,12 +101,7 @@ function linkFromConfig(
100
101
 
101
102
  /** Create a link entry. */
102
103
  function makeLink(href: string, label: string, currentPathname: string): Link {
103
- if (!isAbsolute(href)) {
104
- href = ensureLeadingAndTrailingSlashes(href);
105
- /** Base URL with trailing `/` stripped. */
106
- const base = import.meta.env.BASE_URL.replace(/\/$/, '');
107
- if (base) href = base + href;
108
- }
104
+ if (!isAbsolute(href)) href = withBase(href);
109
105
  const isCurrent = href === currentPathname;
110
106
  return { type: 'link', label, href, isCurrent };
111
107
  }