From b4e4a0c0f0b942327f6f5ef79b6250a4ec27b5c2 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Fri, 25 Jul 2025 19:04:08 +0200 Subject: [PATCH] docs: update more pages for Fresh 2 (#3141) --- docs/canary/advanced/app-wrapper.md | 4 +- docs/canary/concepts/context.md | 6 ++ docs/canary/concepts/static-files.md | 9 +++ docs/canary/deployment/docker.md | 7 ++- .../deployment/{production.md => index.md} | 0 docs/canary/examples/active-links.md | 48 +++++++++++++++ docs/canary/examples/markdown.md | 59 +++++++++++++++++++ docs/toc.ts | 5 +- 8 files changed, 130 insertions(+), 8 deletions(-) rename docs/canary/deployment/{production.md => index.md} (100%) create mode 100644 docs/canary/examples/active-links.md create mode 100644 docs/canary/examples/markdown.md diff --git a/docs/canary/advanced/app-wrapper.md b/docs/canary/advanced/app-wrapper.md index 984de657..775a2dcf 100644 --- a/docs/canary/advanced/app-wrapper.md +++ b/docs/canary/advanced/app-wrapper.md @@ -26,8 +26,8 @@ function AppWrapper({ Component }) { app.appWrapper(AppWrapper); ``` -Every `ctx.render()` call will include the app wrapper component by default, -unless opted out. +Every [`ctx.render()`](/docs/canary/concepts/context#render-1) call will include +the app wrapper component by default, unless opted out. Note that only one app wrapper component is supported per [`App`](/docs/canary/concepts/app) instance. diff --git a/docs/canary/concepts/context.md b/docs/canary/concepts/context.md index bbcf87b5..a7f74fba 100644 --- a/docs/canary/concepts/context.md +++ b/docs/canary/concepts/context.md @@ -79,6 +79,12 @@ Pass data to the next middlewares with state. Every request has its own state object. ```ts +interface State { + text?: string; +} + +const app = new App(); + app.use((ctx) => { ctx.state.text = "foo"; return ctx.next(); diff --git a/docs/canary/concepts/static-files.md b/docs/canary/concepts/static-files.md index 98f8ca9b..83c1b1e9 100644 --- a/docs/canary/concepts/static-files.md +++ b/docs/canary/concepts/static-files.md @@ -16,6 +16,15 @@ const app = new App() .use(staticFiles()); ``` +The path to the static file directory can be customized on the +[`Builder` class](/docs/canary/concepts/builder) inside your `dev.ts` file. + +```ts dev.ts +import { Builder } from "fresh/dev"; + +const builder = new Builder({ staticDir: "path/to/staticDir" }); +``` + ## Caching headers By default, Fresh adds caching headers for the `src` and `srcset` attributes on diff --git a/docs/canary/deployment/docker.md b/docs/canary/deployment/docker.md index 1543ac48..20547011 100644 --- a/docs/canary/deployment/docker.md +++ b/docs/canary/deployment/docker.md @@ -16,7 +16,7 @@ caching **will** cause your project to not function correctly. Here is an example `Dockerfile` for a Fresh project: ```dockerfile Dockerfile -FROM denoland/deno:1.38.3 +FROM denoland/deno:latest ARG GIT_REVISION ENV DENO_DEPLOYMENT_ID=${GIT_REVISION} @@ -24,11 +24,12 @@ ENV DENO_DEPLOYMENT_ID=${GIT_REVISION} WORKDIR /app COPY . . -RUN deno cache main.ts +RUN deno task build +RUN deno cache _fresh/server.js EXPOSE 8000 -CMD ["run", "-A", "main.ts"] +CMD ["serve", "-A", "_fresh/server.js"] ``` To build your Docker image inside of a Git repository: diff --git a/docs/canary/deployment/production.md b/docs/canary/deployment/index.md similarity index 100% rename from docs/canary/deployment/production.md rename to docs/canary/deployment/index.md diff --git a/docs/canary/examples/active-links.md b/docs/canary/examples/active-links.md new file mode 100644 index 00000000..81b82e07 --- /dev/null +++ b/docs/canary/examples/active-links.md @@ -0,0 +1,48 @@ +--- +description: | + Style active links with ease in Fresh +--- + +Fresh automatically enhances the accessibility of `` elements by adding the +aria-current attribute when rendering links that match the current URL. This +attribute is recognized by assistive technologies and clearly indicates the +current page within a set of pages. + +- `aria-current="page"` - Added to links with an exact path match, enhancing + accessibility by indicating the current page to assistive technologies. + +As we aim to improve accessibility, we encourage the use of aria-current for +styling current links where applicable. + +## Styling with CSS + +The aria-current attribute is easily styled with CSS using attribute selectors, +providing a native way to visually differentiate the active link. + +```css +/* Give links pointing to the current page a green color */ +a[aria-current="page"] { + color: green; +} + +/* Color all ancestor links of the current page */ +a[aria-current="true"] { + color: peachpuff; +} +``` + +## Tailwindcss + +In Tailwindcss or similar CSS frameworks, you can apply styles to elements with +the `aria-current` attribute using bracket notation in your class definitions. +For Tailwindcss, use the syntax: + +```tsx +function Menu() { + return ( + + Link to some page + + ); +} +``` diff --git a/docs/canary/examples/markdown.md b/docs/canary/examples/markdown.md new file mode 100644 index 00000000..eec4607f --- /dev/null +++ b/docs/canary/examples/markdown.md @@ -0,0 +1,59 @@ +--- +description: | + How to render markdown on your Fresh site. +--- + +[Markdown](https://www.markdownguide.org/basic-syntax/) is a common text-based +file format that is often used for writing documentation, blogs and more. In +this example we are going convert markdown content to HTML and send it to the +browser. + +First, let's install the [`@deno/gfm`](https://jsr.io/@deno/gfm) package that +can transform markdown to html. + +1. Run `deno install jsr:@deno/gfm` +2. Create a markdown file like `content.md`: + +```md +## some heading + +and some interesting text here + +> oh look a blockquote +``` + +4. Add a route that renders that file + +```tsx +import { CSS, render as renderMarkdown } from "@deno/gfm"; + +const CONTENT = `## some heading + +and some interesting text here + +> oh look a blockquote +`; + +const app = new App(); + +app.get("/", async (ctx) => { + const content = await Deno.readTextFile("path/to/content.md"); + const html = renderMarkdown(content); + + return await ctx.render( +
+

Here comes a markdown post:

+