docs: update more pages for Fresh 2 (#3141)
This commit is contained in:
@@ -26,8 +26,8 @@ function AppWrapper({ Component }) {
|
|||||||
app.appWrapper(AppWrapper);
|
app.appWrapper(AppWrapper);
|
||||||
```
|
```
|
||||||
|
|
||||||
Every `ctx.render()` call will include the app wrapper component by default,
|
Every [`ctx.render()`](/docs/canary/concepts/context#render-1) call will include
|
||||||
unless opted out.
|
the app wrapper component by default, unless opted out.
|
||||||
|
|
||||||
Note that only one app wrapper component is supported per
|
Note that only one app wrapper component is supported per
|
||||||
[`App`](/docs/canary/concepts/app) instance.
|
[`App`](/docs/canary/concepts/app) instance.
|
||||||
|
|||||||
@@ -79,6 +79,12 @@ Pass data to the next middlewares with state. Every request has its own state
|
|||||||
object.
|
object.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
interface State {
|
||||||
|
text?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = new App<State>();
|
||||||
|
|
||||||
app.use((ctx) => {
|
app.use((ctx) => {
|
||||||
ctx.state.text = "foo";
|
ctx.state.text = "foo";
|
||||||
return ctx.next();
|
return ctx.next();
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ const app = new App()
|
|||||||
.use(staticFiles());
|
.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
|
## Caching headers
|
||||||
|
|
||||||
By default, Fresh adds caching headers for the `src` and `srcset` attributes on
|
By default, Fresh adds caching headers for the `src` and `srcset` attributes on
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ caching **will** cause your project to not function correctly.
|
|||||||
Here is an example `Dockerfile` for a Fresh project:
|
Here is an example `Dockerfile` for a Fresh project:
|
||||||
|
|
||||||
```dockerfile Dockerfile
|
```dockerfile Dockerfile
|
||||||
FROM denoland/deno:1.38.3
|
FROM denoland/deno:latest
|
||||||
|
|
||||||
ARG GIT_REVISION
|
ARG GIT_REVISION
|
||||||
ENV DENO_DEPLOYMENT_ID=${GIT_REVISION}
|
ENV DENO_DEPLOYMENT_ID=${GIT_REVISION}
|
||||||
@@ -24,11 +24,12 @@ ENV DENO_DEPLOYMENT_ID=${GIT_REVISION}
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN deno cache main.ts
|
RUN deno task build
|
||||||
|
RUN deno cache _fresh/server.js
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["run", "-A", "main.ts"]
|
CMD ["serve", "-A", "_fresh/server.js"]
|
||||||
```
|
```
|
||||||
|
|
||||||
To build your Docker image inside of a Git repository:
|
To build your Docker image inside of a Git repository:
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
---
|
||||||
|
description: |
|
||||||
|
Style active links with ease in Fresh
|
||||||
|
---
|
||||||
|
|
||||||
|
Fresh automatically enhances the accessibility of `<a>` 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 (
|
||||||
|
<a href="/foo" class="aria-[current]:text-green-600">
|
||||||
|
Link to some page
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -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(
|
||||||
|
<div>
|
||||||
|
<h1>Here comes a markdown post:</h1>
|
||||||
|
<style dangerouslySetInnerHTML={{ __html: CSS }} />
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: html }} />
|
||||||
|
</div>,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Other libraries
|
||||||
|
|
||||||
|
There are several other popular libraries besides `@deno/gfm` that can be used
|
||||||
|
to render markdown. The most common ones are:
|
||||||
|
|
||||||
|
- [marked](https://marked.js.org/)
|
||||||
|
- [remark](https://remark.js.org/)
|
||||||
+2
-3
@@ -59,7 +59,6 @@ const toc: RawTableOfContents = {
|
|||||||
title: "Deployment",
|
title: "Deployment",
|
||||||
link: "canary",
|
link: "canary",
|
||||||
pages: [
|
pages: [
|
||||||
["production", "Production builds", "link:canary"],
|
|
||||||
["deno-deploy", "Deno Deploy", "link:canary"],
|
["deno-deploy", "Deno Deploy", "link:canary"],
|
||||||
["docker", "Docker", "link:canary"],
|
["docker", "Docker", "link:canary"],
|
||||||
],
|
],
|
||||||
@@ -85,14 +84,14 @@ const toc: RawTableOfContents = {
|
|||||||
["migration-guide", "Migration Guide", "link:canary"],
|
["migration-guide", "Migration Guide", "link:canary"],
|
||||||
["modifying-the-head", "Modifying the <head>", "link:latest"],
|
["modifying-the-head", "Modifying the <head>", "link:latest"],
|
||||||
["creating-a-crud-api", "Creating a CRUD API", "link:latest"],
|
["creating-a-crud-api", "Creating a CRUD API", "link:latest"],
|
||||||
["rendering-markdown", "Rendering markdown", "link:latest"],
|
|
||||||
["rendering-raw-html", "Rendering raw HTML", "link:canary"],
|
["rendering-raw-html", "Rendering raw HTML", "link:canary"],
|
||||||
|
["markdown", "Markdown", "link:canary"],
|
||||||
[
|
[
|
||||||
"sharing-state-between-islands",
|
"sharing-state-between-islands",
|
||||||
"Sharing state between islands",
|
"Sharing state between islands",
|
||||||
"link:latest",
|
"link:latest",
|
||||||
],
|
],
|
||||||
["active-links", "Styling active links", "link:latest"],
|
["active-links", "Active links", "link:canary"],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user