Skip to content
Merged
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
25 changes: 17 additions & 8 deletions packages/astro/src/assets/fonts/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# fonts

The vite plugin orchestrates the fonts logic:
Here is an overview of the architecture of the fonts in Astro:

- Retrieves data from the config
- Initializes font providers
- Fetches fonts data
- In dev, serves a middleware that dynamically loads and caches fonts data
- In build, download fonts data (from cache if possible)

The `<Font />` component is the only aspect not managed in the vite plugin, since it's exported from `astro:assets`.
- [`orchestrate()`](./orchestrate.ts) combines sub steps and takes care of getting useful data from the config
- It resolves font families (eg. import remote font providers)
- It prepares [`unifont`](https://github.com/unjs/unifont) providers
- It initializes `unifont`
- For each family, it resolves fonts data and normalizes them
- For each family, optimized fallbacks (and related CSS) are generated if applicable
- It returns the data
- [`/logic`](./logic/) contains the sub steps of `orchestrate()` so they can be easily tested
- The logic uses [inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control) to make it easily testable and swappable
- [`definitions.ts`](./definitions.ts) defines dependencies
- Those dependencies are implemented in [`/implementations`](./implementations/)
- [`fontsPlugin()`](./vite-plugin-fonts.ts) calls `orchestrate()` and using its result, setups anything required so that fonts can
- Be exposed to users (virual module)
- Be used in dev (middleware)
- Be used in build (copy)
- [`<Font />`](../../../components/Font.astro) is managed in [`assets()`](../vite-plugin-assets.ts) so it can be imported from `astro:assets` and consumes the virtual module