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"
/>
This commit is contained in:
Christian Svensson
2025-08-01 09:07:42 +02:00
committed by GitHub
parent 1cecb372a6
commit a2de5154ec
57 changed files with 280 additions and 214 deletions
+18 -17
View File
@@ -19,12 +19,13 @@ In this example we'll be creating a small API that uses
Our project structure will look like this (in addition to the rest of the Fresh
code from a new project):
```txt Project Structure
routes
└── api
└── users
├── [id].ts
└── index.ts
```txt-files Project Structure
<project root>
└── routes
└── api
└── users
├── [id].ts
└── index.ts
```
In each section about a method, only the relevant handler will be shown. The
@@ -50,7 +51,7 @@ Test this with Postman (or your favorite client) with a URL like
`http://localhost:8000/api/users` and a method of `POST`. Make sure to have a
payload like:
```json
```json Request body
{
"id": "2",
"name": "TestUserName"
@@ -59,7 +60,7 @@ payload like:
You should receive the same thing back:
```json
```json Response body
{ "id": "2", "name": "TestUserName" }
```
@@ -82,7 +83,7 @@ export const handler: Handlers<User | null> = {
Let's practice retrieving our user! A `GET` request to
`http://localhost:8000/api/users/2` should return:
```json
```json Response body
{ "id": "2", "name": "TestUserName" }
```
@@ -116,7 +117,7 @@ export const handler: Handlers<User | null> = {
Time to change their name. We'll now `PUT` a request to
`http://localhost:8000/api/users/2` like:
```json
```json Request body
{
"id": "2",
"name": "New Name"
@@ -125,14 +126,14 @@ Time to change their name. We'll now `PUT` a request to
We should receive:
```json
```json Response body
{ "id": "2", "name": "New Name" }
```
If, on the other hand, we chose to implement this as a `PATCH` operation, the
request would just involve the changed property like this:
```json
```json Response body
{
"name": "New Name"
}
@@ -161,7 +162,7 @@ export const handler: Handlers<User | null> = {
Try sending `DELETE` to `http://localhost:8000/api/users/2` without a body.
We'll get back:
```txt
```txt Response body
user 2 deleted
```
@@ -174,9 +175,9 @@ request checks for complex CORS use cases. See more on the
## Full File Reference
<details>
<summary>[id].ts</summary>
<summary><code>[id].ts</code></summary>
```ts
```ts routes/api/users/[id].ts
import { Handlers } from "$fresh/server.ts";
type User = {
@@ -218,9 +219,9 @@ export const handler: Handlers<User | null> = {
</details>
<details>
<summary>index.ts</summary>
<summary><code>index.ts</code></summary>
```ts
```ts routes/api/users/index.ts
import { Handlers } from "$fresh/server.ts";
type User = {