fixed tests and add id to subtitles

This commit is contained in:
Erik Winter 2021-01-23 10:26:11 +01:00
parent 847cb6b115
commit a53b659b9f
4 changed files with 7 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import (
"html"
"strings"
"git.sr.ht/~ewintr/go-kit/slugify"
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
)
@ -34,7 +35,7 @@ func FormatBlock(block adoc.BlockElement) string {
}
return fmt.Sprintf("<p>%s</p>", text)
case adoc.SubTitle:
return fmt.Sprintf("<h2>%s</h2>", html.EscapeString(block.Text()))
return fmt.Sprintf("<h2 id=%q>%s</h2>", slugify.Slugify(block.Text()), html.EscapeString(block.Text()))
case adoc.SubSubTitle:
return fmt.Sprintf("<h3>%s</h3>", html.EscapeString(block.Text()))
case adoc.CodeBlock:

View File

@ -26,7 +26,7 @@ func TestFormatBlock(t *testing.T) {
{
name: "subtitle",
element: adoc.SubTitle("text"),
exp: "<h2>text</h2>",
exp: `<h2 id="text">text</h2>`,
},
{
name: "subsubtitle",

View File

@ -13,9 +13,11 @@ func TestPost(t *testing.T) {
docKind := adoc.KIND_NOTE
siteKind := site.Kind(docKind)
config := &site.SiteConfig{
BaseURL: "base_url",
KindMap: map[adoc.Kind]site.Kind{
docKind: siteKind,
},
PathsWithKind: true,
}
title := "title thing"
author := "author"
@ -60,7 +62,7 @@ func TestPost(t *testing.T) {
})
t.Run("full link", func(t *testing.T) {
test.Equals(t, "https://erikwinter.nl/notes/2020/title-thing/", post.FullLink())
test.Equals(t, "base_url/notes/2020/title-thing/", post.FullLink())
})
t.Run("html summary", func(t *testing.T) {
@ -90,7 +92,7 @@ func TestPost(t *testing.T) {
t.Run("xml post", func(t *testing.T) {
exp := &site.XMLPost{
Link: "https://erikwinter.nl/notes/2020/title-thing/",
Link: "base_url/notes/2020/title-thing/",
Title: "title thing",
DateFormal: "Mon, 28 Dec 2020 07:23:45 +0000",
Content: "<p>one</p>\n<p>two</p>\n",

View File

@ -57,11 +57,6 @@ func TestNewKind(t *testing.T) {
input: "article",
exp: adoc.KIND_ARTICLE,
},
{
name: "work note",
input: "work",
exp: adoc.KIND_WORK,
},
} {
t.Run(tc.name, func(t *testing.T) {
act := adoc.NewKind(tc.input)