@astrojs/starlight 0.10.0 → 0.10.2

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,27 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.10.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#735](https://github.com/withastro/starlight/pull/735) [`2da8692`](https://github.com/withastro/starlight/commit/2da86929c8041f6585790c3baf1cba42220650cc) Thanks [@delucis](https://github.com/delucis)! - Use Starlight font custom property in Pagefind modal
8
+
9
+ - [#735](https://github.com/withastro/starlight/pull/735) [`2da8692`](https://github.com/withastro/starlight/commit/2da86929c8041f6585790c3baf1cba42220650cc) Thanks [@delucis](https://github.com/delucis)! - Fix RTL styling in Pagefind modal
10
+
11
+ - [#739](https://github.com/withastro/starlight/pull/739) [`a9de4a7`](https://github.com/withastro/starlight/commit/a9de4a7dcf9ec8c5c801e8a6cbb0d7faf2c34db7) Thanks [@radenpioneer](https://github.com/radenpioneer)! - Add Indonesian UI translation
12
+
13
+ - [#747](https://github.com/withastro/starlight/pull/747) [`7589515`](https://github.com/withastro/starlight/commit/75895154b11cf9368d4d6b45647b156ce32a88f0) Thanks [@nirtamir2](https://github.com/nirtamir2)! - Add Hebrew UI translations
14
+
15
+ ## 0.10.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#726](https://github.com/withastro/starlight/pull/726) [`f3157c6`](https://github.com/withastro/starlight/commit/f3157c6065943af39995b6dbae5f63cf424bd9a3) Thanks [@delucis](https://github.com/delucis)! - Fix a rare bug in table of contents when handling headings that increase by more than one level on a page.
20
+
21
+ - [#729](https://github.com/withastro/starlight/pull/729) [`80c6ab1`](https://github.com/withastro/starlight/commit/80c6ab1c1ec48805e74c53b615a78d65127eeacb) Thanks [@delucis](https://github.com/delucis)! - Upgrade Pagefind to v1.0.3
22
+
23
+ - [#715](https://github.com/withastro/starlight/pull/715) [`e726155`](https://github.com/withastro/starlight/commit/e7261559f2539a0ceefd36a28e4fbbc17f5970b8) Thanks [@itsmatteomanf](https://github.com/itsmatteomanf)! - feat: prevent scroll on body when search is open
24
+
3
25
  ## 0.10.0
4
26
 
5
27
  ### Minor Changes
@@ -72,20 +72,23 @@ const pagefindTranslations = {
72
72
 
73
73
  const openModal = (event?: MouseEvent) => {
74
74
  dialog.showModal();
75
+ document.body.toggleAttribute('data-search-modal-open', true);
75
76
  this.querySelector('input')?.focus();
76
77
  event?.stopPropagation();
77
78
  window.addEventListener('click', onClick);
78
79
  };
79
80
 
80
- const closeModal = () => {
81
- dialog.close();
82
- window.removeEventListener('click', onClick);
83
- };
81
+ const closeModal = () => dialog.close();
84
82
 
85
83
  openBtn.addEventListener('click', openModal);
86
84
  openBtn.disabled = false;
87
85
  closeBtn.addEventListener('click', closeModal);
88
86
 
87
+ dialog.addEventListener('close', () => {
88
+ document.body.toggleAttribute('data-search-modal-open', false);
89
+ window.removeEventListener('click', onClick);
90
+ });
91
+
89
92
  // Listen for `/` and `cmd + k` keyboard shortcuts.
90
93
  window.addEventListener('keydown', (e) => {
91
94
  const isInput =
@@ -202,6 +205,7 @@ const pagefindTranslations = {
202
205
  #starlight__search {
203
206
  --pagefind-ui-primary: var(--sl-color-accent-light);
204
207
  --pagefind-ui-text: var(--sl-color-gray-2);
208
+ --pagefind-ui-font: var(--__sl-font);
205
209
  --pagefind-ui-background: var(--sl-color-black);
206
210
  --pagefind-ui-border: var(--sl-color-gray-5);
207
211
  --pagefind-ui-border-width: 1px;
@@ -230,6 +234,10 @@ const pagefindTranslations = {
230
234
  </style>
231
235
 
232
236
  <style is:global>
237
+ [data-search-modal-open] {
238
+ overflow: hidden;
239
+ }
240
+
233
241
  #starlight__search {
234
242
  --sl-search-result-spacing: calc(1.25rem * var(--pagefind-ui-scale));
235
243
  --sl-search-result-pad-inline-start: calc(3.75rem * var(--pagefind-ui-scale));
@@ -383,6 +391,12 @@ const pagefindTranslations = {
383
391
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 16 16'%3E%3Cpath d='M8 0v12m6 0H8'/%3E%3C/svg%3E");
384
392
  }
385
393
 
394
+ /* Flip page and tree icons around the vertical axis when in an RTL layout. */
395
+ [dir='rtl'] .pagefind-ui__result-title::before,
396
+ [dir='rtl'] .pagefind-ui__result-nested::before {
397
+ transform: matrix(-1, 0, 0, 1, 0, 0);
398
+ }
399
+
386
400
  #starlight__search .pagefind-ui__result-link::after {
387
401
  content: '';
388
402
  position: absolute;
@@ -4,52 +4,29 @@ export interface TocItem extends MarkdownHeading {
4
4
  children: TocItem[];
5
5
  }
6
6
 
7
- function diveChildren(item: TocItem, depth: number): TocItem[] {
8
- if (depth === 1) {
9
- return item.children;
10
- } else if (item.children.length > 0) {
11
- return diveChildren(item.children.at(-1)!, depth - 1);
12
- } else {
13
- return [];
14
- }
15
- }
16
-
17
7
  interface TocOpts {
18
8
  minHeadingLevel: number;
19
9
  maxHeadingLevel: number;
20
- title?: string;
10
+ title: string;
21
11
  }
22
12
 
13
+ /** Convert the flat headings array generated by Astro into a nested tree structure. */
23
14
  export function generateToC(
24
15
  headings: MarkdownHeading[],
25
- { minHeadingLevel, maxHeadingLevel, title = 'Overview' }: TocOpts
16
+ { minHeadingLevel, maxHeadingLevel, title }: TocOpts
26
17
  ) {
27
- const overview = { depth: 2, slug: '_top', text: title };
28
- headings = [
29
- overview,
30
- ...headings.filter(({ depth }) => depth >= minHeadingLevel && depth <= maxHeadingLevel),
31
- ];
32
- const toc: Array<TocItem> = [];
18
+ headings = headings.filter(({ depth }) => depth >= minHeadingLevel && depth <= maxHeadingLevel);
19
+ const toc: Array<TocItem> = [{ depth: 2, slug: '_top', text: title, children: [] }];
20
+ for (const heading of headings) injectChild(toc, { ...heading, children: [] });
21
+ return toc;
22
+ }
33
23
 
34
- for (const heading of headings) {
35
- if (toc.length === 0) {
36
- toc.push({ ...heading, children: [] });
37
- } else {
38
- const lastItemInToc = toc.at(-1)!;
39
- if (heading.depth < lastItemInToc.depth) {
40
- throw new Error(`Orphan heading found: ${heading.text}.`);
41
- }
42
- if (heading.depth === lastItemInToc.depth) {
43
- // same depth
44
- toc.push({ ...heading, children: [] });
45
- } else {
46
- // higher depth
47
- // push into children, or children's children alike
48
- const gap = heading.depth - lastItemInToc.depth;
49
- const target = diveChildren(lastItemInToc, gap);
50
- target.push({ ...heading, children: [] });
51
- }
52
- }
24
+ /** Inject a ToC entry as deep in the tree as its `depth` property requires. */
25
+ function injectChild(items: TocItem[], item: TocItem): void {
26
+ const lastItem = items.at(-1);
27
+ if (!lastItem || lastItem.depth >= item.depth) {
28
+ items.push(item);
29
+ } else {
30
+ return injectChild(lastItem.children, item);
53
31
  }
54
- return toc;
55
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -39,13 +39,13 @@
39
39
  "dependencies": {
40
40
  "@astrojs/mdx": "^1.0.0",
41
41
  "@astrojs/sitemap": "^3.0.0",
42
- "@pagefind/default-ui": "^1.0.2",
42
+ "@pagefind/default-ui": "^1.0.3",
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.2",
48
+ "pagefind": "^1.0.3",
49
49
  "rehype": "^12.0.1",
50
50
  "remark-directive": "^2.0.1",
51
51
  "unified": "^10.1.2",
@@ -0,0 +1,22 @@
1
+ {
2
+ "skipLink.label": "דלגו לתוכן",
3
+ "search.label": "חיפוש",
4
+ "search.shortcutLabel": "(לחצו / כדי לחפש)",
5
+ "search.cancelLabel": "ביטול",
6
+ "search.devWarning": "החיפוש זמין רק בסביבת ייצור. \nנסו לבנות ולהציג תצוגה מקדימה של האתר כדי לבדוק אותו באופן מקומי.",
7
+ "themeSelect.accessibleLabel": "בחרו פרופיל צבע",
8
+ "themeSelect.dark": "כהה",
9
+ "themeSelect.light": "בהיר",
10
+ "themeSelect.auto": "מערכת",
11
+ "languageSelect.accessibleLabel": "בחרו שפה",
12
+ "menuButton.accessibleLabel": "תפריט",
13
+ "sidebarNav.accessibleLabel": "ראשי",
14
+ "tableOfContents.onThisPage": "בדף זה",
15
+ "tableOfContents.overview": "סקירה כללית",
16
+ "i18n.untranslatedContent": "תוכן זה אינו זמין עדיין בשפה שלך.",
17
+ "page.editLink": "ערכו דף",
18
+ "page.lastUpdated": "עדכון אחרון:",
19
+ "page.previousLink": "הקודם",
20
+ "page.nextLink": "הבא",
21
+ "404.text": "הדף לא נמצא. אנא בדקו את כתובת האתר או נסו להשתמש בסרגל החיפוש."
22
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "skipLink.label": "Lewati ke konten",
3
+ "search.label": "Pencarian",
4
+ "search.shortcutLabel": "(Tekan / untuk mencari)",
5
+ "search.cancelLabel": "Batal",
6
+ "search.devWarning": "Pencarian hanya tersedia pada build produksi. \nLakukan proses build dan pratinjau situs Anda sebelum mencoba di lingkungan lokal.",
7
+ "themeSelect.accessibleLabel": "Pilih tema",
8
+ "themeSelect.dark": "Gelap",
9
+ "themeSelect.light": "Terang",
10
+ "themeSelect.auto": "Otomatis",
11
+ "languageSelect.accessibleLabel": "Pilih Bahasa",
12
+ "menuButton.accessibleLabel": "Menu",
13
+ "sidebarNav.accessibleLabel": "Utama",
14
+ "tableOfContents.onThisPage": "Di halaman ini",
15
+ "tableOfContents.overview": "Selayang Pandang",
16
+ "i18n.untranslatedContent": "Konten ini belum tersedia dalam bahasa Anda.",
17
+ "page.editLink": "Edit halaman",
18
+ "page.lastUpdated": "Terakhir diperbaharui:",
19
+ "page.previousLink": "Sebelumnya",
20
+ "page.nextLink": "Selanjutnya",
21
+ "404.text": "Halaman tidak ditemukan. Cek kembali kolom URL atau gunakan fitur pencarian."
22
+ }
@@ -7,6 +7,8 @@ import ja from './ja.json';
7
7
  import pt from './pt.json';
8
8
  import fa from './fa.json';
9
9
  import fr from './fr.json';
10
+ import he from './he.json';
11
+ import id from './id.json';
10
12
  import it from './it.json';
11
13
  import nl from './nl.json';
12
14
  import da from './da.json';
@@ -21,7 +23,26 @@ import ru from './ru.json';
21
23
  const { parse } = builtinI18nSchema();
22
24
 
23
25
  export default Object.fromEntries(
24
- Object.entries({ cs, en, es, de, ja, pt, fa, fr, it, nl, da, tr, ar, nb, zh, ko, sv, ru }).map(
25
- ([key, dict]) => [key, parse(dict)]
26
- )
26
+ Object.entries({
27
+ cs,
28
+ en,
29
+ es,
30
+ de,
31
+ ja,
32
+ pt,
33
+ fa,
34
+ fr,
35
+ he,
36
+ id,
37
+ it,
38
+ nl,
39
+ da,
40
+ tr,
41
+ ar,
42
+ nb,
43
+ zh,
44
+ ko,
45
+ sv,
46
+ ru,
47
+ }).map(([key, dict]) => [key, parse(dict)])
27
48
  );