Commit Graph
327 Commits
Author SHA1 Message Date
Marvin Hagemeister f27f10fbcb docs: fix duplicate line (#3215) 2025-08-12 12:34:15 +02:00
Marvin Hagemeister 477fcefed4 feat: support inlining FRESH_PUBLIC_ env vars (#3214)
Fixes https://github.com/denoland/fresh/issues/3213
2025-08-12 12:00:59 +02:00
Marvin Hagemeister 27e407a1e3 feat: add define.layout helper (#3198) 2025-08-06 15:23:18 +02:00
Roscoe Rubin-Rottenberg a5205b2a8e docs: add correct ctx.state example to init and docs (#3147)
- Correct outdated, non-functional and confusing "Removal of <Head>
component" section of migration guide in the docs to be real functional
code that uses Fresh 2 and define helpers correctly
- Added example of ctx.state being used for a head component (title)
because it's something almost every single project will need to know how
to do.
- Small change to define docs use of define.page to be more in line with
its use commonly
- Removed mention of deno-puppeteer - a non-official repository that
hasn't been updated in three years - needing to be installed from
`CONTRIBUTING.md`
2025-08-06 00:17:24 +02:00
Christian Svensson b7f1abb0d0 test(docs): type check docs code examples (#3180)
This PR adds the initial seeds of type checking the code in all code
blocks for the Markdown Docs.

- Adds a unit test, disabled due to the many remaining errors, that can
help find incorrect code
- Fixes a bunch of syntax errors, type errors, and other code issues
found in the docs

## Future improvements

A lot of remaining issues is mostly related to missing imports, e.g.
`App`, `staticFiles`, `HttpError` etc. There's a couple of different
directions to solve this in future PR's.

- Add explicit imports to all docs examples (may become unnecessarily
verbose)
- Add code to docs code blocks, but with a hint to remove it when
rendering the markdown as HTML
   ```tsx
   import { App } from "fresh";
   // #docs-start

   // Everything above marker above is trimmed away
   const app = new App();
   ```
- Add a `types.d.ts` with "global" types used during type checking, so
globals, imports and so on can be handled globally

I do think that some examples probably should be more explicit with
imports, but it would be overkill for a lot of places such as `app.md`
and `context.md`.
2025-08-05 23:56:04 +02:00
Christian Svensson e014d80a0f docs: add canary docs for <head> modifications (#3173)
Adds v2 version of "Modyfing the <head>" example. This is the next to
last page that needs to be updated (though the other only requires minor
changes to types).
2025-08-05 23:50:58 +02:00
Marvin Hagemeister 71b7d922ea fix: add deno compile entry (#3189)
Fixes https://github.com/denoland/fresh/issues/3123
2025-08-05 14:53:08 +02:00
Christian SvenssonandMarvin Hagemeister 57596dc406 feat: support passing URL to islands (#3181)
Adds support for passing `URL` values to Islands.

```tsx
// routes/index.html
export default function Page() {
  return <MyIsland url={new URL("https://fresh.deno.dev")} />;
}
```

Also updates documentation with some missing serialization features
(`undefined`, `Map`, `Set`, and `-0`).

---------

Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
2025-08-03 20:42:50 +02:00
Christian Svensson 24c86ea20e fix: correct anchors by using heading text only (#3167)
Addresses the issue mentioned in
https://github.com/denoland/fresh/pull/3163#discussion_r2246708003.

The issue was that the `raw` markdown was being used for e.g. `## My
title`, thus the slug became `-my-title` instead of `my-title`. Slugs
were working correctly for `codespan` in headers, e.g. ``## `someCode`
``.

I decided to hard error if unexpected heading syntax is used over
sluggifying unexpected content (can become super weird otherwise, e.g.
`## <button ...>My heading</button>`). I can revert to fallbacking to
`raw` if preferred, but perhaps with at least trimming leading `-` just
in case.
2025-08-01 12:46:12 +02:00
Christian Svensson a2de5154ec fix(docs): improve and increase consistency for code blocks (#3163)
Follow-up from #3162.

This PR does various tweaks, mostly related to code blocks.

- Adds missing titles to code blocks, and updates titles to be more
consistent
- Adds filenames to most ` ```tsx` blocks with e.g. `main.ts`, `dev.ts`
or a suitable example (e.g. `routes/greeting.tsx`) based on the code
- Adds filenames to ` ```diff` blocks if there's a relevant file, to
make the icon e.g. TS over Diff icon
  - Code blocks with Fresh code (e.g. interfaces) uses ` ```tsx fresh 🍋`
- Changes most ` ```sh` blocks with example terminal commands to ` ```sh
Terminal`
- Updates ` ```txt Project Structure` or ` ```diff Project Structure`
blocks to be more consistent
- Changes `sh` or `txt` to `txt-files` which improves highlighting and
makes icon consistent
- Renames `<project dir>` to `<project root>` to match builder `root`
option terminology
- Adds `<project root>` root folder to most/all overview folder
overviews
  - Makes the structure blocks more consistently displayed
- Tried to make some "bare" examples more complete

## Comparison

Here's a small curated set of before/after changes.

### Deployment

- `deno` highlighted in terminal commands
- `.gitignore` syntax highlighting works without using `sh` as language

<img width="1641" height="1009" alt="image"
src="https://github.com/user-attachments/assets/170cf833-1f6a-4b0d-8d2d-a081bc28a967"
/>

### File routing

Updated icon, comments same as before, but root and hierarchy have new
colors (`operator`/`function`).

<img width="1647" height="588" alt="image"
src="https://github.com/user-attachments/assets/f28db51b-4bee-45e4-be1c-e137a6d3ae3d"
/>
2025-08-01 09:07:42 +02:00
Christian Svensson c9b43ea32b feat(docs): add file/language type icons to code blocks (#3162)
I originally wanted to make it clearer the distinction between "files"
and e.g. `` ```tsx foo.tsx `` compared to `` ```sh Terminal `` or ``
```txt Project structure``. I originally started just trying to add a 📝
icon or something. But instead I ended showing file types of all
markdown languages.

I took the file type icons for the SVG's from
https://github.com/vscode-icons/vscode-icons, which has a MIT license.

I think the icons make it a even more clear what the language of the
code snippet is.

I have a follow-up PR for improving code block titles and making
examples more consistent in #3163.


## Comparisons

<details>

<summary><strong>Open &mdash; Before | After</strong></summary>


### TS + Shell icons - Hover tooltips and alt text

<img width="1504" height="639" alt="image"
src="https://github.com/user-attachments/assets/636838a3-f38c-4048-a536-52c1cdd6b6d4"
/>


### TS + Shell icons 2

<img width="1511" height="761" alt="image"
src="https://github.com/user-attachments/assets/2ad6d25c-3995-433a-ad93-162830ca55a1"
/>

### Shell + Dockerfile icons

<img width="1500" height="780" alt="image"
src="https://github.com/user-attachments/assets/88010749-d0d2-4498-9eb2-9bd971e48365"
/>

### Nested blocks + Git icon

<img width="1513" height="634" alt="image"
src="https://github.com/user-attachments/assets/400c27f8-d0b4-40bd-801d-611e1e8a8e36"
/>

</details>
2025-07-31 23:48:00 +02:00
Marvin Hagemeister 62f8bb008e docs: update Fresh 2 migration info (#3161) 2025-07-31 10:46:44 +02:00
Marvin Hagemeister 9d769f3cf1 feat: support setting production source maps on builder (#3151)
This adds a new `sourceMap` option on the `Builder` configuration. This
can be used to optionally specify how production source maps should be
generated.

See https://esbuild.github.io/api/#source-maps for more information.
2025-07-29 21:20:15 +02:00
Carlos GuzmanandMarvin Hagemeister 1218038918 docs: fix missing parentheses in about.tsx example file (#3143)
Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
2025-07-27 12:36:44 +02:00
e4d9160a92 docs: add daisyUI setup to examples (#3144)
Add a page to the docs on how to use https://daisyui.com/ with Fresh. 
---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-07-26 12:28:02 +00:00
Marvin Hagemeister b4e4a0c0f0 docs: update more pages for Fresh 2 (#3141) 2025-07-25 19:04:08 +02:00
Marvin Hagemeister c9c85ba36d docs: add page for define helpers (#3139) 2025-07-25 18:57:39 +02:00
Marvin Hagemeister 9e4dea516f docs: add csrf() page (#3138) 2025-07-25 16:59:22 +02:00
Marvin Hagemeister 3ad3e6ecf3 feat: support lazily loading routes/handlers (#3131)
We can improve cold start times by only loading route modules when the particular pattern matches. This PR introduces the concept of lazy middlewares, routes and handlers to do that.
2025-07-25 14:33:28 +02:00
Marvin Hagemeister d573622a40 feat: add separate tailwindcss v3 plugin (#3135)
Makes it easier to keep using tailwindcss v3 with newer Fresh versions.
2025-07-25 10:27:22 +02:00
Marvin Hagemeister 659d7687f0 docs: add builder docs (#3130) 2025-07-24 22:18:23 +02:00
Marvin Hagemeister e9f0a4bb0c docs: migration for createHandler (#3129)
Fixes https://github.com/denoland/fresh/issues/2986
2025-07-24 16:26:41 +02:00
Marvin Hagemeister 41b11de470 docs: update fs route (#3125) 2025-07-24 15:34:51 +02:00
Marvin Hagemeister 118242eaa6 major: build islands + scan routeDir without importing user code (#3122)
This fixes a bunch of long standing issues in our tracker where a build
wouldn't finish because of importing user code. It's common for backend
apps to spawn some open ended tasks like subscribing to Deno KV or other
things. This addresses another problem of having to set up ENV vars just
for the build, even though they are technically not required to build
islands.

This also gives a roughly ~30% performance boost on cold starts (at
least on `deno.com`). Unfortunately, this does require some breaking
changes. But I believe the performance improvements + removing the
footgun of loading user code during build is well worth it. This work is
also a precursor in case we want to exploring moving to vite at some
point in the future.

## Breaking changes

1. Build options have moved to the builder.
```diff
  // main.ts
- const app = new App({ build: { outDir: "dist/" } })
+ const app = new App()

  // dev.ts
- const builder = new Builder();
+ const builder = new Builder({ outDir: "dist/" });
```

2. Another breaking change is how file based routes are loaded. Since
they're prepared and loaded by the builder the API changed.

```diff
  // main.ts
  const app = new App()
    .use(staticFiles())
  
- await fsRoutes(app, {
-   loadIsland: (path) => import(`./islands/${path}`),
-   loadRoute: (path) => import(`./routes/${path}`),
- }); 
+ app.fsRoutes()
```
You can optionally change the `islandDir` or `routeDir` by passing that
to the `Builder`:

```ts
// dev.ts
const builder = new Builder({
  islandDir: "/path/to/islands", 
  routeDir: "/path/to/routes"
});
```

3. Import `app` lazily in `dev.ts`. Passing `app` to `builder.build()`
is not necessary anymore.

```diff
- import { app } from "./main.ts";

  const builder = new Builder({ target: "safari12" });
  
  if (Deno.args.includes("build")) {
-    await builder.build(app);
+    await builder.build();
  } else {
-   await builder.listen(app);
+   await builder.listen(() => import("./main.ts"));
  }
```

4. The production run command has changed. It's now using `deno serve`
```diff
  // deno.json
  {
    "tasks": {
      "dev": "deno run -A --watch=static/,routes/ dev.ts",
      "dev": "deno run -A dev.ts build",
-     "start": "deno run -A main.ts",
+     "start": "deno serve -A _fresh/server.js",
    }
  }
```
Remove this bit in `main.ts`:

```diff
  // main.ts
  
- if (import.meta.main) {
-   await app.listen()
- }
```

Fixes https://github.com/denoland/fresh/issues/2240
Fixes https://github.com/denoland/fresh/issues/2640
Fixes https://github.com/denoland/fresh/issues/2592
Fixes https://github.com/denoland/fresh/issues/1843
2025-07-24 15:04:05 +02:00
Marvin Hagemeister 96da1c5cd0 docs: add page for tailwindcss (#3120) 2025-07-21 19:32:25 +02:00
bb23643779 feat: support tailwindcss v4 (#3054)
update /www and tailwind-plugin to support tailwind v4.

Thanks to the merge of #3034, the work of integrating and advancing
#2903 is promoted.

related #3034 
related #2903 

close #3056
close #2819

--patch-1 
based on review,

1. del compiler and make it more clean and simple,
2.  fix init tailwind part,
3. fix test tailwind part

--patch-2

1. fix the docs 
2. fix the docs of plugin and version

--patch-3
1. Addressed various maintenance tasks (chores)
2. Updated the Tailwind CSS plugin to align with this release. Generated
a fresh project using the updated init configuration and
3. deployed it via Deno Deploy EA. Deployment is functioning correctly.

--patch-4
Move postcss imports to Tailwind section in init script

--patch-5
Refactored Tailwind plugin type definitions by copying PluginOptions
properties from @tailwindcss/postcss and adding Fresh-specific exclude
option, while exporting types from package entrypoint for better
accessibility.

Test Project: https://fresh.fresh-press.deno.net/
Test Project Repository:
https://github.com/SisyphusZheng/fresh-tailwindv4
Test Plugin: https://jsr.io/@freshpress/fresh-plugin-tailwind@1.0.0

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-07-21 16:13:34 +02:00
Marvin Hagemeister 39737b4530 fix: write matched pattern into ctx.route (#3113)
Fixes https://github.com/denoland/fresh/issues/3112
2025-07-18 22:38:56 +02:00
Weverton Marques 958b9528cc docs: fix: Change port to 3000 after setting PORT=3000 (#2828) 2025-07-18 19:14:56 +02:00
Marvin Hagemeister e6a5a5fabb docs: canary remove outdated csp page (#3111) 2025-07-18 18:42:53 +02:00
Marvin Hagemeister 79db6391f0 docs: update canary rendering raw HTML page (#3110) 2025-07-18 18:36:52 +02:00
Marvin Hagemeister 35b696d870 docs: update canary error handling (#3109) 2025-07-18 18:21:58 +02:00
Marvin Hagemeister a703e79181 docs: update canary docs for Fresh 2 (#3108)
There are still some rough edges here and there, but it's in a much
better shape than what we have today.
2025-07-18 15:18:38 +02:00
Zichao Lan 3c43d98a57 docs: update HandlerContext -> FreshContext (#3092)
'HandlerContext' is deprecated.deno-ts(6385)
2025-07-13 23:21:56 +02:00
zhizhengand李嘉图·M·路 8d3b8c53c6 docs: Update Fresh canary usage instructions in docs (#3067)
Revise documentation to clarify how to use the latest Fresh 2 canary,
specific commits, and forks via deno.json. Add instructions for creating
new projects using JSR and local sources, and update references to
current package versions. Include links to the Fresh v2 blog and
migration guide for further reading.

close #3058

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-30 12:27:53 +02:00
zhizheng 10400ff130 fix(www): quotes in markdown image alt causing html issues #3002 (#3003)
## Problem:
The problem was reproduced as described in #3002. Chrome DevTools shows
the following error:

props.js:137 Uncaught (in promise) InvalidCharacterError: Failed to
execute 'setAttribute' on 'Element': 'docs-content""' is not a valid
attribute name.
    at j (props.js:137:8)
    at V (index.js:528:5)
    at O (index.js:326:28)
    at I (children.js:97:16)
    at V (index.js:547:4)
    at O (index.js:326:28)
    at I (children.js:97:16)
    at V (index.js:547:4)
    at O (index.js:326:28)
    at I (children.js:97:16)

## Solution:
The issue was resolved by removing the double quotes around docs-content
in the Markdown image description. After this change, the application
resumed normal operation.

## Test:
Deno task ok and local env check

## Close:
close #3002
2025-06-04 19:32:31 +02:00
zhizhengand李嘉图·M·路 a631ae3876 Fix[docs] correct the broken links and errors in migration-guide (#3008)
Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-06-03 13:30:12 +02:00
Marvin Hagemeister e595d35c44 docs: simplify introduction content (#2978)
The original text is a bit wordy. This shortens the introduction content
a bit in our docs.
2025-05-21 11:32:50 +02:00
Brian Knight b6c02b0668 docs: Fix build command in deployment documentation (#2840)
The `Self Contained Executable` instructions in the `Deployment`
documentation contains an error in the sample code.

```sh Terminal
$ deno build
$ deno compile --include static --include _fresh --include deno.json -A main.ts
```

should be:

```sh Terminal
$ deno task build
$ deno compile --include static --include _fresh --include deno.json -A main.ts
```

This PR fixes that.
2025-05-19 13:28:48 +02:00
Sviatoslav M. 1321cda916 docs: update rendering-markdown.md (#2800)
When using deno add @deno/gfm outputs the following:
```
error: @deno/gfm is missing a prefix. Did you mean `deno add jsr:@deno/gfm`?
```
Then when jsr is specified:
```
deno add jsr:@deno/gfm
Add jsr:@deno/gfm@0.10.0
```

deno --version: 2.1.4
2025-05-19 13:20:10 +02:00
zhizhengand李嘉图·M·路 ebe65b035e docs(canary): clean the twind part for canary version (#2966)
## What does this PR do?

This PR cleans all the Twind - related parts in the canary
documentation. Specifically, it removes the Twind - related entries in
the docs/toc.ts file, which streamlines the documentation and eliminates
references to the Twind technology that might no longer be relevant or
in use.

## Problem Being Solved
Outdated Information: Twind removed from fresh v2. Keeping Twind -
related content in the documentation can lead to confusion for new users
who might be using the canary version of Fresh with Tailwind CSS.

## Changes Made
docs/toc.ts:
Removed the "migrating - to - tailwind" entry. 
Removed the "using - twind - v1" entry, which is directly related to
using the Twind v1 version and is no longer needed in the canary
documentation.
Removed the "using - fresh - canary - version" entry, which is no reason
in canary docs

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
2025-05-16 21:35:56 +02:00
Matt NieldandMarvin Hagemeister 107c25b79a chore: Update links (#2956)
This commit updates several links which are outdated and now redirect to
different URLs on the updated Deno website and documentation.

There are a few dozen instances of URLs starting with
`https:://deno.land/x` and `https:://deno.land/std`. I left these alone
since they are dependencies. Would it make sense to update these from
the versions hosted at `deno.land` to their JSR equivalents, since that
is the new and preferred location of the Deno Standard Library packages
as well as other JavaScript/TypeScript packages used by Deno projects?

For example, the latest version of the Deno Standard Library is now
hosted at `https://jsr.io/@std` instead of `https://deno.land/std`.


![image](https://github.com/user-attachments/assets/7416da3b-3867-4d8f-9a1a-79e6a11ddb46)

---------

Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
2025-05-15 19:24:27 +02:00
Asher Gomez 8ea3dbeac5 refactor(www): use useSignal() instead of useState() (#2894) 2025-05-12 23:28:46 +02:00
zhizheng 2b0f76be62 docs: improve styling for form submission example (#2899)
![before](https://github.com/user-attachments/assets/3936dcc6-d9f4-49e3-8b53-973a21eaadcd)

![after](https://github.com/user-attachments/assets/8abdb950-6473-4f0a-a27d-4a8b09229a57)

## Changes
- Added border and padding to the search input field for better
visibility
- Added light gray background and border to the search button for better
clickability

## Why
- The original styling makes it difficult to recognize the search input
field and button, as they appear as plain text elements without any
visual distinction.
2025-05-08 11:54:12 +02:00
Luca Casonato 03847e9a33 2.0.0-alpha.26 2024-12-10 16:05:22 +01:00
Ian Bull f1b6b4c401 doc: add information about deno compile (#2783) 2024-12-05 14:04:41 +01:00
Luca Casonato 6ee4551df1 2.0.0-alpha.25 2024-11-08 12:08:56 +01:00
Efe 22af15279d www: Fix block quotes not rendering links (#2712)
- Fixes a bug where block quotes were not able to properly render URLs
in docs (e.g. Info section at
https://fresh.deno.dev/docs/getting-started/create-a-route)
- Replaces existing JSX docs url with the suggested, up-to-date docs url

<img width="775" alt="image"
src="https://github.com/user-attachments/assets/e2e83456-697b-47d5-b074-66e4f287f17a">
2024-10-24 11:13:13 +02:00
Kyle Loveless e651ea514c docs: fix typo in islands/other-island.tsx (#2706)
very minor typo, but should still be fixed
2024-10-15 11:31:01 +02:00
Per Guth 4181ef3263 docs: fix formatting (#2707) 2024-10-15 11:30:29 +02:00
Marvin HagemeisterandLuca Casonato de8f1b0c59 feat: update for Deno 2 (#2655)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-09-30 18:30:30 +02:00