@astrojs/starlight 0.8.1 → 0.9.1

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#647](https://github.com/withastro/starlight/pull/647) [`ea57726`](https://github.com/withastro/starlight/commit/ea5772655274a3900310cb700836fdd2f6dba7cd) Thanks [@bgmort](https://github.com/bgmort)! - Fix translated 404 pages not being excluded from search results
8
+
9
+ - [#667](https://github.com/withastro/starlight/pull/667) [`9828f73`](https://github.com/withastro/starlight/commit/9828f739b73e2f377c1450b9e11f0914722ee440) Thanks [@delucis](https://github.com/delucis)! - Break inline `<code>` across lines to avoid overflow
10
+
11
+ - [#642](https://github.com/withastro/starlight/pull/642) [`e623d92`](https://github.com/withastro/starlight/commit/e623d92c2fddc0ff5fe83d2554266885d683a906) Thanks [@fk](https://github.com/fk)! - Don't hard-code nav height in table of contents highlighting script
12
+
13
+ - [#676](https://github.com/withastro/starlight/pull/676) [`6419006`](https://github.com/withastro/starlight/commit/641900615aa9a9a128d6934e65a57ba89e503cfd) Thanks [@vedmalex](https://github.com/vedmalex)! - Upgrade and pin Pagefind to latest beta release.
14
+
15
+ - [#647](https://github.com/withastro/starlight/pull/647) [`ea57726`](https://github.com/withastro/starlight/commit/ea5772655274a3900310cb700836fdd2f6dba7cd) Thanks [@bgmort](https://github.com/bgmort)! - Add frontmatter option to exclude a page from Pagefind search results
16
+
17
+ ## 0.9.0
18
+
19
+ ### Minor Changes
20
+
21
+ - [#626](https://github.com/withastro/starlight/pull/626) [`5dd22b8`](https://github.com/withastro/starlight/commit/5dd22b875dc19a32c48692082fbd934e2b70da63) Thanks [@delucis](https://github.com/delucis)! - Throw an error for duplicate MDX or sitemap integrations
22
+
23
+ - [#615](https://github.com/withastro/starlight/pull/615) [`7b75b3e`](https://github.com/withastro/starlight/commit/7b75b3eb7e6f7870a0adef2d6534ff48309fdb0e) Thanks [@delucis](https://github.com/delucis)! - Bump minimum required Astro version to 3.0
24
+
25
+ ⚠️ **BREAKING CHANGE** Astro v2 is no longer supported. Make sure you [update Astro](https://docs.astro.build/en/guides/upgrade-to/v3/) and any other integrations at the same time as updating Starlight.
26
+
3
27
  ## 0.8.1
4
28
 
5
29
  ### Patch Changes
@@ -28,7 +28,7 @@ try {
28
28
  {
29
29
  date && (
30
30
  <p>
31
- {t('page.lastUpdated')}
31
+ {t('page.lastUpdated')}{' '}
32
32
  <time datetime={date.toISOString()}>
33
33
  {date.toLocaleDateString(lang, { dateStyle: 'medium' })}
34
34
  </time>
@@ -110,7 +110,7 @@ const pagefindTranslations = {
110
110
  new PagefindUI({
111
111
  element: '#starlight__search',
112
112
  baseUrl: import.meta.env.BASE_URL,
113
- bundlePath: import.meta.env.BASE_URL.replace(/\/$/, '') + '/_pagefind/',
113
+ bundlePath: import.meta.env.BASE_URL.replace(/\/$/, '') + '/pagefind/',
114
114
  showImages: false,
115
115
  translations,
116
116
  });
@@ -21,10 +21,13 @@ interface Props {
21
21
  >
22
22
  <span>{entry.label}</span>
23
23
  {entry.badge && (
24
- <Badge
25
- text={entry.badge.text}
26
- variant={entry.isCurrent ? 'outline' : entry.badge.variant}
27
- />
24
+ <>
25
+ {' '}
26
+ <Badge
27
+ text={entry.badge.text}
28
+ variant={entry.isCurrent ? 'outline' : entry.badge.variant}
29
+ />
30
+ </>
28
31
  )}
29
32
  </a>
30
33
  ) : (
@@ -122,7 +122,7 @@ const t = useTranslations(locale);
122
122
  }
123
123
 
124
124
  constructor() {
125
- super({ smallViewport: true });
125
+ super();
126
126
  const details = this.querySelector('details');
127
127
  if (!details) return;
128
128
  const closeToC = () => {
@@ -10,7 +10,7 @@ export class StarlightTOC extends HTMLElement {
10
10
  this._current = link;
11
11
  }
12
12
 
13
- constructor({ smallViewport = false } = {}) {
13
+ constructor() {
14
14
  super();
15
15
 
16
16
  /** All the links in the table of contents. */
@@ -68,19 +68,13 @@ export class StarlightTOC extends HTMLElement {
68
68
  // Also observe direct children of `.content` to include elements before
69
69
  // the first heading.
70
70
  const toObserve = document.querySelectorAll('main [id], main [id] ~ *, main .content > *');
71
- /** Start intersections at nav height + 2rem padding. */
72
- const top = (smallViewport ? 104 : 64) + 32;
73
- /** End intersections 1.5rem later. */
74
- const bottom = top + 24;
75
71
 
76
72
  let observer: IntersectionObserver | undefined;
77
- function observe() {
73
+ const observe = () => {
78
74
  if (observer) observer.disconnect();
79
- const height = document.documentElement.clientHeight;
80
- const rootMargin = `-${top}px 0% ${bottom - height}px`;
81
- observer = new IntersectionObserver(setCurrent, { rootMargin });
75
+ observer = new IntersectionObserver(setCurrent, { rootMargin: this.getRootMargin() });
82
76
  toObserve.forEach((h) => observer!.observe(h));
83
- }
77
+ };
84
78
  observe();
85
79
 
86
80
  const onIdle = window.requestIdleCallback || ((cb) => setTimeout(cb, 1));
@@ -92,6 +86,18 @@ export class StarlightTOC extends HTMLElement {
92
86
  timeout = setTimeout(() => onIdle(observe), 200);
93
87
  });
94
88
  }
89
+
90
+ private getRootMargin(): `-${number}px 0% ${number}px` {
91
+ const navBarHeight = document.querySelector('header')?.getBoundingClientRect().height || 0;
92
+ // `<summary>` only exists in mobile ToC, so will fall back to 0 in large viewport component.
93
+ const mobileTocHeight = this.querySelector('summary')?.getBoundingClientRect().height || 0;
94
+ /** Start intersections at nav height + 2rem padding. */
95
+ const top = navBarHeight + mobileTocHeight + 32;
96
+ /** End intersections 1.5rem later. */
97
+ const bottom = top + 24;
98
+ const height = document.documentElement.clientHeight;
99
+ return `-${top}px 0% ${bottom - height}px`;
100
+ }
95
101
  }
96
102
 
97
103
  customElements.define('starlight-toc', StarlightTOC);
package/index.ts CHANGED
@@ -7,7 +7,7 @@ import { starlightAsides } from './integrations/asides';
7
7
  import { starlightSitemap } from './integrations/sitemap';
8
8
  import { vitePluginStarlightUserConfig } from './integrations/virtual-user-config';
9
9
  import { errorMap } from './utils/error-map';
10
- import { StarlightConfigSchema, StarlightUserConfig } from './utils/user-config';
10
+ import { StarlightConfigSchema, type StarlightUserConfig } from './utils/user-config';
11
11
  import { rehypeRtlCodeSupport } from './integrations/code-rtl-support';
12
12
 
13
13
  export default function StarlightIntegration(opts: StarlightUserConfig): AstroIntegration[] {
@@ -45,22 +45,30 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn
45
45
  // Configure Shiki theme if the user is using the default github-dark theme.
46
46
  config.markdown.shikiConfig.theme !== 'github-dark' ? {} : { theme: 'css-variables' },
47
47
  },
48
- build: { inlineStylesheets: 'auto' },
49
- experimental: {
50
- assets: true,
51
- // @ts-ignore - Needed for older versions of Astro, but an error since astro@2.6.0
52
- inlineStylesheets: 'auto',
53
- },
48
+ scopedStyleStrategy: 'where',
54
49
  };
55
50
  updateConfig(newConfig);
56
51
  },
57
52
 
53
+ 'astro:config:done': ({ config }) => {
54
+ const integrations = config.integrations.map(({ name }) => name);
55
+ for (const builtin of ['@astrojs/mdx', '@astrojs/sitemap']) {
56
+ if (integrations.filter((name) => name === builtin).length > 1) {
57
+ throw new Error(
58
+ `Found more than one instance of ${builtin}.\n` +
59
+ `Starlight includes ${builtin} by default.\n` +
60
+ 'Please remove it from your integrations array in astro.config.mjs'
61
+ );
62
+ }
63
+ }
64
+ },
65
+
58
66
  'astro:build:done': ({ dir }) => {
59
67
  const targetDir = fileURLToPath(dir);
60
68
  const cwd = dirname(fileURLToPath(import.meta.url));
61
69
  const relativeDir = relative(cwd, targetDir);
62
70
  return new Promise<void>((resolve) => {
63
- spawn('npx', ['-y', 'pagefind', '--source', relativeDir], {
71
+ spawn('npx', ['-y', 'pagefind', '--site', relativeDir], {
64
72
  stdio: 'inherit',
65
73
  shell: true,
66
74
  cwd,
@@ -1,5 +1,5 @@
1
1
  import type { AstroUserConfig } from 'astro';
2
- import { h as _h, s as _s, Properties } from 'hastscript';
2
+ import { h as _h, s as _s, type Properties } from 'hastscript';
3
3
  import type { Paragraph as P, Root } from 'mdast';
4
4
  import remarkDirective from 'remark-directive';
5
5
  import type { Plugin, Transformer } from 'unified';
@@ -1,4 +1,4 @@
1
- import sitemap, { SitemapOptions } from '@astrojs/sitemap';
1
+ import sitemap, { type SitemapOptions } from '@astrojs/sitemap';
2
2
  import type { StarlightConfig } from '../types';
3
3
 
4
4
  /**
package/layout/Page.astro CHANGED
@@ -45,6 +45,8 @@ const tocConfig = !hasSidebar
45
45
  : config.tableOfContents;
46
46
  const hasToC = Boolean(tocConfig);
47
47
  const hasHero = Boolean(entry.data.hero);
48
+ const pagefindEnabled =
49
+ entry.slug !== '404' && !entry.slug.endsWith('/404') && entry.data.pagefind !== false;
48
50
  ---
49
51
 
50
52
  <html
@@ -91,7 +93,7 @@ const hasHero = Boolean(entry.data.hero);
91
93
  {hasSidebar && <Sidebar slot="sidebar" {sidebar} {locale} />}
92
94
  <TwoColumnContent {hasToC}>
93
95
  <RightSidebar slot="right-sidebar" {headings} {locale} {tocConfig} />
94
- <main data-pagefind-body={entry.slug !== '404'} lang={entryMeta.lang} dir={entryMeta.dir}>
96
+ <main data-pagefind-body={pagefindEnabled} lang={entryMeta.lang} dir={entryMeta.dir}>
95
97
  {/* TODO: Revisit how this logic flows. */}
96
98
  {entry.data.banner && <Banner {...entry.data.banner} />}
97
99
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -28,24 +28,24 @@
28
28
  "./404.astro": "./404.astro"
29
29
  },
30
30
  "peerDependencies": {
31
- "astro": "^2.5.0"
31
+ "astro": "^3.0.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^18.16.19",
35
35
  "@vitest/coverage-v8": "^0.33.0",
36
- "astro": "^2.10.5",
36
+ "astro": "^3.0.6",
37
37
  "vitest": "^0.33.0"
38
38
  },
39
39
  "dependencies": {
40
- "@astrojs/mdx": "^0.19.7",
41
- "@astrojs/sitemap": "^1.3.3",
42
- "@pagefind/default-ui": "^1.0.0-alpha.5",
40
+ "@astrojs/mdx": "^1.0.0",
41
+ "@astrojs/sitemap": "^3.0.0",
42
+ "@pagefind/default-ui": "1.0.0-beta.2",
43
43
  "@types/mdast": "^3.0.11",
44
44
  "bcp-47": "^2.1.0",
45
45
  "execa": "^7.1.1",
46
46
  "hast-util-select": "^5.0.5",
47
47
  "hastscript": "^7.2.0",
48
- "pagefind": "^1.0.0-alpha.5",
48
+ "pagefind": "1.0.0-beta.2",
49
49
  "rehype": "^12.0.1",
50
50
  "remark-directive": "^2.0.1",
51
51
  "unified": "^10.1.2",
package/schema.ts CHANGED
@@ -165,5 +165,8 @@ export function docsSchema() {
165
165
  content: z.string(),
166
166
  })
167
167
  .optional(),
168
+
169
+ /** Pagefind indexing for this page - set to false to disable. */
170
+ pagefind: z.boolean().default(true),
168
171
  });
169
172
  }
package/style/reset.css CHANGED
@@ -38,7 +38,8 @@ h2,
38
38
  h3,
39
39
  h4,
40
40
  h5,
41
- h6 {
41
+ h6,
42
+ code {
42
43
  overflow-wrap: break-word;
43
44
  }
44
45