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
5 changes: 5 additions & 0 deletions .changeset/rare-eggs-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes support for numeric IDs in YAML frontmatter when using content collection references
5 changes: 5 additions & 0 deletions .changeset/shaggy-wolves-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Adds a JSON schema to the Wrangler configuration file generated when running `astro add cloudflare`
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Use `pnpm -C <dir> <command>` for project-local script commands when working in

# `bgproc`

Use `pnpm exec bgproc` to start, stop, and manage long-running `astro dev` & `astro preview` servers in the background. Do not manually start detatched servers with `&` if you can use `bgproc` instead.
Use `pnpm exec bgproc` to start, stop, and manage long-running `astro dev` & `astro preview` servers in the background. Do not manually start detached servers with `&` if you can use `bgproc` instead.

Use `pnpm exec bgproc --help` to see all available commands.

Expand Down
53 changes: 53 additions & 0 deletions examples/advanced-routing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Astro Advanced Routing Example

```sh
npm create astro@latest -- --template advanced-routing
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/advanced-routing)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/advanced-routing)

This example showcases Astro's experimental advanced routing with `src/app.ts`, using [Hono](https://hono.dev/) middleware to control the request pipeline.

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── src/
│ ├── actions/
│ ├── layouts/
│ ├── pages/
│ │ ├── dashboard/
│ │ └── es/
│ └── app.ts
├── astro.config.mjs
├── package.json
└── tsconfig.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

The `src/app.ts` file controls the request pipeline. This example composes Astro's middleware with custom Hono middleware to handle routing behavior like authentication, redirects, and locale-specific pages.

## Server-side rendering (SSR)

This project uses the [`@astrojs/node`](https://docs.astro.build/en/guides/integrations-guide/node/) adapter with `output: "server"` and enables Astro's experimental `advancedRouting` option.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
4 changes: 2 additions & 2 deletions examples/component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This is a template for an Astro component library. Use this template for writing
npm create astro@latest -- --template component
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/non-html-pages)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/non-html-pages)
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/component)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/component)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/component/devcontainer.json)

## 🚀 Project Structure
Expand Down
4 changes: 2 additions & 2 deletions examples/container-with-vitest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
npm create astro@latest -- --template container-with-vitest
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/with-vitest)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/with-vitest)
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/container-with-vitest)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/container-with-vitest)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/with-vitest/devcontainer.json)

This example showcases Astro working with [Vitest](https://vitest.dev/) and how to test components using the Container API.
62 changes: 62 additions & 0 deletions examples/ssr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Astro SSR Example

```sh
npm create astro@latest -- --template ssr
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/ssr)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/ssr)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/ssr/devcontainer.json)

This example showcases server-side rendering with Astro using the [`@astrojs/node`](https://docs.astro.build/en/guides/integrations-guide/node/) adapter and [`@astrojs/svelte`](https://docs.astro.build/en/guides/integrations-guide/svelte/) integration.

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── public/
│ ├── favicon.ico
│ ├── favicon.svg
│ └── images/
├── src/
│ ├── components/
│ ├── models/
│ ├── pages/
│ │ ├── api/
│ │ └── products/
│ ├── styles/
│ └── api.ts
├── astro.config.mjs
├── package.json
└── tsconfig.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. Dynamic routes like `products/[id].astro` are used to render individual product pages.

There's nothing special about `src/components/`, but that's where we like to put any Astro or framework components.

Any static assets, like images, can be placed in the `public/` directory.

## Server-side rendering (SSR)

This project uses the [`@astrojs/node`](https://docs.astro.build/en/guides/integrations-guide/node/) adapter with `output: "server"` to render pages on demand and expose API routes from `src/pages/api/`.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run server` | Run the built Node server from `./dist/server/` |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
1 change: 1 addition & 0 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default async function seed() {
`,
CLOUDFLARE_WRANGLER_CONFIG: (name: string, compatibilityDate: string) => `\
{
"$schema": "./node_modules/wrangler/config-schema.json",
"compatibility_date": ${JSON.stringify(compatibilityDate)},
"compatibility_flags": ["global_fetch_strictly_public"],
"name": ${JSON.stringify(name)},
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type ContainerRenderOptions = {
routeType?: RouteType;

/**
* Allows to pass `Astro.props` to an Astro component:
* Allows passing `Astro.props` to an Astro component:
*
* ```js
* container.renderToString(Endpoint, { props: { "lorem": "ipsum" } });
Expand All @@ -105,9 +105,9 @@ export type ContainerRenderOptions = {
props?: Props;

/**
* When `false`, it forces to render the component as it was a full-fledged page.
* When `false`, it forces the component to render as if it were a full-fledged page.
*
* By default, the container API render components as [partials](https://docs.astro.build/en/basics/astro-pages/#page-partials).
* By default, the container API renders components as [partials](https://docs.astro.build/en/basics/astro-pages/#page-partials).
*
*/
partial?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/content/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ export function createReference() {
return function reference(collection: string) {
return z
.union([
z.number().transform((num) => num.toString(10)),
z.string(),
z.object({
id: z.string(),
Expand Down
57 changes: 57 additions & 0 deletions packages/astro/test/units/content-layer/data-transforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,61 @@ describe('Content Layer - Data Transforms', () => {
// The default is applied as a string, not transformed to a reference object
assert.equal(result2.data.category, 'general');
});

it('transforms numeric ids to strings', async () => {
const store = new MutableDataStore();
const settings = createMinimalSettings(root);
const logger = new AstroLogger({
destination: { write: () => true },
level: 'silent',
});

// Create a loader that returns data with reference strings
const dogsLoader = {
name: 'dogs-loader',
load: async (context: any) => {
const data = {
id: 'beagle',
name: 'Beagle Dog',
favoriteCat: 1,
};

const parsed = await context.parseData({
id: 'beagle',
data,
});

await context.store.set({
id: 'beagle',
data: parsed,
});
},
};

const collections = {
dogs: defineCollection({
loader: dogsLoader,
schema: z.object({
id: z.string(),
name: z.string(),
favoriteCat: reference('cats'),
}),
}),
};

const contentLayer = new ContentLayer({
settings,
logger,
store,
contentConfigObserver: createTestConfigObserver(collections),
});

await contentLayer.sync();

const result: any = store.get('dogs', 'beagle');
assert.ok(result);
assert.equal(result.data.id, 'beagle');
assert.equal(result.data.name, 'Beagle Dog');
assert.deepEqual(result.data.favoriteCat, { collection: 'cats', id: '1' });
});
});
Loading