Skip to content

Commit

Permalink
Merge branch 'main' into feat/shiki-defaultcolor
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored Jul 13, 2024
2 parents df4d945 + 4d93c91 commit e1c7ea6
Show file tree
Hide file tree
Showing 72 changed files with 4,402 additions and 515 deletions.
10 changes: 4 additions & 6 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import { rehypeAutolink } from './plugins/rehype-autolink';
import { rehypeTasklistEnhancer } from './plugins/rehype-tasklist-enhancer';
import { remarkFallbackLang } from './plugins/remark-fallback-lang';

/* https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables */
const VERCEL_PREVIEW_SITE =
process.env.VERCEL_ENV !== 'production' &&
process.env.VERCEL_URL &&
`https://${process.env.VERCEL_URL}`;
/* https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables */
const NETLIFY_PREVIEW_SITE = process.env.CONTEXT !== 'production' && process.env.DEPLOY_PRIME_URL;

const site = VERCEL_PREVIEW_SITE || 'https://docs.astro.build/';
const site = NETLIFY_PREVIEW_SITE || 'https://docs.astro.build/';

// https://astro.build/config
export default defineConfig({
Expand Down Expand Up @@ -62,6 +59,7 @@ export default defineConfig({
},
},
],
disable404Route: true,
}),
sitemap(),
],
Expand Down
113 changes: 1 addition & 112 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,113 +1,2 @@
[[headers]]
for = "/_astro/*"
[headers.values]
Cache-Control = "public, max-age=604800, immutable"

[build]
command = "NODE_OPTIONS=--max_old_space_size=4096 pnpm netlify:build"
ignore = "git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- /"

[[redirects]]
from = "/reference/renderer-reference"
to = "/en/reference/integrations-reference"

[[redirects]]
from = "/en/reference/renderer-reference"
to = "/en/reference/integrations-reference"

[[redirects]]
from = "/en/core-concepts/component-hydration"
to = "/en/concepts/islands"

[[redirects]]
from = "/core-concepts/component-hydration"
to = "/en/concepts/islands"

[[redirects]]
from = "/en/getting-started/quick-start"
to = "/en/install/auto"

[[redirects]]
from = "/docs/*"
to = "/:splat"

[[redirects]]
from = "/:lang/docs/*"
to = "/:lang/:splat"

[[redirects]]
from = "/:lang/core-concepts/partial-hydration"
to = "/:lang/concepts/islands"

[[redirects]]
from = "/core-concepts/collections"
to = "/en/guides/content-collections"

[[redirects]]
from = "/:lang/core-concepts/collections"
to = "/:lang/guides/content-collections"

[[redirects]]
from = "/comparing-astro-vs-other-tools"
to = "/en/guides/migrate-to-astro"

[[redirects]]
from = "/:lang/comparing-astro-vs-other-tools"
to = "/:lang/guides/migrate-to-astro"

[[redirects]]
from = "/lighthouse/*"
to = "/en/guides/migrate-to-astro"

[[redirects]]
from = "/:lang/guides/publish-to-npm"
to = "/:lang/reference/publish-to-npm"

[[redirects]]
from = "/en/guides/debugging"
to = "/en/guides/troubleshooting"

[[redirects]]
from = "/en/quick-start"
to = "/en/installation"

[[redirects]]
from = "/:lang/concepts/mpa-vs-spa"
to = "/:lang/concepts/why-astro"

[[redirects]]
from = "/:lang/deploy/:service"
to = "/:lang/guides/deploy/:service"

[[redirects]]
from = "/:lang/guides/deploy/layer-zero"
to = "/:lang/guides/deploy/edgio"

[[redirects]]
from = "/:lang/guides/client-side-routing"
to = "/:lang/guides/view-transitions"

[[redirects]]
from = "/:lang/guides/assets"
to = "/:lang/guides/images"

[[redirects]]
from = "/:lang/guides/integrations-guide/image"
to = "/:lang/guides/images"

[[redirects]]
from = "/:lang/migration/0.21.0"
to = "/:lang/guides/upgrade-to/v1"

[[redirects]]
from = "/:lang/migrate"
to = "/:lang/guides/upgrade-to/v1"

[[redirects]]
from = "/"
to = "/en/getting-started"

[[redirects]]
from = "/:lang/*"
to = "/:lang/404/"
status = 404
command = "NODE_OPTIONS=--max_old_space_size=4096 pnpm netlify:build"
4 changes: 4 additions & 0 deletions public/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/_astro/*
cache-control: max-age=31536000
cache-control: immutable
cache-control: public
52 changes: 52 additions & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Moved content
# When moving a page, usually you’ll want to add a redirect to the bottom of this block.
/:lang/install/auto /:lang/install-and-setup/
/:lang/install/manual /:lang/install-and-setup/
/:lang/core-concepts/project-structure /:lang/basics/project-structure/
/:lang/core-concepts/astro-components /:lang/basics/astro-components/
/:lang/core-concepts/astro-pages /:lang/basics/astro-pages/
/:lang/core-concepts/layouts /:lang/basics/layouts/
/:lang/core-concepts/astro-syntax /:lang/basics/astro-syntax/
/:lang/core-concepts/rendering-modes /:lang/basics/rendering-modes/
/:lang/core-concepts/routing /:lang/guides/routing/
/:lang/core-concepts/endpoints /:lang/guides/endpoints/
/:lang/core-concepts/framework-components /:lang/guides/framework-components/
/:lang/core-concepts/sharing-state /:lang/recipes/sharing-state-islands/
/:lang/reference/dev-overlay-plugin-reference /:lang/reference/dev-toolbar-app-reference/
/:lang/core-concepts/partial-hydration /:lang/concepts/islands/
/:lang/guides/publish-to-npm /:lang/reference/publish-to-npm/
/:lang/concepts/mpa-vs-spa /:lang/concepts/why-astro/
/:lang/deploy/:service /:lang/guides/deploy/:service
/:lang/guides/deploy/layer-zero /:lang/guides/deploy/edgio/
/:lang/guides/client-side-routing /:lang/guides/view-transitions/
/:lang/guides/assets /:lang/guides/images/
/en/guides/aliases /en/guides/imports/#aliases
/:lang/guides/aliases /:lang/guides/imports/
/:lang/guides/integrations-guide/image /:lang/guides/images/
/:lang/migration/0.21.0 /:lang/guides/upgrade-to/v1/
/:lang/migrate /:lang/guides/upgrade-to/v1/
/:lang/recipes/studio /:lang/guides/astro-db/
/:lang/recipes /:lang/community-resources/content/

# Very old docs site redirects
# Once upon a time these URLs existed, so we try to keep them meaning something.
/reference/renderer-reference /en/reference/integrations-reference/
/en/reference/renderer-reference /en/reference/integrations-reference/
/en/core-concepts/component-hydration /en/concepts/islands/
/core-concepts/component-hydration /en/concepts/islands/
/core-concepts/collections /en/guides/content-collections/
/:lang/core-concepts/collections /:lang/guides/content-collections/
/en/getting-started/quick-start /en/install-and-setup/
/docs/* /:splat
/:lang/docs/* /:lang/:splat
/comparing-astro-vs-other-tools /en/guides/migrate-to-astro/
/:lang/comparing-astro-vs-other-tools /:lang/guides/migrate-to-astro/
/lighthouse/* /en/guides/migrate-to-astro/
/en/guides/debugging /en/guides/troubleshooting/
/en/quick-started /en/installation/

# Redirect root to English homepage
/ /en/getting-started/

# Translated 404s
/:lang/* /:lang/404/ 404
57 changes: 29 additions & 28 deletions src/components/LeftSidebar/Sponsors.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@ import UIString from '../UIString.astro';

<div dir="ltr" lang="en" class="sponsors">
<h2 class="sponsors-title"><UIString key="leftSidebar.sponsoredBy" /></h2>
<a href="https://vercel.com/" aria-label="Vercel">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 284 65" width="95" aria-hidden="true">
<a href="https://netlify.com/" aria-label="Netlify">
<svg xmlns="http://www.w3.org/2000/svg" width="96" viewBox="0 0 256 105" aria-hidden="true">
<path
d="M141.7 16.3c-11 0-19 7.1-19 18s9 18 20 18c6.7 0 12.5-2.7 16.2-7.1l-7.7-4.5c-2 2.2-5 3.5-8.5 3.5-4.8 0-8.9-2.5-10.4-6.5h28c.3-1 .4-2.2.4-3.5 0-10.8-8-18-19-18zm-9.5 14.4c1.3-4 4.7-6.4 9.5-6.4s8.2 2.5 9.4 6.4h-18.9zm117.2-14.4c-11 0-19 7.1-19 18s9 18 20 18a21 21 0 0 0 16.2-7.1l-7.7-4.5c-2 2.2-5 3.5-8.5 3.5-4.8 0-8.9-2.5-10.4-6.5h28c.2-1 .4-2.2.4-3.5 0-10.8-8-18-19-18zm-9.5 14.4c1.3-4 4.7-6.4 9.5-6.4s8.2 2.5 9.4 6.4H240zm-39 3.6c0 6 3.9 10 10 10 4.1 0 7.2-2 8.8-5l7.7 4.5a18.5 18.5 0 0 1-16.5 8.5c-11 0-19-7.2-19-18s8-18 19-18c7.3 0 13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6.6v12Zm20.3 8.3h-6.6l-.6-.6V28l.6-.6h6.6l.5.6v37.3l-.5.6ZM157 34h-6.6l-.5-.5V28l.5-.6h6.6l.6.6v5.5l-.6.5Zm0 31.9h-6.6l-.5-.6V39l.5-.6h6.6l.6.6v26.3l-.6.6Zm25.8-38v5.6l-.5.5h-5c-1 0-1.6.6-1.6 1.7v2.2l.5.5h5.5l.6.6v5.5l-.6.5h-5.5l-.5.6v19.7l-.6.6h-6.5l-.6-.6V45.5l-.5-.5h-3.9l-.5-.5V39l.5-.6h3.9l.5-.5v-2.2c0-6 4.4-8.3 9.4-8.3h4.9l.5.6Zm20.3 38.5c-2.2 5.5-4.3 8.8-12 8.8h-2.8l-.5-.5v-5.5l.5-.6h2.8c2.7 0 3.3-.5 3.8-2.2V66l-8.8-21.4V39l.6-.6h5l.5.6 6.5 18.7h.6L206 39l.5-.6h5l.5.6v5.5l-8.8 22Z"
></path>
</svg>
</a>
<a
href="https://sentry.io/welcome/?utm_medium=partner&utm_source=astro&utm_campaign=astro-docs"
aria-label="Sentry"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 44" width="96" aria-hidden="true">
<path
d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z"
fill="currentColor"></path>
</svg>
</a>
<a href="https://www.storyblok.com/" aria-label="Storyblok">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 251 53" width="125" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 251 53" width="114" aria-hidden="true">
<g>
<path
d="M73 37c-2 0-3.7-.2-5.5-.7-1.6-.6-3.2-1.5-4.5-2.7l2.4-4c1.3 1 2.5 1.6 3.8 2.1 1.2.6 2.4.8 3.6.8a4 4 0 0 0 2-.5c.4-.3.6-.7.6-1.3 0-.5-.2-1-.9-1.4-1-.4-2-.8-3-1L67.7 27a13 13 0 0 1-2.4-1.3c-.6-.4-1.1-1-1.4-1.6a5 5 0 0 1-.4-2c0-2.2.9-4.1 2.5-5.4a9.3 9.3 0 0 1 6.1-2c1.6 0 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-30h6.6v12a8 8 0 0 1 10.8-3c1.1.5 2 1.3 3 2.3a14 14 0 0 1 1.8 12.4c-.5 1.3-1.2 2.6-2 3.5a9.6 9.6 0 0 1-7.3 3.2Zm-1.8-5.5a5 5 0 0 0 4.7-3.4c.8-2 .4-4.4-1-6.2-.8-1-2-1.7-3.4-1.7-1 0-2 .4-2.8 1-.9.8-1.6 1.7-2 2.8v4.5a5 5 0 0 0 4.6 3Zm15-24.8h6.6V29c0 1.7.7 2.5 2.1 2.5a5 5 0 0 0 2.1-.5l1 4.8a15 15 0 0 1-5.9 1.3c-1.9 0-3.3-.5-4.3-1.5s-1.6-2.4-1.6-4.3V6.8Zm24 30.3c-1.6 0-3.2-.3-4.8-.9-2.7-1-4.9-3.3-5.9-6a12 12 0 0 1 2.2-12 11.3 11.3 0 0 1 8.5-3.4 11 11 0 0 1 10.7 6.9c1.6 4.1.8 8.7-2.2 12a10 10 0 0 1-3.6 2.5c-1.6.6-3.2 1-4.9.9ZM210.2 26c0 1.7.4 3 1.3 4 1 1 2.1 1.6 3.5 1.6 1.3 0 2.5-.6 3.4-1.6a6.4 6.4 0 0 0 1.4-4 6 6 0 0 0-1.4-4.1c-1-1-2-1.6-3.4-1.6-1.3 0-2.6.6-3.4 1.6a6 6 0 0 0-1 1.8c-.3.7-.4 1.4-.4 2.3Zm34 10.7-5.6-8.7-2.3 2.4v6.3h-6.6v-30h6.6v17.4l7.2-8.9h7l-7.8 9.3 8.4 12.2h-7Z"
Expand All @@ -28,32 +42,19 @@ import UIString from '../UIString.astro';
</g>
</svg>
</a>
<a
href="https://sentry.io/welcome/?utm_medium=partner&utm_source=astro&utm_campaign=astro-docs"
aria-label="Sentry"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 200 44"
width="110"
height="24"
aria-hidden="true"
>
<path
d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z"
fill="currentColor"></path>
</svg>
</a>
</div>

<style>
.sponsors {
display: flex;
flex-wrap: wrap;
gap: 1.25rem;
padding: 1rem 0;
gap: 0 1.5rem;
padding: 1.5rem 0.5rem 0.75rem;
}
a {
display: flex;
align-items: center;
min-height: 3rem;
opacity: 0.75;
}
a:hover {
Expand All @@ -66,11 +67,11 @@ import UIString from '../UIString.astro';

.sponsors-title {
width: 100%;
color: hsl(var(--color-base-gray), 25%);
font-size: 0.8em;
font-weight: 300;
letter-spacing: 0.0625em;
margin: 0 0;
text-transform: uppercase;
color: var(--sl-color-gray-3);
font-size: var(--sl-text-xs);
font-weight: 400;
font-family: var(--__sl-font-mono);
line-height: var(--sl-line-height-headings);
margin: 0 0 0.5rem;
}
</style>
90 changes: 10 additions & 80 deletions src/components/NotFound.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,24 @@
import { Image } from 'astro:assets';
import Houston from '~/assets/houston_astronaut.png';
import NotFoundSvg from '~/assets/not_found.png';
import languages from '~/i18n/languages';
import type { UILanguageKeys } from '~/i18n/translation-checkers';
import { useTranslationsForLang } from '~/i18n/util';
const defaultLang = 'en';
const t = useTranslationsForLang(defaultLang);
/**
* Dictionary of translated content for the 404 page.
* Creates an object like:
* ```js
* {
* en: { p: 'This page isn’t in our solar system.', a: 'Take me home.' },
* // other languages
* }
* ```
* `p` targets the paragraph content, `a` targets the link text.
*/
const dictionary = Object.fromEntries(
Object.keys(languages).map((_lang) => {
const lang = _lang as UILanguageKeys;
const t = useTranslationsForLang(lang);
return [lang, { p: t('404.content'), a: t('404.linkText') }];
})
);
interface Props {
lang: UILanguageKeys;
}
const { lang } = Astro.props;
const t = useTranslationsForLang(lang);
---

<div class="wrapper">
<Image class="galaxy" src={NotFoundSvg} alt="" loading="eager" />
<Image class="houston" src={Houston} alt="" loading="eager" width="192" />
<four-oh-four data-dictionary={JSON.stringify(dictionary)}>
<div class="hero-text">
<h1>404</h1>
<p>{t('404.content')}</p>
<a href={`/${defaultLang}/`}>{t('404.linkText')}</a>
</div>
</four-oh-four>
<div class="hero-text">
<h1>404</h1>
<p>{t('404.content')}</p>
<a href={`/${lang}/`}>{t('404.linkText')}</a>
</div>
</div>

<style is:global>
Expand Down Expand Up @@ -118,54 +99,3 @@ const dictionary = Object.fromEntries(
<script>
window.addEventListener('load', () => (window as any).fathom.trackGoal('4KN9VI2W', 0));
</script>

<script is:inline>
/**
* Custom element that updates its content to match the requested URL’s language.
* Script is inlined to avoid a visible flash of the English fallback content.
*/
class FourOhFour extends HTMLElement {
constructor() {
super();
try {
if (!this.dataset.dictionary) return;
const dictionary = JSON.parse(this.dataset.dictionary);
const languages = Object.keys(dictionary);

// Get current language from the URL path.
const langCodeMatch = location.pathname.match(`/(${languages.join('|')})/`);
const lang = langCodeMatch ? langCodeMatch[1] : 'en';

// Update homepage link to use current language.
const a = this.querySelector('a');
a.pathname = `/${lang}/`;

// Update text to use current language’s strings.
const translations = dictionary[lang];
for (const key in translations) {
this.querySelector(key).innerText = translations[key];
}

// Set the `lang` attribute to match the updated content.
const bcp47 = lang.slice(0, 3) + lang.slice(3, 5).toUpperCase();
this.setAttribute('lang', bcp47);
} catch {
// Falls back to static rendered text on errors, which should be fine.
}
}
}
customElements.define('four-oh-four', FourOhFour);
</script>

<script is:inline>
// Script is inlined to avoid visible flash
(() => {
// Get current language from URL, then apply it to language selector if matched
const language = location.pathname.split('/').at(1);
const cssSelector = `starlight-lang-select option[value^="/${language}/"]`;
const matchedLanguageOption = document.querySelector(cssSelector);
if (matchedLanguageOption?.parentElement) {
matchedLanguageOption.parentElement.value = matchedLanguageOption.value;
}
})();
</script>
Loading

0 comments on commit e1c7ea6

Please sign in to comment.