# Writing guides

> Everything you can use in a guide page, with the Markdown that makes it.

Source: https://aminbytes.dev/bytes/getting-started/writing-docs/


This page is a cheat sheet for writing guides here. Every feature below shows the Markdown that produces it.

## Topics, parts and pages

Bytes are organized in three levels. Every folder is a level, and every folder has an `_index.md`:

```text
content/bytes/
├── _index.md                        ← the Bytes landing page
└── http/                            ← a topic: "How HTTP works"
    ├── _index.md                    ← topic title, intro text, order
    ├── basics/                      ← a part: "The basics"
    │   ├── _index.md
    │   ├── what-is-http.md          ← a page (step 1)
    │   ├── anatomy-of-a-url.md      ← step 2
    │   └── request-response-cycle/  ← a page with images gets its own folder
    │       ├── index.md
    │       └── cycle.svg
    └── requests/                    ← next part
        ├── _index.md
        └── http-methods.md
```

- A **topic** gets a card on the Bytes page and its own sidebar.
- A **part** groups pages under a heading in the sidebar.
- **Pages** are numbered as steps ("Step 3 of 9") in reading order, with Previous/Next links that run through the whole topic.

You can nest parts inside parts, and a topic can also hold pages directly without any parts.

### Order with `weight`

Every `_index.md` and page has a `weight`. Lower comes first:

```yaml {title="content/bytes/http/requests/_index.md"}
---
title: "Requests"
description: "What the client sends: methods, headers and data."
weight: 2
---
```

```yaml {title="content/bytes/http/requests/http-methods.md"}
---
title: "HTTP methods"
description: "Shown under the title, in the outline and in search results."
weight: 1
---
```

### Adding things

```bash
hugo new content bytes/http/requests/cookies.md
```

To start a new topic, create `content/bytes/<topic>/_index.md` with a `title`, `description`, `weight` and an intro. Give it a `color` (indigo, teal, amber, violet, rose or sky) and an `icon`: they style its animated cover, its cards and its share images. See `brand/README.md` for which color fits which kind of topic. Its landing page shows the intro, a **Start reading** button and a numbered outline of every page.

### Linking between pages

Use relative links to the folder of the page:

```markdown
See [status codes](../../responses/status-codes/).
```

## Code blocks

### Filename tab

Add a `title` after the language:

````markdown
```js {title="src/app.js"}
console.log("hi")
```
````

```js {title="src/app.js"}
const app = createApp();
app.listen(3000, () => console.log("listening on :3000"));
```

### Highlighting lines

Use `hl_lines` to draw attention to specific lines:

````markdown
```go {hl_lines="6-7"}
````

```go {hl_lines="6-7"}
package main

import "fmt"

func main() {
	total := 0
	for i := 1; i <= 10; i++ {
		total += i
	}
	fmt.Println(total)
}
```

### Line numbers

Code longer than two lines gets line numbers automatically. Shell snippets don't. Turn them off with `{lineNos=false}` or start from another number with `{linenostart=40}`.

```bash
hugo new content bytes/http/requests/cookies.md
./dev.sh
```

## Callouts

Use GitHub-style alerts for side notes:

```markdown
> [!NOTE]
> Useful information the reader should notice.
```

> [!NOTE]
> Useful information the reader should notice, even when skimming.

> [!TIP]
> A better or easier way to do something.

> [!IMPORTANT]
> Something the reader needs to know to succeed.

> [!WARNING]
> Something that can go wrong if they're not careful.

> [!CAUTION]
> Something that can break things or lose data.

> [!TIP] Custom title
> Write your own title after the type.

## Images

Put the image in the page's folder and reference it by name. The text in quotes becomes the caption. Click an image to zoom in.

```markdown
![Request flow from browser to server](diagram.svg "A request travels from the browser to the server and back")
```

![Request flow from browser to server](diagram.svg "A request travels from the browser to the server and back")

## Tables

| Syntax          | Result              |
| --------------- | ------------------- |
| `**bold**`      | **bold**            |
| `*italic*`      | *italic*            |
| `` `code` ``    | `code`              |
| `[link](url)`   | [link](#tables)     |

## Glossary terms

Wrap a term to give it a hover card with its short definition. The definitions live in `data/glossary.yaml`, and every term also gets an entry on the [Glossary](/glossary/) page, with the bytes that use it.

```markdown
The browser asks a {{< g "dns" />}} resolver for the address.
Computers connect to {{< g "ip-address" >}}IP addresses{{< /g >}}, not names.
```

The browser asks a DNS resolver for the address. Computers connect to IP addresses, not names.

To add a term, add an entry to `data/glossary.yaml` with a `term`, a one- or two-sentence `def` and the page that explains it best in `see`. A typo in a term's id stops the build with a clear message, so broken terms never go live.

## Margin notes

For a fun fact or an aside that would interrupt the sentence:

```markdown
HTTP has a status code for teapots.{{< note >}}`418 I'm a teapot`, from a 1998 April Fools' joke.{{< /note >}}
```

HTTP has a status code for teapots. (Side note: `418 I'm a teapot`, from a 1998 April Fools' joke.) It shows as a small number after the sentence: hover it, or tap it on a phone, and the note opens in a little card. It never takes extra space on the page.

## Byte check

A short quiz at the end of a byte. Getting every answer right **commits** the byte to the reader's [learning path](/path/), so put two or three questions in the front matter of every byte:

```yaml {title="content/bytes/http/requests/http-methods.md"}
---
title: "HTTP methods"
check:
  - q: "Which method should **never** change data on the server?"
    options: ["`GET`", "`POST`", "`DELETE`"]
    answer: 0             # the right option, counting from 0
    why: "`GET` is *safe*, so browsers and crawlers may send it freely."
---
```

Bytes without a `check` end with a **Commit this byte** button instead. It unlocks once the reader has spent about a third of the reading time on the page and reached the end, so a quick scroll doesn't count. Either way, a committed byte can be undone with **git reset**.

## Interactive examples

Two "Try it" widgets you can drop into any page:

```markdown
{{< url-explorer >}}
{{< url-explorer "https://example.com/search?q=http#results" >}}

{{< http-builder >}}
{{< http-builder method="POST" path="/todos" >}}
```

- **`url-explorer`** takes a URL apart, colors each part and shows the request the server actually receives.
- **`http-builder`** sends requests to a pretend to-do API that runs in the reader's browser, and shows the raw request and response.

## Byte cards

Give a topic up to five `takeaways` (each under ~100 characters). The topic page then shows a shareable image card with a download button:

```yaml {title="content/bytes/http/_index.md"}
takeaways:
  - "HTTP is plain text: a client sends a request, the server sends one response."
  - "Status codes by first digit: 2xx worked, 3xx look elsewhere, 4xx your mistake, 5xx theirs."
```

Every page also gets its own link preview image automatically, with its title on the AminBytes background. To change their design, edit `brand/src/og.py` and run `python3 brand/src/og.py`.


