Skip to content

Commit cf9f93c

Browse files
authored
Migrate Docs to Starlight (withastro#4266)
Co-authored-by: Genteure <[email protected]> Co-authored-by: HiDeoo <[email protected]> Co-authored-by: Sergio A. Arevalo Soria <[email protected]> Co-authored-by: Atharva Pise <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Luiz Ferraz <[email protected]> Co-authored-by: Mark Peck <[email protected]> Co-authored-by: Vitor Ayres <[email protected]> Co-authored-by: Lucid Jeon <[email protected]> Co-authored-by: Elian <[email protected]> Co-authored-by: Yan Thomas <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]> Co-authored-by: Kevin Zuniga Cuellar <[email protected]> Co-authored-by: hippotastic <[email protected]> Co-authored-by: Voxel <[email protected]> @tracker-major:./src/content/docs/en/getting-started.mdx;
1 parent ace1a42 commit cf9f93c

File tree

187 files changed

+3646
-8195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+3646
-8195
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,3 @@ jobs:
6666

6767
- name: Run Check
6868
run: pnpm run lint:linkcheck
69-
unitTest:
70-
name: Check for code issues with Vitest
71-
runs-on: ubuntu-latest
72-
steps:
73-
- name: Checkout
74-
uses: actions/checkout@v3
75-
76-
- name: Install Tools & Dependencies
77-
uses: ./.github/actions/install
78-
79-
- name: Run Check
80-
run: pnpm run test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ sandbox.config.json
3535

3636
# Cached requests
3737
.cache
38+
**/_fonts/brand/

.prettierrc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
"tabWidth": 2,
66
"trailingComma": "es5",
77
"useTabs": true,
8+
"plugins": ["prettier-plugin-astro"],
89
"overrides": [
910
{
1011
"files": [".*", "*.json", "*.md", "*.mdx", "*.toml", "*.yml"],
1112
"options": {
1213
"useTabs": false
1314
}
14-
},
15-
{
16-
"files": ["**/*.astro"],
17-
"options": {
18-
"parser": "astro"
19-
}
2015
}
2116
]
2217
}

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

astro.config.ts

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,75 @@
1-
import mdx from '@astrojs/mdx';
2-
import preact from '@astrojs/preact';
3-
import { defineConfig } from 'astro/config';
1+
import starlight from '@astrojs/starlight';
2+
import { defineConfig, sharpImageService } from 'astro/config';
3+
import { makeLocalesConfig } from './config/locales';
4+
import { makeSidebar } from './config/sidebar';
45

5-
import AutoImport from 'astro-auto-import';
6-
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
76
import rehypeSlug from 'rehype-slug';
87
import remarkSmartypants from 'remark-smartypants';
98

10-
import { asideAutoImport, astroAsides } from './integrations/astro-asides';
11-
import { astroDocsExpressiveCode } from './integrations/expressive-code';
12-
import { sitemap } from './integrations/sitemap';
13-
import { autolinkConfig } from './plugins/rehype-autolink-config';
14-
import { rehypei18nAutolinkHeadings } from './plugins/rehype-i18n-autolink-headings';
159
import { rehypeOptimizeStatic } from './plugins/rehype-optimize-static';
1610
import { rehypeTasklistEnhancer } from './plugins/rehype-tasklist-enhancer';
1711
import { remarkFallbackLang } from './plugins/remark-fallback-lang';
12+
import { sitemap } from './integrations/sitemap';
13+
14+
/* https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables */
15+
const VERCEL_PREVIEW_SITE =
16+
process.env.VERCEL_ENV !== 'production' &&
17+
process.env.VERCEL_URL &&
18+
`https://${process.env.VERCEL_URL}`;
19+
20+
const site = VERCEL_PREVIEW_SITE || 'https://docs.astro.build/';
1821

1922
// https://astro.build/config
2023
export default defineConfig({
21-
site: 'https://docs.astro.build/',
24+
site,
2225
integrations: [
23-
AutoImport({
24-
imports: [asideAutoImport],
26+
starlight({
27+
title: 'Docs',
28+
customCss: ['./src/styles/custom.css'],
29+
logo: {
30+
light: './src/assets/astro-logo-light.svg',
31+
dark: './src/assets/astro-logo-dark.svg',
32+
alt: 'Astro',
33+
},
34+
components: {
35+
EditLink: './src/components/starlight/EditLink.astro',
36+
Head: './src/components/starlight/Head.astro',
37+
Hero: './src/components/starlight/Hero.astro',
38+
MarkdownContent: './src/components/starlight/MarkdownContent.astro',
39+
MobileTableOfContents: './src/components/starlight/MobileTableOfContents.astro',
40+
TableOfContents: './src/components/starlight/TableOfContents.astro',
41+
PageSidebar: './src/components/starlight/PageSidebar.astro',
42+
Pagination: './src/components/starlight/Pagination.astro',
43+
SiteTitle: './src/components/starlight/SiteTitle.astro',
44+
Search: './src/components/starlight/Search.astro',
45+
Sidebar: './src/components/starlight/Sidebar.astro',
46+
},
47+
editLink: {
48+
baseUrl: 'https://github.com/withastro/docs/edit/main',
49+
},
50+
defaultLocale: 'en',
51+
locales: makeLocalesConfig(),
52+
sidebar: makeSidebar(),
53+
social: {
54+
github: 'https://github.com/withastro/astro',
55+
discord: 'https://astro.build/chat',
56+
},
57+
pagefind: false,
58+
head: [
59+
// Add ICO favicon fallback for Safari.
60+
{
61+
tag: 'link',
62+
attrs: {
63+
rel: 'icon',
64+
href: '/favicon.ico',
65+
sizes: '32x32',
66+
},
67+
},
68+
],
2569
}),
26-
preact({ compat: true }),
2770
sitemap(),
28-
astroAsides(),
29-
astroDocsExpressiveCode(),
30-
mdx(),
3171
],
72+
trailingSlash: 'always',
3273
scopedStyleStrategy: 'where',
3374
compressHTML: false,
3475
markdown: {
@@ -41,14 +82,14 @@ export default defineConfig({
4182
],
4283
rehypePlugins: [
4384
rehypeSlug,
44-
// This adds links to headings
45-
[rehypeAutolinkHeadings, autolinkConfig],
4685
// Tweak GFM task list syntax
4786
rehypeTasklistEnhancer(),
48-
// Translates the autolink headings anchors
49-
rehypei18nAutolinkHeadings(),
5087
// Collapse static parts of the hast to html
5188
rehypeOptimizeStatic,
5289
],
5390
},
91+
image: {
92+
domains: ['avatars.githubusercontent.com'],
93+
service: sharpImageService(),
94+
},
5495
});

config/locales.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type starlight from '@astrojs/starlight';
2+
import { normalizeLangTag } from '../src/i18n/bcp-normalize';
3+
import languages, { rtlLanguages } from '../src/i18n/languages';
4+
5+
type StarlightLocalesConfig = NonNullable<Parameters<typeof starlight>[0]['locales']>;
6+
7+
export function makeLocalesConfig(): StarlightLocalesConfig {
8+
return Object.fromEntries(
9+
Object.entries(languages).map(([locale, label]) => [
10+
locale,
11+
{ label, lang: normalizeLangTag(locale), dir: rtlLanguages.has(locale) ? 'rtl' : 'ltr' },
12+
])
13+
);
14+
}

config/sidebar.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type starlight from '@astrojs/starlight';
2+
import { normalizeLangTag } from '../src/i18n/bcp-normalize';
3+
import type { NavDict } from '../src/i18n/translation-checkers';
4+
import { navTranslations } from '../src/i18n/util';
5+
6+
/** For an item in our sidebar, get translations of its label. */
7+
function getTranslations(item: NavDict[number]): Record<string, string> | undefined {
8+
return Object.fromEntries(
9+
Object.entries(navTranslations)
10+
.map(([lang, translations]) => {
11+
const translation = translations.find((t) => t.key === item.key);
12+
return [
13+
normalizeLangTag(lang),
14+
translation && translation.text !== item.text ? translation?.text : '',
15+
] as const;
16+
})
17+
.filter(([, text]) => Boolean(text))
18+
);
19+
}
20+
21+
type StarlightSidebarConfig = NonNullable<Parameters<typeof starlight>[0]['sidebar']>;
22+
23+
/** Generate a Starlight sidebar config object from our existing `nav.ts` files. */
24+
export function makeSidebar(): StarlightSidebarConfig {
25+
return navTranslations.en.reduce((sidebar, item) => {
26+
if ('header' in item) {
27+
sidebar.push({
28+
label: item.text,
29+
translations: getTranslations(item),
30+
items: [],
31+
});
32+
} else {
33+
const group = sidebar.at(-1);
34+
if (group && 'items' in group) {
35+
group.items.push({
36+
label: item.text,
37+
link: item.slug,
38+
translations: getTranslations(item),
39+
});
40+
}
41+
}
42+
return sidebar;
43+
}, [] as StarlightSidebarConfig);
44+
}

0 commit comments

Comments
 (0)