|
|
@@ -165,6 +165,56 @@ func TestFeed(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestHeaderAndFooter(t *testing.T) {
|
|
|
+ srv, dir := newTestServer(t, sample)
|
|
|
+ for _, path := range []string{"/", "/posts/middle", "/about", "/nope"} {
|
|
|
+ _, _, body := get(t, srv, path)
|
|
|
+ for _, want := range []string{
|
|
|
+ `<a class="home" href="/">Home</a>`,
|
|
|
+ `<nav><a href="/about">About</a></nav>`,
|
|
|
+ "<footer class=\"site\">\n <a href=\"/feed.xml\">RSS</a>\n</footer>",
|
|
|
+ } {
|
|
|
+ if !strings.Contains(body, want) {
|
|
|
+ t.Errorf("%s: missing %q", path, want)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ writeFile(t, dir, "site.json", `{"homeText": "All <posts>"}`)
|
|
|
+ if _, _, body := get(t, srv, "/"); !strings.Contains(body, `<a class="home" href="/">All <posts></a>`) {
|
|
|
+ t.Errorf("configured home text not used (or not escaped):\n%s", body)
|
|
|
+ }
|
|
|
+ if status, _, _ := get(t, srv, "/posts/site"); status != 404 {
|
|
|
+ t.Error("site.json should not be treated as a post")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestAboutPage(t *testing.T) {
|
|
|
+ srv, _ := newTestServer(t, sample)
|
|
|
+ status, _, body := get(t, srv, "/about")
|
|
|
+ if status != 200 {
|
|
|
+ t.Fatalf("status = %d", status)
|
|
|
+ }
|
|
|
+ for _, want := range []string{
|
|
|
+ "<title>About · posts.example.com</title>",
|
|
|
+ "<dt>Version</dt>\n <dd>" + version,
|
|
|
+ "<dt>Posts</dt>\n <dd>3</dd>",
|
|
|
+ `<dd><a href="/posts/newest">Newest</a>`,
|
|
|
+ `<h2 id="the-header-block">The header block</h2>`,
|
|
|
+ `<h2 id="what-markdown-works">What Markdown works</h2>`,
|
|
|
+ } {
|
|
|
+ if !strings.Contains(body, want) {
|
|
|
+ t.Errorf("missing %q in:\n%s", want, body)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ empty, _ := newTestServer(t, nil)
|
|
|
+ _, _, body = get(t, empty, "/about")
|
|
|
+ if !strings.Contains(body, "<dd>0</dd>") || strings.Contains(body, "Latest post") {
|
|
|
+ t.Errorf("empty site: expected 0 posts and no latest post:\n%s", body)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestReloadsWhenContentChanges(t *testing.T) {
|
|
|
srv, dir := newTestServer(t, map[string]string{"2026-01-01-one.md": "# One\n"})
|
|
|
if _, _, body := get(t, srv, "/"); strings.Contains(body, "Two") {
|