|
|
@@ -197,36 +197,39 @@ func TestFeed(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestAuthor(t *testing.T) {
|
|
|
- srv, _ := newTestServer(t, map[string]string{
|
|
|
+ srv, dir := newTestServer(t, map[string]string{
|
|
|
"2026-01-01-anon.md": "# Anonymous\n",
|
|
|
- "2026-01-02-signed.md": "---\nauthor: Claude & co\n---\n# Signed\n",
|
|
|
+ "2026-01-02-signed.md": "---\nauthor: Ann & co\n---\n# Signed\n",
|
|
|
})
|
|
|
- _, _, index := get(t, srv, "/")
|
|
|
- if !strings.Contains(index, "</time> · by Claude & co</span>") {
|
|
|
- t.Errorf("index: author missing or unescaped:\n%s", index)
|
|
|
- }
|
|
|
- if strings.Count(index, " · by ") != 1 {
|
|
|
- t.Error("index: a post without an author should not show a byline")
|
|
|
- }
|
|
|
- _, _, post := get(t, srv, "/posts/signed")
|
|
|
- if !strings.Contains(post, "</time> · by Claude & co</span>") {
|
|
|
- t.Errorf("post page: author missing:\n%s", post)
|
|
|
- }
|
|
|
- if _, _, anon := get(t, srv, "/posts/anon"); strings.Contains(anon, " · by ") {
|
|
|
- t.Error("post page: byline shown without an author")
|
|
|
- }
|
|
|
- _, _, feed := get(t, srv, "/feed.xml")
|
|
|
- for _, want := range []string{
|
|
|
- `xmlns:dc="http://purl.org/dc/elements/1.1/"`,
|
|
|
- "<dc:creator>Claude & co</dc:creator>",
|
|
|
- } {
|
|
|
- if !strings.Contains(feed, want) {
|
|
|
- t.Errorf("feed: missing %q in:\n%s", want, feed)
|
|
|
+ check := func(defaultAuthor string) {
|
|
|
+ t.Helper()
|
|
|
+ _, _, index := get(t, srv, "/")
|
|
|
+ for _, want := range []string{"</time> · by Ann & co</span>", "</time> · by " + defaultAuthor + "</span>"} {
|
|
|
+ if !strings.Contains(index, want) {
|
|
|
+ t.Errorf("index: missing %q:\n%s", want, index)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if _, _, post := get(t, srv, "/posts/signed"); !strings.Contains(post, "</time> · by Ann & co</span>") {
|
|
|
+ t.Errorf("signed post: author missing:\n%s", post)
|
|
|
+ }
|
|
|
+ if _, _, anon := get(t, srv, "/posts/anon"); !strings.Contains(anon, "</time> · by "+defaultAuthor+"</span>") {
|
|
|
+ t.Errorf("anonymous post: want default author %q:\n%s", defaultAuthor, anon)
|
|
|
+ }
|
|
|
+ _, _, feed := get(t, srv, "/feed.xml")
|
|
|
+ for _, want := range []string{
|
|
|
+ `xmlns:dc="http://purl.org/dc/elements/1.1/"`,
|
|
|
+ "<dc:creator>Ann & co</dc:creator>",
|
|
|
+ "<dc:creator>" + defaultAuthor + "</dc:creator>",
|
|
|
+ } {
|
|
|
+ if !strings.Contains(feed, want) {
|
|
|
+ t.Errorf("feed: missing %q in:\n%s", want, feed)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if strings.Count(feed, "<dc:creator>") != 1 {
|
|
|
- t.Error("feed: dc:creator should be omitted when there is no author")
|
|
|
- }
|
|
|
+
|
|
|
+ check("Claude")
|
|
|
+ writeFile(t, dir, "site.json", `{"defaultAuthor": "Site Owner"}`)
|
|
|
+ check("Site Owner")
|
|
|
}
|
|
|
|
|
|
func TestHeaderAndFooter(t *testing.T) {
|