# MEDIA.md — hosting, media & Cloudflare

Where the site lives, where media lives, and how to add audio, video and images without ever
making the core pages heavier.

```
Namecheap ....... domain registration only
   │ nameservers → Cloudflare (DNS + CDN + DDoS)
   ▼
Cloudflare Pages → tsunamiunleashed.com
   • the hand-built pages, and the generated feeds/
Cloudflare R2 ... → media.tsunamiunleashed.com   (public bucket, no egress fees)
   • audio/  video/  img/   — everything large
External (opt-in) → YouTube / Vimeo, reached only when a visitor clicks a facade
```

**Why media is not in the repo.** Cloudflare Pages caps a single file at **25 MiB**, and a git repo
is a poor home for large binaries regardless. R2 has no egress fees, so a sermon that gets shared
widely costs nothing extra to serve. Media is therefore *linked* by absolute URL from pages and
feeds — never bundled.

---

## Part 1 — Adding media to an item

Upload the file first (Part 3), then add the matching block to a `content/*.md` front-matter.
Media URLs may be absolute, or a path relative to `media_base` — `audio/baptism-01.mp3` becomes
`https://media.tsunamiunleashed.com/audio/baptism-01.mp3`.

### Audio — this makes the item a podcast episode

```yaml
audio:
  url: audio/baptism-01.mp3
  type: audio/mpeg
  length: 41231234        # bytes — REQUIRED, see below
  duration: "00:32:10"
```

Any feed containing an audio item automatically becomes a podcast: `feeds/baptism.xml` is both the
baptism RSS feed and the baptism podcast. `feeds/audio.xml` collects every audio item regardless of
topic.

**`length` must be the true byte count.** Podcast apps use it to size the download, and a wrong
number can break playback. Two ways to get it right:

```sh
python build_feeds.py --head     # asks the server for Content-Length
```

or read it locally and paste it in — `ls -l file.mp3`, or on Windows
`(Get-Item file.mp3).Length`. Prefer pasting it into the front-matter: `--head` makes the build
depend on a server's answer, which is the one thing that can make output non-deterministic. Use
`--head` to *discover* the number once, then write it down.

If an audio item has no `length` and you do not pass `--head`, the build **fails and tells you
which file** — it will not publish an episode podcast apps would reject.

### Self-hosted video

```yaml
video:
  url: video/the-gathering.mp4
  type: video/mp4
  length: 88112233
  duration: "00:06:40"
  poster: img/the-gathering-poster.jpg    # first-party thumbnail
```

### External video (YouTube / Vimeo)

```yaml
embed:
  provider: youtube        # youtube | vimeo
  id: dQw4w9WgXcQ          # 11 chars for YouTube; digits for Vimeo
  poster: img/lesson-poster.jpg
```

The item's `link` becomes the watch URL unless you set `link:` yourself. **The build warns if the
id is not the right shape** — that is how you catch the placeholder in
`content/eight-commands-hand-motions.md` before it ships as a dead link.

### Images

```yaml
images:
  - url: img/cards-love-god.jpg
    type: image/jpeg
    alt: "Two open hands lifted, with a small heart above them."
```

**Always write `alt`.** It is what a blind reader hears and what a visitor on a slow connection
reads instead of the picture. The build warns when it is missing. (`image: path.jpg` on its own is
accepted as shorthand for a single entry.)

### Where each one ends up

RSS 2.0 allows **one `<enclosure>` per item**, so it is reserved for the primary audio, or the
primary self-hosted video when there is no audio. Everything else travels as Media RSS:

| Front-matter | In the feed |
|---|---|
| `audio` | `<enclosure>` + `<itunes:duration>` + a "Listen" link in the body |
| `video` (no audio) | `<enclosure type="video/…">` + `<media:thumbnail>` |
| `video` (alongside audio) | `<media:content medium="video" duration fileSize>` + `<media:thumbnail>` |
| `embed` | `<media:content>` (watch URL) + `<media:player>` (embed URL) + `<media:thumbnail>`, and a poster **linked** to the watch page in the body — never an auto-playing iframe |
| `images` | `<media:content medium="image">` + `<media:thumbnail>` each, plus inline `<img alt>` |

---

## Part 2 — Putting media on a page

`media.html` is the working reference; copy its patterns. Three rules, and they are the whole point:

1. **Nothing loads until the visitor acts.** `<audio preload="none">`,
   `<video preload="none" poster=…>`, `loading="lazy"` on images. Opening a page must not pull media
   bytes.
2. **Nothing third-party until a click.** A YouTube video is a **click-to-load facade**: a
   first-party poster inside a `<button>`, and the `youtube-nocookie.com` iframe is created only on
   click. Always also render a visible "Watch on YouTube ↗" link and a `<noscript>` note, so
   no-JavaScript and low-bandwidth visitors are never stranded.
3. **The core five pages stay self-contained.** `index.html`, `walk.html`, `map.html`,
   `helpers.html` and `life-with-god.html` make **zero** external requests on load and pull no
   raster media. Media is additive: it belongs in feed items and on media pages. A plain hyperlink
   from a core page is fine — links do not fetch.

`media.html`'s posters are **inline SVG data URIs**, so even the media page costs no requests until
you press play. That is not a placeholder trick; it is worth keeping.

---

## Part 3 — Cloudflare R2 (the media bucket)

**One-time setup**

1. Cloudflare dashboard → **R2** → *Create bucket* → name it `tu-media`. Pick a location hint near
   most of your audience.
2. In the bucket → **Settings** → **Public access** → *Custom Domains* → **Connect Domain** →
   `media.tsunamiunleashed.com`. Cloudflare adds the DNS record itself if the domain's nameservers
   already point at Cloudflare (Part 4). Wait for it to show **Active**.
   - Use a custom domain rather than the `r2.dev` development URL: `r2.dev` is rate-limited and not
     meant for production, and a custom domain is what gets CDN-cached with **no egress fees**.
3. Create the folders as you upload: `audio/`, `video/`, `img/`.

**Uploading**

Dashboard drag-and-drop works. From a terminal:

```sh
npx wrangler r2 object put tu-media/audio/baptism-01.mp3 \
  --file ./baptism-01.mp3 \
  --content-type audio/mpeg \
  --cache-control "public, max-age=31536000, immutable"
```

`rclone` or any S3-compatible tool works too, via an R2 API token.

**Cache headers.** Set `Cache-Control: public, max-age=31536000, immutable` on media objects. That
is safe *only* because filenames are versioned — `baptism-01.mp3`, then `baptism-02.mp3`. **Never
overwrite a file in place** with a new recording: caches and podcast apps will keep the old one.
Upload under a new name and update the front-matter.

**Watch the free tier.** Roughly 10 GB of storage. Audio is cheap; video is not. If a video library
grows, move to **Cloudflare Stream** (adaptive streaming, paid per minute stored and delivered) or
keep video on YouTube and use the facade — no storage cost, and nothing third-party until a click.
For low-bandwidth audiences, prefer **audio plus a link** over video, and never autoplay.

**After uploading**

```sh
python build_feeds.py --head    # picks up byte lengths; paste them into front-matter
python build_feeds.py           # deterministic rebuild
python build_feeds.py --check   # confirms nothing is stale
```

---

## Part 4 — Cloudflare Pages + DNS

See the step-by-step in the README's deploy section. In short: keep the registration at Namecheap,
point its nameservers at Cloudflare, connect this repo to a Pages project with
`python build_feeds.py --check` as the build command, and add `tsunamiunleashed.com` as the custom
domain.

Pages serves from a **private** repo on the free plan, so the repo stays private while the site is
public.

---

## Podcast submission checklist

Feeds are valid and playable in any podcast app right now. Before submitting to Apple or Spotify,
two config values in `feeds.config.yaml` must be filled in — the generator warns on every run until
they are:

- **`itunes_owner_email`** — Apple requires an owner email, and it becomes a **public** address
  inside the feed XML. Choose deliberately: use the ministry ProtonMail address, never a personal
  one. Given where this material travels and who carries it, this is a safeguarding decision rather
  than a formality.
- **`itunes_image`** — square artwork, **1400–3000 px**, JPEG or PNG, uploaded to R2. May be a path
  relative to `media_base`, e.g. `img/podcast-cover.jpg`.

Then verify:

```
[ ] feed passes the W3C Feed Validator          https://validator.w3.org/feed/
[ ] feed passes a podcast validator             e.g. Cast Feed Validator / Podbase
[ ] enclosure length is the file's TRUE byte count
[ ] the episode downloads and plays from media.tsunamiunleashed.com in a real app
[ ] itunes:duration shows the right length
```

Apple Podcasts Connect and Spotify for Podcasters both ingest the **same feed URL** — e.g.
`https://tsunamiunleashed.com/feeds/audio.xml`. Nothing about the site changes when you submit.

---

CC0 1.0 Public Domain — keep it faithful to Scripture and worthy of Christ.
