diff --git a/AGENTS.md b/AGENTS.md index d718f91c..a88208cc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ with workspace members in `packages/*` and `www/`. - **`packages/plugin-vite/`** (`@fresh/plugin-vite`): Vite integration plugin with dev server, SSR/client builds, and HMR. - **`packages/init/`** (`@fresh/init`): Project scaffolding - (`deno run -A jsr:@fresh/init`). + (`deno create @fresh/init`). - **`packages/update/`** (`@fresh/update`): Automated Fresh 1.x to 2.x migration tool using ts-morph for AST transforms. - **`packages/build-id/`** (`@fresh/build-id`): Build/deployment ID generation. diff --git a/README.md b/README.md index ecee756c..9921eea3 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ You can scaffold a new project by running the Fresh init script. To scaffold a project run the following: ```sh -deno run -Ar jsr:@fresh/init +deno create @fresh/init ``` Then navigate to the newly created project folder: diff --git a/docs/1.x/concepts/partials.md b/docs/1.x/concepts/partials.md index aa8af04a..1b697dcf 100644 --- a/docs/1.x/concepts/partials.md +++ b/docs/1.x/concepts/partials.md @@ -76,7 +76,7 @@ Let's use a typical documentation page layout as an example. It often features a main content area and a sidebar of links to switch between pages of the documentation (marked green here). - + The code for such a page (excluding styling) might look like this: diff --git a/docs/check_images_test.ts b/docs/check_images_test.ts new file mode 100644 index 00000000..e53c2ffa --- /dev/null +++ b/docs/check_images_test.ts @@ -0,0 +1,55 @@ +/** + * Verifies that all image references in documentation markdown files + * point to existing files in www/static/. + * + * Run: deno test -A docs/check_images_test.ts + */ +import { walk } from "jsr:@std/fs@1/walk"; +import { join, resolve } from "jsr:@std/path@1"; + +const ROOT = resolve(import.meta.dirname!); +const PROJECT_ROOT = resolve(ROOT, ".."); +const DOCS_DIR = ROOT; +const STATIC_DIR = join(PROJECT_ROOT, "www", "static"); + +const IMAGE_RE = /!\[.*?\]\(([^)]+)\)/g; + +Deno.test("all doc image references point to existing files", async () => { + const errors: string[] = []; + + for await ( + const entry of walk(DOCS_DIR, { + exts: [".md", ".mdx"], + includeDirs: false, + }) + ) { + const content = await Deno.readTextFile(entry.path); + const relativePath = entry.path.slice(PROJECT_ROOT.length); + + for (const match of content.matchAll(IMAGE_RE)) { + const imgPath = match[1]; + + // Skip external URLs + if (imgPath.startsWith("http://") || imgPath.startsWith("https://")) { + continue; + } + + // Doc image paths like "/docs/foo.png" map to "www/static/docs/foo.png" + const fsPath = join(STATIC_DIR, imgPath); + + try { + await Deno.stat(fsPath); + } catch { + errors.push(`${relativePath}: image not found: ${imgPath}`); + } + } + } + + if (errors.length > 0) { + throw new Error( + `Found ${errors.length} broken image reference(s):\n\n${ + errors.join("\n") + }`, + ); + } +}); diff --git a/docs/latest/advanced/api-reference.md b/docs/latest/advanced/api-reference.md new file mode 100644 index 00000000..ce6a65b9 --- /dev/null +++ b/docs/latest/advanced/api-reference.md @@ -0,0 +1,98 @@ +--- +description: | + Quick reference for all public exports from Fresh's entry points: fresh, fresh/runtime, and fresh/dev. +--- + +This page lists all public exports from Fresh's entry points. + +> [info]: You can also explore Fresh's full API documentation on JSR: +> [`@fresh/core`](https://jsr.io/@fresh/core/doc) + +## `fresh` + +The main entry point for server-side code. + +```ts +import { App, createDefine, HttpError, page, staticFiles } from "fresh"; +``` + +| Export | Kind | Description | +| --------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------- | +| [`App`](https://jsr.io/@fresh/core/doc/~/App) | Class | The main application class. See [App](/docs/concepts/app). | +| [`staticFiles`](https://jsr.io/@fresh/core/doc/~/staticFiles) | Function | Middleware for serving static files. See [Static Files](/docs/concepts/static-files). | +| [`createDefine`](https://jsr.io/@fresh/core/doc/~/createDefine) | Function | Create type-safe `define.*` helpers. See [Define Helpers](/docs/advanced/define). | +| [`page`](https://jsr.io/@fresh/core/doc/~/page) | Function | Return data from a handler to a page component. See [Data Fetching](/docs/concepts/data-fetching). | +| [`HttpError`](https://jsr.io/@fresh/core/doc/~/HttpError) | Class | Throw HTTP errors with status codes. See [Error Handling](/docs/advanced/error-handling). | +| [`cors`](https://jsr.io/@fresh/core/doc/~/cors) | Function | CORS middleware. See [cors](/docs/plugins/cors). | +| [`csrf`](https://jsr.io/@fresh/core/doc/~/csrf) | Function | CSRF protection middleware. See [csrf](/docs/plugins/csrf). | +| [`csp`](https://jsr.io/@fresh/core/doc/~/csp) | Function | Content Security Policy middleware. See [csp](/docs/plugins/csp). | +| [`trailingSlashes`](https://jsr.io/@fresh/core/doc/~/trailingSlashes) | Function | Trailing slash enforcement middleware. See [trailingSlashes](/docs/plugins/trailing-slashes). | + +**Types:** + +| Export | Kind | Description | +| --------------------------------------------------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------- | +| [`Context`](https://jsr.io/@fresh/core/doc/~/Context) / [`FreshContext`](https://jsr.io/@fresh/core/doc/~/FreshContext) | Interface | The request context passed to all middlewares and handlers. | +| [`PageProps`](https://jsr.io/@fresh/core/doc/~/PageProps) | Type | Props received by page components (`data`, `url`, `params`, `state`, etc.). | +| [`Middleware`](https://jsr.io/@fresh/core/doc/~/Middleware) / [`MiddlewareFn`](https://jsr.io/@fresh/core/doc/~/MiddlewareFn) | Type | Middleware function type. | +| [`HandlerFn`](https://jsr.io/@fresh/core/doc/~/HandlerFn) | Type | Single handler function type. | +| [`HandlerByMethod`](https://jsr.io/@fresh/core/doc/~/HandlerByMethod) | Type | Object with per-method handler functions. | +| [`RouteHandler`](https://jsr.io/@fresh/core/doc/~/RouteHandler) | Type | Union of `HandlerFn` and `HandlerByMethod`. | +| [`PageResponse`](https://jsr.io/@fresh/core/doc/~/PageResponse) | Type | Return type of `page()`. | +| [`RouteConfig`](https://jsr.io/@fresh/core/doc/~/RouteConfig) | Interface | Route configuration (`routeOverride`, `skipInheritedLayouts`, etc.). | +| [`LayoutConfig`](https://jsr.io/@fresh/core/doc/~/LayoutConfig) | Interface | Layout configuration (`skipInheritedLayouts`, `skipAppWrapper`). | +| [`Define`](https://jsr.io/@fresh/core/doc/~/Define) | Interface | Type of the object returned by `createDefine()`. | +| [`FreshConfig`](https://jsr.io/@fresh/core/doc/~/FreshConfig) / [`ResolvedFreshConfig`](https://jsr.io/@fresh/core/doc/~/ResolvedFreshConfig) | Interface | App configuration types. | +| [`ListenOptions`](https://jsr.io/@fresh/core/doc/~/ListenOptions) | Interface | Options for `app.listen()`. | +| [`Island`](https://jsr.io/@fresh/core/doc/~/Island) | Type | Island component type. | +| [`Method`](https://jsr.io/@fresh/core/doc/~/Method) | Type | HTTP method union type. | +| [`RouteData`](https://jsr.io/@fresh/core/doc/~/RouteData) | Type | Data type returned by route handlers via `page()`. | +| [`Lazy`](https://jsr.io/@fresh/core/doc/~/Lazy) / [`MaybeLazy`](https://jsr.io/@fresh/core/doc/~/MaybeLazy) | Type | Utility types for lazily-loaded routes and middleware. | +| [`CORSOptions`](https://jsr.io/@fresh/core/doc/~/CORSOptions) | Interface | Options for `cors()`. | +| [`CsrfOptions`](https://jsr.io/@fresh/core/doc/~/CsrfOptions) | Interface | Options for `csrf()`. | +| [`CSPOptions`](https://jsr.io/@fresh/core/doc/~/CSPOptions) | Interface | Options for `csp()`. | + +## `fresh/runtime` + +Shared runtime utilities for both server and client code. Safe to import in +[islands](/docs/concepts/islands). + +```ts +import { + asset, + assetSrcSet, + Head, + HttpError, + IS_BROWSER, + Partial, +} from "fresh/runtime"; +``` + +| Export | Kind | Description | +| --------------------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------- | +| [`IS_BROWSER`](https://jsr.io/@fresh/core/doc/runtime/~/IS_BROWSER) | Constant | `true` in the browser, `false` on the server. Use to guard browser-only code. | +| [`asset`](https://jsr.io/@fresh/core/doc/runtime/~/asset) | Function | Add cache-busting query params to asset URLs. See [Static Files](/docs/concepts/static-files). | +| [`assetSrcSet`](https://jsr.io/@fresh/core/doc/runtime/~/assetSrcSet) | Function | Apply `asset()` to all URLs in a `srcset` string. | +| [`Partial`](https://jsr.io/@fresh/core/doc/runtime/~/Partial) | Component | Mark a region for partial updates. See [Partials](/docs/advanced/partials). | +| [`Head`](https://jsr.io/@fresh/core/doc/runtime/~/Head) | Component | Add elements to the document `
`. See [ element](/docs/advanced/head). | +| [`HttpError`](https://jsr.io/@fresh/core/doc/runtime/~/HttpError) | Class | HTTP error class (re-exported from `fresh`). | + +## `fresh/dev` + +Development and build tools. Only used in `dev.ts` (legacy) or build scripts. + +```ts +import { Builder } from "fresh/dev"; +``` + +| Export | Kind | Description | +| --------------------------------------------------------- | ----- | ---------------------------------------------------------------------- | +| [`Builder`](https://jsr.io/@fresh/core/doc/dev/~/Builder) | Class | Pre-Vite build system (legacy). See [Builder](/docs/advanced/builder). | + +**Types:** + +| Export | Kind | Description | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------- | +| [`BuildOptions`](https://jsr.io/@fresh/core/doc/dev/~/BuildOptions) | Interface | Options for `new Builder()`. | +| [`ResolvedBuildConfig`](https://jsr.io/@fresh/core/doc/dev/~/ResolvedBuildConfig) | Interface | Resolved build configuration. | +| [`OnTransformArgs`](https://jsr.io/@fresh/core/doc/dev/~/OnTransformArgs) / [`OnTransformOptions`](https://jsr.io/@fresh/core/doc/dev/~/OnTransformOptions) / [`TransformFn`](https://jsr.io/@fresh/core/doc/dev/~/TransformFn) | Type | Build plugin hook types. | diff --git a/docs/latest/advanced/app-wrapper.md b/docs/latest/advanced/app-wrapper.md index 54baa325..752a31c2 100644 --- a/docs/latest/advanced/app-wrapper.md +++ b/docs/latest/advanced/app-wrapper.md @@ -1,12 +1,51 @@ --- description: | - Add a global app wrapper to provide common meta tags or context for application routes. + The app wrapper defines the outermost HTML shell shared by all pages - the , , and tags. --- -The app wrapper component is a Preact component that represents the outer -structure of the HTML document, typically up until the ``-tag. It is only -rendered on the server and never on the client. The passed `Component` value -represents the children of this component. +The app wrapper is the outermost component in Fresh's rendering hierarchy. It +defines the ``, ``, and `` tags that every page shares. It is +only rendered on the server. + +## When to use an app wrapper + +Use an app wrapper when you need to: + +- Set the document language (``) +- Include global `` tags, fonts, or stylesheets +- Add analytics scripts or structured data to every page +- Set a global `` class or data attribute +- Provide a consistent HTML skeleton without repeating it in every layout + +If you're using [file-based routing](/docs/concepts/file-routing), create a +`routes/_app.tsx` file. Otherwise, register it programmatically with +`app.appWrapper()`. + +## Basic example + +```tsx routes/_app.tsx +import { define } from "../utils.ts"; + +export default define.page(({ Component, url }) => { + return ( + + + + +