Commit Graph
69 Commits
Author SHA1 Message Date
Marvin Hagemeister fe4a59a88c feat: support custom server entry (#3216) 2025-08-12 12:50:10 +02:00
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
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
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
Mayank 364810def4 docs: fix typo in migration guide (#2578)
Just a stray underscore 😅
2024-07-05 16:54:58 +02:00
Luca Casonato c3ec742a65 feat: import fresh from fresh (#2479)
Instead of importing as `@fresh/core`.
2024-06-05 14:51:35 +02:00
Duncan Holm 67a3714db3 docs: Fix name of JSR update tool (#2468) 2024-05-25 12:33:28 +02:00
Marvin Hagemeister 5dd854341c www: add back trailing slash handling (#2467)
In Fresh 2 trailing slash handling isn't applied automatically anymore
and I forgot to do that when merging the Fresh 2 code base.

While we're at it, I've added a section for that to our migration guide.
2024-05-25 12:11:13 +02:00
Marvin HagemeisterandLuca Casonato 2b1de48ff1 docs: add Fresh 2 migration guide (#2459)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-05-24 21:09:51 +02:00
Marvin Hagemeister dace008611 chore: release 1.6.0 (#2113) 2023-12-01 16:20:40 +01:00
Marvin Hagemeister bd372b9535 fix: errors in plugin fixture + improve island docs (#2109) 2023-12-01 12:21:10 +01:00
Reed von RedwitzandMarvin Hagemeister 9ab8651018 feat(server): Add basePath config to host from a directory (#2092)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-29 16:44:25 +00:00
Marvin Hagemeister d62d22a4fc docs: fix link (#2087) 2023-11-28 22:50:48 +01:00
Marvin Hagemeister 79fd85ef93 docs: Add migrating to Tailwind CSS page (#2077) 2023-11-28 13:39:05 +01:00
Reed von Redwitz 72edafde46 feat(server): plugins can create islands (#1472) 2023-11-22 11:19:13 +01:00
Marvin HagemeisterandAdam Gregory 7ff2781fcd feat: allow plugins to modify HTML body (#2022)
Based on https://github.com/denoland/fresh/pull/1769 . Mostly added a
test.

---------

Co-authored-by: Adam Gregory <adam@aguilaengineering.com>
2023-11-10 13:59:41 +01:00
Adam Gregory 14cecc0a6f Allow plugin render hooks to add link tags to the page (#1963)
Adds an extra optional property to plugin render results to allow
plugins to add `<link>` tags to the page.
2023-11-08 23:51:14 +01:00
Adam GregoryandMarvin Hagemeister 264f3073bd Support AOT-built static assets (#1999)
Creates a static folder under `config.build.outDir` during AOT build.
Serves any static files that are found there.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-04 14:01:21 +01:00
Reed von Redwitz f39e0d4218 feat(server): throwing Deno.errors.NotFound triggers 404 (#1984) 2023-10-30 18:00:57 +01:00
Marvin Hagemeister fe2c95cc25 chore: release 1.5.0 (#1899) 2023-10-10 18:08:44 +02:00
Marvin Hagemeister 01e5f71058 docs: improve admonition styles (#1880) 2023-10-06 22:56:11 +02:00
Marvin Hagemeister 21fcf6169b docs: add partials documentation (#1878) 2023-10-06 22:55:54 +02:00