@astrojs/starlight 0.0.7 → 0.0.8

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,21 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
9
+ - [#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
10
+
11
+ - [#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
12
+
13
+ - [#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.
14
+
15
+ - [#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
16
+
17
+ - [#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
18
+
3
19
  ## 0.0.7
4
20
 
5
21
  ### 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
 
@@ -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,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);
@@ -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.8",
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
  }