Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions astro.sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const sidebar = [
'reference/experimental-flags/svg-optimization',
'reference/experimental-flags/queued-rendering',
'reference/experimental-flags/rust-compiler',
'reference/experimental-flags/logger',
],
}),
'reference/legacy-flags',
Expand Down
22 changes: 9 additions & 13 deletions src/content/docs/en/guides/fonts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,20 @@ You can also opt out of the default optimization by setting [`font.optimizedFall

## Accessing font data programmatically

Astro exposes a low-level API for accessing font family data programmatically through the [`fontData`](/en/reference/modules/astro-assets/#fontdata) object. This can be useful for advanced use cases where you need direct access to font files, such as generating OpenGraph images with [Satori](https://github.com/vercel/satori) in an [API Route](/en/guides/endpoints/#server-endpoints-api-routes).
Astro exposes low-level APIs for accessing data programmatically:

This low-level API gives you access to all font files downloaded by Astro for your project, along with their metadata. This means that you are responsible for filtering font files to find the specific file you need, and for resolving the file path to use based on the build output structure.
- Font family data through the [`fontData`](/en/reference/modules/astro-assets/#fontdata) object
- Font file URLs with the [`experimental_getFontFileURL()`](/en/reference/modules/astro-assets/#experimental_getfontfileurl) function.

:::note
The current API has a [known limitation that requires you to manually load the font file](https://github.com/withastro/astro/issues/16139) from the output path at build time.
This can be useful for advanced use cases where you need direct access to font files, such as generating OpenGraph images with [Satori](https://github.com/vercel/satori) in an [API Route](/en/guides/endpoints/#server-endpoints-api-routes).

A new API is being developed to simplify this process and will be available in a future release. You can subscribe to the GitHub issue to follow its progress.
:::
The `fontData` object gives you access to all font files downloaded by Astro for your project, along with their metadata. This means that you are responsible for filtering font files to find the specific file you need, and for fetching data after resolving URLs.

The following example generates an OpenGraph image in a static file endpoint, assuming that only [one font and its format have been configured](/en/reference/configuration-reference/#fontformats) with a [format supported by Satori](https://github.com/vercel/satori?tab=readme-ov-file#fonts):

```tsx title="src/pages/og.png.ts" {2} "fontData[\"--font-roboto\"]"
```tsx title="src/pages/og.png.ts" {2,14-15} "fontData[\"--font-roboto\"]"
import type { APIRoute } from "astro";
import { fontData } from "astro:assets";
import { outDir } from "astro:config/server";
import { readFile } from "node:fs/promises";
import { fontData, experimental_getFontFileURL } from "astro:assets";
import satori from "satori";
import { html } from "satori-html";
import sharp from "sharp";
Expand All @@ -303,9 +300,8 @@ export const GET: APIRoute = async (context) => {
throw new Error("Cannot find the font path.");
}

const data = import.meta.env.DEV
? await fetch(new URL(fontPath, context.url.origin)).then(async (res) => res.arrayBuffer())
: await readFile(new URL(`.${fontPath}`, outDir));
const url = experimental_getFontFileURL(fontPath, context.url);
const data = await fetch(url).then((res) => res.arrayBuffer());

const svg = await satori(
html`<div style="color: black;">hello, world</div>`,
Expand Down
10 changes: 10 additions & 0 deletions src/content/docs/en/reference/adapter-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,16 @@ Defines an instance of the Astro logger that can be used to write logs when the

Describes the [configured HTTP response headers](/en/reference/configuration-reference/#serverheaders).

#### `PreviewServerParams.allowedHosts`

<p>

**Type:** `string[] | true | undefined`<br />
<Since v="6.2.0" />
</p>

Describes the [configured allowed hosts](/en/reference/configuration-reference/#serverallowedhosts) that the preview server should respond to.

#### `PreviewServerParams.root`

<p>
Expand Down
13 changes: 8 additions & 5 deletions src/content/docs/en/reference/configuration-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,23 @@ The value can be either an absolute file system path or a path relative to the p

<p>

**Type:** `boolean`<br />
**Type:** `boolean | "jsx"`<br />
**Default:** `true`
</p>

This is an option to minify your HTML output and reduce the size of your HTML files.
Controls how Astro handles whitespace in your HTML. This affects both development mode and the final build output.

By default, Astro removes whitespace from your HTML, including line breaks, in a lossless manner from `.astro` components. Some whitespace may be preserved as needed to maintain the visual rendering of your HTML.

By default, Astro removes whitespace from your HTML, including line breaks, from `.astro` components in a lossless manner.
Some whitespace may be kept as needed to preserve the visual rendering of your HTML. This occurs both in development mode and in the final build.
Setting this option to `"jsx"` instead applies the JSX whitespace stripping rules used by frameworks like React. Leading and trailing whitespace is only preserved when explicitly included in the source code through constructs such as `{" "}`, and is otherwise removed entirely.

To disable HTML compression, set `compressHTML` to false.
Setting this option to false disables HTML compression and preserves all whitespace.

```js
{
compressHTML: false
// or:
// compressHTML: 'jsx'
}
```

Expand Down
4 changes: 4 additions & 0 deletions src/content/docs/en/reference/error-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ The following reference is a complete list of the errors you may encounter while
- [**CannotDetermineWeightAndStyleFromFontFile**](/en/reference/errors/cannot-determine-weight-and-style-from-font-file/)<br/>Cannot determine weight and style from font file.
- [**CannotFetchFontFile**](/en/reference/errors/cannot-fetch-font-file/)<br/>Cannot fetch the given font file.
- [**FontFamilyNotFound**](/en/reference/errors/font-family-not-found/)<br/>Font family not found
- [**FontFileUrlNotFound**](/en/reference/errors/font-file-url-not-found/)<br/>Font file URL not found
- [**MissingGetFontFileRequestUrl**](/en/reference/errors/missing-get-font-file-request-url/)<br/>`experimental_getFontFileURL()` requires the request URL with on-demand rendering.
- [**UnavailableAstroGlobal**](/en/reference/errors/unavailable-astro-global/)<br/>Unavailable Astro global in getStaticPaths()
- [**UnableToLoadLogger**](/en/reference/errors/unable-to-load-logger/)<br/>Unable to load the logger.
- [**LoggerConfigurationNotSerializable**](/en/reference/errors/logger-configuration-not-serializable/)<br/>The configuration of the logger is not serializable

## CSS Errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import DontEditWarning from '~/components/DontEditWarning.astro'
<DontEditWarning />


> An error occurred while optimizing the SVG file with SVGO.
> An error occurred while optimizing the SVG file with the optimizer.



Expand Down
22 changes: 22 additions & 0 deletions src/content/docs/en/reference/errors/font-file-url-not-found.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# NOTE: This file is auto-generated from 'scripts/error-docgen.mjs'
# Do not make edits to it directly, they will be overwritten.
# Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
# Translators, please remove this note and the <DontEditWarning/> component.

title: Font file URL not found
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
---
import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />


> The URL passed to the `experimental_getFontFileURL()` function is invalid.

## What went wrong?
Font file URL not found



Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# NOTE: This file is auto-generated from 'scripts/error-docgen.mjs'
# Do not make edits to it directly, they will be overwritten.
# Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
# Translators, please remove this note and the <DontEditWarning/> component.

title: The configuration of the logger is not serializable
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
---
import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />


> The configuration of the logger is not serializable.

## What went wrong?
The configuration of the logger is not serializable.



Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# NOTE: This file is auto-generated from 'scripts/error-docgen.mjs'
# Do not make edits to it directly, they will be overwritten.
# Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
# Translators, please remove this note and the <DontEditWarning/> component.

title: experimental_getFontFileURL() requires the request URL with on-demand rendering.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
---
import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />


## What went wrong?
`experimental_getFontFileURL()` requires the request URL with on-demand rendering.



22 changes: 22 additions & 0 deletions src/content/docs/en/reference/errors/unable-to-load-logger.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# NOTE: This file is auto-generated from 'scripts/error-docgen.mjs'
# Do not make edits to it directly, they will be overwritten.
# Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
# Translators, please remove this note and the <DontEditWarning/> component.

title: Unable to load the logger.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
---
import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />


> Couldn't load the logger at the given path.

## What went wrong?
Unable to load the logger.



Loading
Loading