Skip to content

DirectoryListing tag filter #22064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 1, 2025
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
4 changes: 3 additions & 1 deletion public/__redirects
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,9 @@
/workers/tutorials/create-sitemap-from-sanity-cms/ /developer-spotlight/tutorials/create-sitemap-from-sanity-cms/ 301
/workers/tutorials/custom-access-control-for-files-in-r2-using-d1-and-workers/ /developer-spotlight/tutorials/custom-access-control-for-files/ 301
/workers/tutorials/generate-dynamic-og-images-using-workers/ /workers/tutorials/ 302
/workers/static-assets/compatibility-matrix/ /workers/static-assets/migrate-from-pages/ 301
/workers/static-assets/migrate-from-pages/ /workers/static-assets/migration-guides/migrate-from-pages/ 301
/workers/static-assets/compatibility-matrix/ /workers/static-assets/migration-guides/migrate-from-pages/ 301
/workers/static-assets/migrations/vercel-to-workers/ /workers/static-assets/migration-guides/vercel-to-workers/ 301
/workers/frameworks/framework-guides/remix/ /workers/frameworks/framework-guides/react-router/ 301
/workers/testing/unit-testing/ /workers/testing/vitest-integration/write-your-first-test/ 301
/workers/testing/integration-testing/ /workers/testing/ 301
Expand Down
9 changes: 7 additions & 2 deletions src/components/DirectoryListing.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const props = z.object({
descriptions: z.boolean().default(false),
folder: z.string().optional(),
maxDepth: z.number().default(1),
tag: z.string().optional(),
});

let { descriptions, folder, maxDepth } = props.parse(Astro.props);
let { descriptions, folder, maxDepth, tag } = props.parse(Astro.props);

if (!folder) folder = Astro.params.slug!;

Expand All @@ -34,7 +35,11 @@ function getChildren(parentPath: string, depth: number) {
return allPages.filter((page) => {
const pagePath = page.id;
const pageDepth = pagePath.split("/").length;
return pageDepth === depth && pagePath.startsWith(parentPath);
return (
pageDepth === depth &&
pagePath.startsWith(parentPath) &&
(tag ? page.data.tags?.includes(tag) : true)
);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enable_flag: "assets_navigation_prefers_asset_serving"
disable_flag: "assets_navigation_has_no_effect"
---

For Workers with [static assets](/workers/static-assets/) and this compatibility flag enabled, navigation requests (requests which have a `Sec-Fetch-Mode: navigate` header) will prefer to be served by our asset-serving logic, even when an exact asset match cannot be found. This is particularly useful for applications which operate in either [Single Page Application (SPA) mode](/workers/static-assets/routing/#not_found_handling--404-page--single-page-application--none) or [404 page mode](/workers/static-assets/routing/#not_found_handling--404-page--single-page-application--none), as this now means the fallback pages of `200 /index.html` and `404 /404.html` will be served ahead of invoking a Worker script and will therefore avoid incurring a charge.
For Workers with [static assets](/workers/static-assets/) and this compatibility flag enabled, navigation requests (requests which have a `Sec-Fetch-Mode: navigate` header) will prefer to be served by our asset-serving logic, even when an exact asset match cannot be found. This is particularly useful for applications which operate in either [Single Page Application (SPA) mode](/workers/static-assets/routing/single-page-application/) or have [custom 404 pages](/workers/static-assets/routing/static-site-generation/#custom-404-pages), as this now means the fallback pages of `200 /index.html` and `404 /404.html` will be served ahead of invoking a Worker script and will therefore avoid incurring a charge.

Without this flag, the runtime will continue to apply the old behavior of invoking a Worker script (if present) for any requests which do not exactly match a static asset.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The [`@opennextjs/cloudflare` adapter](https://opennext.js.org/cloudflare), whic

`@opennextjs/cloudflare` is pre 1.0, and still in active development. As it approaches 1.0, it will become the clearly better choice for most Next.js apps, since Next.js has been engineered to only support its Node.js "runtime" for many newly introduced features.

Refer to the [OpenNext docs](https://opennext.js.org/cloudflare) and the [Workers vs. Pages compatibility matrix](/workers/static-assets/migrations/migrate-from-pages/#compatibility-matrix) for more information to help you decide which to use.
Refer to the [OpenNext docs](https://opennext.js.org/cloudflare) and the [Workers vs. Pages compatibility matrix](/workers/static-assets/migration-guides/migrate-from-pages/#compatibility-matrix) for more information to help you decide which to use.

#### Supported Node.js APIs when using `@cloudflare/next-on-pages`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ When enabled, shows the [frontmatter `description`](/style-guide/frontmatter/) f

Controls how many levels of nested pages to display. A value of `1` shows only direct children, while higher values will show deeper nesting levels.

### `tag`

**type:** `string`

Optionally, filter the listing to only pages with a specific tag.

## Associated content types

- [Navigation](/style-guide/documentation-content-strategy/content-types/navigation/)
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ At a minimum, the `main_module` key is required to upload a Worker.

* [Asset](/workers/static-assets/) configuration for a Worker.
* `config` <Type text="object" /> <MetaInfo text="optional" />
* [html_handling](/workers/static-assets/routing/#1-html_handling) determines the redirects and rewrites of requests for HTML content.
* [not_found_handling](/workers/static-assets/routing/#2-not_found_handling) determines the response when a request does not match a static asset, and there is no Worker script.
* [html_handling](/workers/static-assets/routing/advanced/html-handling/) determines the redirects and rewrites of requests for HTML content.
* [not_found_handling](/workers/static-assets/routing/) determines the response when a request does not match a static asset.
* `jwt` field provides a token authorizing assets to be attached to a Worker.

* `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Angular
head: []
tags: ["full-stack"]
description: Create an Angular application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Astro
head: []
tags: ["ssg", "full-stack"]
description: Create an Astro application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down Expand Up @@ -38,7 +38,7 @@ import {

Astro emphasizes performance through minimal client-side JavaScript - by default, it renders as much content as possible at build time, or [on-demand](https://docs.astro.build/en/guides/on-demand-rendering/) on the "server" - this can be a Cloudflare Worker. [“Islands”](https://docs.astro.build/en/concepts/islands/) of JavaScript are added only where interactivity or personalization is needed.

Astro is also framework-agnostic, and supports every major UI framework, including React, Preact, Svelte, Vue, SolidJS , via its official [integrations](https://astro.build/integrations/).
Astro is also framework-agnostic, and supports every major UI framework, including React, Preact, Svelte, Vue, SolidJS, via its official [integrations](https://astro.build/integrations/).

## Deploy a new Astro project on Workers

Expand Down Expand Up @@ -96,7 +96,7 @@ If your Astro project is entirely pre-rendered, follow these steps:
</WranglerConfig>
<Details header="What's this configuration doing?">
The key part of this config is the `assets` field, which tells Wrangler where to find your static assets. In this case, we're telling Wrangler to look in the `./dist` directory. If your assets are in a different directory, update the `directory` value accordingly.
Read about other [asset configuration options](/workers/static-assets/routing/).
Read about other [asset configuration options](/workers/wrangler/configuration/#assets).

Also note how there's no `main` field in this config - this is because you're only serving static assets, so no Worker code is needed for on demand rendering/SSR.
</Details>
Expand Down Expand Up @@ -161,7 +161,7 @@ If your Astro project uses [on demand rendering (also known as SSR)](https://doc
- `main` points to the entry point of your Worker script. This is generated by the Astro adaptor, and is what powers your server-rendered pages.
- `assets.directory` tells Wrangler where to find your static assets. In this case, we're telling Wrangler to look in the `./dist` directory. If your assets are in a different directory, update the `directory` value accordingly.

Read more about [Wrangler configuration options](/workers/wrangler/configuration/) and [asset configuration options](/workers/static-assets/routing/).
Read more about [Wrangler configuration options](/workers/wrangler/configuration/) and [asset configuration options](/workers/wrangler/configuration/#assets).
</Details>

4. **Build and deploy your project**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Docusaurus
head: []
tags: ["ssg"]
description: Create a Docusaurus application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Gatsby
head: []
tags: ["ssg"]
description: Create a Gatsby application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Next.js
head: []
tags: ["full-stack"]
description: Create an Next.js application and deploy it to Cloudflare Workers with Workers Assets.
sidebar:
badge: Beta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Nuxt
head: []
tags: ["full-stack"]
description: Create a Nuxt application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Qwik
head: []
tags: ["full-stack"]
description: Create a Qwik application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
pcx_content_type: how-to
title: React Router (formerly Remix)
tags: ["full-stack"]
description: Create a React Router application and deploy it to Cloudflare Workers
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: React
head: []
tags: ["spa"]
description: Create a React application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Solid
head: []
tags: ["full-stack"]
description: Create a Solid application and deploy it to Cloudflare Workers with Workers Assets.
sidebar:
badge: Beta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Svelte
head: []
tags: ["spa"]
description: Create a Svelte application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
pcx_content_type: how-to
title: Vue
head: []
tags: ["spa"]
description: Create a Vue application and deploy it to Cloudflare Workers with Workers Assets.
---

Expand Down
8 changes: 4 additions & 4 deletions src/content/docs/workers/static-assets/binding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Now Wrangler will not upload these files as client-side assets when deploying th

## `run_worker_first`

Controls whether to invoke the Worker script regardless of a request which would have otherwise matched an asset. `run_worker_first = false` ([default](/workers/static-assets/routing/#default-behavior)) will serve any static asset matching a request, while `run_worker_first = true` will unconditionally [invoke your Worker script](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets).
Controls whether to invoke the Worker script regardless of a request which would have otherwise matched an asset. `run_worker_first = false` (default) will serve any static asset matching a request, while `run_worker_first = true` will unconditionally [invoke your Worker script](/workers/static-assets/routing/worker-script/#run-your-worker-script-first).

<WranglerConfig>

Expand Down Expand Up @@ -115,7 +115,7 @@ In the example above, assets would be available through `env.ASSETS`.

Your dynamic code can make new, or forward incoming requests to your project's static assets using the assets binding. For example, `env.ASSETS.fetch(request)`, `env.ASSETS.fetch(new URL('https://assets.local/my-file'))` or `env.ASSETS.fetch('https://assets.local/my-file')`.

Take the following example that configures a Worker script to return a response under all requests headed for `/api/`. Otherwise, the Worker script will pass the incoming request through to the asset binding. In this case, because a Worker script is only invoked when the requested route has not matched any static assets, this will always evaluate [`not_found_handling`](/workers/static-assets/routing/#routing-configuration) behavior.
Take the following example that configures a Worker script to return a response under all requests headed for `/api/`. Otherwise, the Worker script will pass the incoming request through to the asset binding. In this case, because a Worker script is only invoked when the requested route has not matched any static assets, this will always evaluate [`not_found_handling`](/workers/static-assets/routing/) behavior.

<Tabs>
<TabItem label="JavaScript" icon="seti:javascript">
Expand Down Expand Up @@ -166,7 +166,7 @@ For the various static asset routing configuration options, refer to [Routing](/

### Smart Placement with Worker Code First

If you desire to run your [Worker code ahead of assets](/workers/static-assets/routing/#invoking-worker-script-ahead-of-assets) by setting `run_worker_first=true`, all requests must first travel to your Smart-Placed Worker. As a result, you may experience increased latency for asset requests.
If you desire to run your [Worker code ahead of assets](/workers/static-assets/routing/worker-script/#run-your-worker-script-first) by setting `run_worker_first=true`, all requests must first travel to your Smart-Placed Worker. As a result, you may experience increased latency for asset requests.

Use Smart Placement with `run_worker_first=true` when you need to integrate with other backend services, authenticate requests before serving any assets, or if your want to make modifications to your assets before serving them.

Expand All @@ -178,4 +178,4 @@ Enabling Smart Placement with `run_worker_first=false` (or not specifying it) le

Use Smart Placement with `run_worker_first=false` (or not specifying it) when prioritizing fast asset delivery.

This will not impact the [default routing behavior](/workers/static-assets/routing/#default-behavior).
This will not impact the [default routing behavior](/workers/static-assets/routing/).
7 changes: 4 additions & 3 deletions src/content/docs/workers/static-assets/direct-upload.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Render,
TabItem,
Tabs,
TypeScriptExample,
} from "~/components";
import { Icon } from "astro-icon/components";

Expand Down Expand Up @@ -176,7 +177,7 @@ If this is a Worker which already has assets, and you wish to just re-use the ex
}
```

Asset [routing configuration](/workers/static-assets/routing/#routing-configuration) can be provided in the `assets` object, such as `html_handling` and `not_found_handling`.
Asset [routing configuration](/workers/wrangler/configuration/#assets) can be provided in the `assets` object, such as `html_handling` and `not_found_handling`.

```bash title="Example Worker Metadata Specifying Asset Configuration"
{
Expand Down Expand Up @@ -213,7 +214,7 @@ Optionally, an assets binding can be provided if you wish to fetch and serve ass

## Programmatic Example

<Tabs> <TabItem label="TypeScript" icon="seti:typescript">
<TypeScriptExample>

```ts
import * as fs from "fs";
Expand Down Expand Up @@ -427,4 +428,4 @@ if (buckets.length > 0) {
await scriptUpload(completionToken);
```

</TabItem> </Tabs>
</TypeScriptExample>
6 changes: 6 additions & 0 deletions src/content/docs/workers/static-assets/headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ When serving static assets, Workers will attach some headers to the response by

This header complements the default `Cache-Control` header. Its value is a hash of the static asset file, and browsers can use this in subsequent requests with an `If-None-Match` header to check for freshness, without needing to re-download the entire file in the case of a match.

- **`CF-Cache-Status`**

This header indicates whether the asset was served from the cache (`HIT`) or not (`MISS`).[^1]

Cloudflare reserves the right to attach new headers to static asset responses at any time in order to improve performance or harden the security of your Worker application.

<Render file="custom_headers" params={{ product: "workers" }} />

[^1]: Due to a technical limitation that we hope to address in the future, the `CF-Cache-Status` header is not always entirely accurate. It is possible for false-positives and false-negatives to occur. This should be rare. In the meantime, this header should be considered as returning a "probablistic" result.
4 changes: 2 additions & 2 deletions src/content/docs/workers/static-assets/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default {

By default, if a requested URL matches a file in the static assets directory, that file will always be served — without running Worker code. If no matching asset is found and a Worker is configured, the request will be processed by the Worker instead.

- If no Worker is set up, the [`not_found_handling`](/workers/static-assets/routing/#2-not_found_handling-1) setting in your Wrangler configuration determines what happens next. By default, a `404 Not Found` response is returned.
- If no Worker is set up, the [`not_found_handling`](/workers/static-assets/routing/) setting in your Wrangler configuration determines what happens next. By default, a `404 Not Found` response is returned.

- If a Worker is configured and a request does not match a static asset, the Worker will handle the request. The Worker can choose to pass the request to the asset binding (through `env.ASSETS.fetch()`), following the `not_found_handling` rules.

Expand Down Expand Up @@ -117,7 +117,7 @@ If you want the Worker code to execute before serving an asset (for example, to

<LinkCard
title="Routing options"
href="/workers/static-assets/routing/#routing-configuration"
href="/workers/static-assets/routing/"
description="Learn more about how you can customize routing behavior."
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
---
pcx_content_type: navigation
title: Migrations
title: Migration Guides
sidebar:
order: 11
group:
hideIndex: true
head: []
description: Learn how to migrate your applications to Cloudflare Workers.
---

import {
Description,
DirectoryListing,
} from "~/components";
import { Description, DirectoryListing } from "~/components";

<Description>
Migrate your existing applications to Cloudflare Workers.
</Description>

Take advantage of Cloudflare's global network and migrate your existing applications to Workers.

<DirectoryListing folder="workers/static-assets/migrations" />
<DirectoryListing />
Loading
Loading