package site import ( "fmt" "html" "strings" "code.ewintr.nl/go-kit/slugify" "code.ewintr.nl/shitty-ssg/pkg/adoc" ) type HTMLPost struct { Slug string Title string DateLong string DateShort string Content string } type HTMLSummary struct { Link string Title string Language Language DateShort string DateLong string Summary string } func FormatBlock(block adoc.BlockElement) string { switch block.(type) { case adoc.Paragraph: text := "" for _, inline := range block.(adoc.Paragraph) { text += FormatInline(inline) } return fmt.Sprintf("

%s

", text) case adoc.SubTitle: return fmt.Sprintf("

%s

", slugify.Slugify(block.Text()), html.EscapeString(block.Text())) case adoc.SubSubTitle: return fmt.Sprintf("

%s

", html.EscapeString(block.Text())) case adoc.CodeBlock: return fmt.Sprintf("
%s
", html.EscapeString(block.Text())) case adoc.List: var items []string for _, item := range block.(adoc.List) { itemText := "" for _, inline := range item { itemText += FormatInline(inline) } items = append(items, fmt.Sprintf("
  • %s
  • ", itemText)) } return fmt.Sprintf("", strings.Join(items, "\n")) default: return "" } } func FormatInline(src adoc.InlineElement) string { text := html.EscapeString(src.Text()) switch src.(type) { case adoc.PlainText: return text case adoc.StrongText: return fmt.Sprintf("%s", text) case adoc.EmpText: return fmt.Sprintf("%s", text) case adoc.StrongEmpText: return fmt.Sprintf("%s", text) case adoc.Link: return fmt.Sprintf("%s", src.(adoc.Link).URL(), text) case adoc.CodeText: return fmt.Sprintf("%s", text) default: return "" } }