From b3673ecd7865c9144b68e5bfd34318c98e398931 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 12 Jul 2026 17:46:15 -0600 Subject: include the title h1 in `.Sections` --- main_test.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'main_test.go') diff --git a/main_test.go b/main_test.go index f2aae0a..a1eda14 100644 --- a/main_test.go +++ b/main_test.go @@ -38,6 +38,8 @@ func TestMarkdownGFMFrontmatterTitleSectionsAndLinks(t *testing.T) { writeTestFile(t, root, "page.md", `--- summary: hello --- +> Read this first. + # My *Page* First paragraph with [local](other.md#part), [web](https://example.com/a.md), and [fragment](#part). @@ -56,13 +58,16 @@ First paragraph with [local](other.md#part), [web](https://example.com/a.md), an t.Fatal(err) } got := string(raw) - for _, want := range []string{"My Page", `href="other.html#part"`, `href="https://example.com/a.md"`, `href="#part"`, ""} { + for _, want := range []string{"My Page", "
", ""} { if !strings.Contains(got, want) { t.Errorf("output missing %q:\n%s", want, got) } } - if strings.Contains(got, "") { - t.Errorf("H1 duplicated or raw HTML rendered:\n%s", got) + if strings.Index(got, "
") > strings.Index(got, "") { + t.Errorf("raw HTML rendered:\n%s", got) } s := &site{root: root, pages: map[string][]*Page{}} @@ -75,7 +80,7 @@ First paragraph with [local](other.md#part), [web](https://example.com/a.md), an page = src.page } } - if page == nil || page.Meta["summary"] != "hello" || len(page.Sections) != 3 { + if page == nil || page.Meta["summary"] != "hello" || len(page.Sections) != 5 { t.Fatalf("unexpected page model: %#v", page) } } @@ -350,10 +355,14 @@ func TestGitignoreTracksOnlyCurrentGeneratedOutputs(t *testing.T) { func TestSortingFilteringSlicing(t *testing.T) { a := &Page{Title: "A", Meta: map[string]any{"post_date": "2024-01-01", "kind": "x"}, ModTime: time.Unix(1, 0)} - b := &Page{Title: "B", Meta: map[string]any{"post_date": "2025-01-01", "kind": "y"}, ModTime: time.Unix(2, 0)} + b := &Page{Title: "B", Meta: map[string]any{"post_date": "2025-01-01", "kind": "y"}, ModTime: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)} if got := sortPages([]*Page{a, b}, "post_date"); got[0] != b { t.Fatal("date sort") } + b.Meta["post_date"] = "invalid" + if got := sortPages([]*Page{a, b}, "post_date", "mod_time"); got[0] != b { + t.Fatal("date fallback sort") + } if got := filterPages([]*Page{a, b}, "kind", "x"); len(got) != 1 || got[0] != a { t.Fatal("filter") } -- cgit v1.3