summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md156
1 files changed, 156 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a67f90d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,156 @@
+# mingyuet-server
+
+A minimal blogging server for **明月樓閒話 Mingyuet Comments**.
+
+You keep writing raw HTML — but only the *content* of each post. The server
+wraps it in the site layout (the table shell with the sidebar and footer
+that every page used to carry by hand), generates the index and archive
+pages, gives every post a permalink, and produces an RSS feed. No database:
+the content *is* the file system. No third-party Go dependencies either —
+just the standard library.
+
+One binary, two subcommands:
+
+```
+mingyuet-server convert [flags] one-time migration from the old static site
+mingyuet-server serve [flags] run the server
+```
+
+## Content root layout
+
+```
+<root>/
+ posts/*.html dated post fragments (your blog entries)
+ pages/*.html standalone page fragments (About, Special, Releases, ...)
+ static/* served verbatim (style.css, images, robots.txt, assets/, ...)
+ layout.html optional override of the embedded layout template
+```
+
+### Post fragments (`posts/`)
+
+A fragment is plain HTML — exactly what used to live *inside* a
+`<div class="entry">` — plus a few optional meta comments on their own
+lines at the top of the file:
+
+```html
+<!-- title: Some Raw Title (may contain HTML like <q>quotes</q> or <br />) -->
+<!-- id: optional-anchor-id -->
+<!-- alias: old-url-stem -->
+<!-- date: 2026-10-04 --> (only needed if the filename isn't a date)
+<!-- time: 21:05 +08:00 --> (optional; affects the pubDate in the RSS feed)
+<p>Your content. The date line is generated for you — don't write it;
+ on listing pages it's a link to the post's own page.</p>
+<!-- more -->
+<p>Everything after the marker only appears on the post's own page.</p>
+```
+
+* **File name = date.** `20261004.html` → dated 2026.10.4. To publish, just
+ drop the file into `posts/`; it appears within a few seconds
+ (`-scan-interval`), no restart needed.
+* **Several posts on one date:** give them suffixes in the order you want
+ them listed (newest first): `20261004-2.html` is listed *above*
+ `20261004-1.html`. If there is only one post that day, no suffix.
+* **`title:`** renders as the `<h1>` on both the listing and the post page
+ (and in `<title>` / RSS, tag-stripped). Omit it for untitled entries.
+* **`<!-- more -->`** splits excerpt from body. The listing page shows the
+ excerpt followed by a `>>> More` link to the post page; without the marker
+ the full content is shown inline, like the old short entries.
+* **`time:`** sets the post's clock time, used in the RSS `pubDate`
+ (without it the post is dated midnight UTC). Format: `HH:MM` or
+ `HH:MM:SS`, optionally followed by a zone — an IANA name
+ (`Asia/Hong_Kong`, `Europe/Dublin` — DST is applied for the post's
+ date, and the binary carries its own tz database so this works on any
+ host), `UTC`, or a fixed offset (`+08`, `+08:00`, `-0530`). No zone
+ means UTC. The site pages themselves keep showing just the date.
+* **`id:`** is the `id=` attribute of the entry `<div>` on listing pages
+ (used to preserve old `#pNN` anchors). Defaults to the filename stem.
+* **`alias:`** makes `/articles/<alias>.html` redirect to this post — used
+ to keep old inbound article links alive.
+* Use absolute paths for assets inside content (`/assets/...`), since
+ fragments render at several URL depths.
+
+### Page fragments (`pages/`)
+
+Mapped 1:1 to URLs: `pages/about.html` → `/about.html`,
+`pages/special/beatles.html` → `/special/beatles.html`. Optional
+`<!-- title: ... -->` sets the `<title>` suffix (e.g. `About`, or
+`Higgins's Guide to the Beatles :: Special`). Content renders inside the
+same layout.
+
+## URL map
+
+| URL | What |
+|---|---|
+| `/` (also `/index.html`) | newest `-page-size` posts + link to older collection |
+| `/archives/01.html`, `/archives/02.html`, ... | auto-generated older collections |
+| `/post/<name>.html` | permalink for one post (every post has one, titled or not) |
+| `/articles/<name>.html` | **301** to `/post/<name>.html` — matched by name *or* `alias:` |
+| `/feed.xml` (alias `/rss.xml`) | RSS 2.0, newest `-feed-items` posts; item title = `title:` meta or the date, description = post HTML, cut off after `-feed-maxlen` characters with a `(more on the source page)` note |
+| `/<pages path>` | page fragments |
+| anything else | looked up in `static/`, otherwise a themed 404 |
+
+## Migrating the old site (`convert`)
+
+```
+go build -o mingyuet-server .
+./mingyuet-server convert -src /path/to/old/site -dst /path/to/content-root
+./mingyuet-server serve -site /path/to/content-root -addr :8080 \
+ -base-url https://your.domain
+```
+
+The converter reads `index.html` and `archives/*.html`, extracts every
+`<div id="pNN" class="entry">` block, and merges each `>>> More` /
+`>> Read More` pointer with the article page it pointed to (the article's
+body becomes the post's post-page content; the old entry keeps its `pNN`
+id and gets an `alias:` for the article URL). Pages (`about.html`,
+`special.html`, `releases.html`, `special/*.html`) become fragments and
+static assets are copied (`assets/`, `releases/`, root-level non-HTML
+files). The source tree is never modified; it also prints a report of
+what went where and skips any article no entry points at.
+
+Notes:
+
+* Relative links inside content (`./assets/…`, `../assets/…`) are
+ rewritten to absolute `/assets/…` — fragments render at mixed depths
+ now. (This also fixes links that were already broken on the old
+ archive page.)
+* Same-date entries get `-1`/`-2` suffixes arranged to preserve the
+ original display order.
+* With the current content this yields 43 posts; the index shows the
+ same 22 entries as before and `archives/01.html` the same 21.
+* Orphan article `20251108.html` / `20251121.html` are reported and
+ skipped: nothing links to them (their live counterparts are the
+ `special/` pages, which the converter does import).
+
+## Running (`serve`)
+
+| Flag | Default | Meaning |
+|---|---|---|
+| `-addr` | `:8080` | listen address |
+| `-site` | `./site` | content root |
+| `-base-url` | `http://localhost:8080` | public URL used for RSS links |
+| `-page-size` | `22` | posts per page (matches the old index) |
+| `-feed-items` | `25` | RSS items |
+| `-feed-maxlen` | `2000` | cut RSS descriptions longer than this many characters, ending with a `(more on the source page)` note (0 = never cut) |
+| `-rate` | `60` | max requests per client IP per `-rate-window` |
+| `-rate-window` | `1m` | rate limit window |
+| `-trust-proxy` | off | take client IP from `X-Forwarded-For` (use **only** behind your own reverse proxy, otherwise clients can spoof it) |
+| `-scan-interval` | `5s` | how often to rescan `posts/` and `pages/` |
+
+### Anti-abuse rate limiting
+
+Every request counts against a fixed per-IP window (`-rate` requests per
+`-rate-window`, default 60/minute). Over the limit the server answers
+`429 Too Many Requests` with a `Retry-After` header until the window rolls
+over. State is in memory only. If you run behind nginx/caddy/etc., pass
+`-trust-proxy` so the limit applies to real client IPs rather than the
+proxy's.
+
+### Layout override
+
+Drop a `layout.html` into the content root to change the site shell (the
+embedded default replicates the original hand-written one, plus an RSS
+`<link>` in `<head>`). It must use the `{{.FullTitle}}`, `{{.Root}}` and
+`{{.Content}}` template actions. `{{.Root}}` is the correct relative prefix
+for the page's depth (`./`, `../`, ...), so the same template works at any
+depth. \ No newline at end of file