fixed tests and add id to subtitles
This commit is contained in:
parent
847cb6b115
commit
a53b659b9f
|
@ -5,6 +5,7 @@ import (
|
||||||
"html"
|
"html"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.sr.ht/~ewintr/go-kit/slugify"
|
||||||
"git.sr.ht/~ewintr/shitty-ssg/pkg/adoc"
|
"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)
|
return fmt.Sprintf("<p>%s</p>", text)
|
||||||
case adoc.SubTitle:
|
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:
|
case adoc.SubSubTitle:
|
||||||
return fmt.Sprintf("<h3>%s</h3>", html.EscapeString(block.Text()))
|
return fmt.Sprintf("<h3>%s</h3>", html.EscapeString(block.Text()))
|
||||||
case adoc.CodeBlock:
|
case adoc.CodeBlock:
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestFormatBlock(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "subtitle",
|
name: "subtitle",
|
||||||
element: adoc.SubTitle("text"),
|
element: adoc.SubTitle("text"),
|
||||||
exp: "<h2>text</h2>",
|
exp: `<h2 id="text">text</h2>`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "subsubtitle",
|
name: "subsubtitle",
|
||||||
|
|
|
@ -13,9 +13,11 @@ func TestPost(t *testing.T) {
|
||||||
docKind := adoc.KIND_NOTE
|
docKind := adoc.KIND_NOTE
|
||||||
siteKind := site.Kind(docKind)
|
siteKind := site.Kind(docKind)
|
||||||
config := &site.SiteConfig{
|
config := &site.SiteConfig{
|
||||||
|
BaseURL: "base_url",
|
||||||
KindMap: map[adoc.Kind]site.Kind{
|
KindMap: map[adoc.Kind]site.Kind{
|
||||||
docKind: siteKind,
|
docKind: siteKind,
|
||||||
},
|
},
|
||||||
|
PathsWithKind: true,
|
||||||
}
|
}
|
||||||
title := "title thing"
|
title := "title thing"
|
||||||
author := "author"
|
author := "author"
|
||||||
|
@ -60,7 +62,7 @@ func TestPost(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("full link", func(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) {
|
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) {
|
t.Run("xml post", func(t *testing.T) {
|
||||||
exp := &site.XMLPost{
|
exp := &site.XMLPost{
|
||||||
Link: "https://erikwinter.nl/notes/2020/title-thing/",
|
Link: "base_url/notes/2020/title-thing/",
|
||||||
Title: "title thing",
|
Title: "title thing",
|
||||||
DateFormal: "Mon, 28 Dec 2020 07:23:45 +0000",
|
DateFormal: "Mon, 28 Dec 2020 07:23:45 +0000",
|
||||||
Content: "<p>one</p>\n<p>two</p>\n",
|
Content: "<p>one</p>\n<p>two</p>\n",
|
||||||
|
|
|
@ -57,11 +57,6 @@ func TestNewKind(t *testing.T) {
|
||||||
input: "article",
|
input: "article",
|
||||||
exp: adoc.KIND_ARTICLE,
|
exp: adoc.KIND_ARTICLE,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "work note",
|
|
||||||
input: "work",
|
|
||||||
exp: adoc.KIND_WORK,
|
|
||||||
},
|
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
act := adoc.NewKind(tc.input)
|
act := adoc.NewKind(tc.input)
|
||||||
|
|
Loading…
Reference in New Issue