Home

blog @bd21260238688a3fd94b48f00b4505b13aaef9a9 - refs - log -
-
https://git.jolheiser.com/blog.git
My nonexistent blog
blog / html / html.go
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package html

import (
	"fmt"
	"os"

	"blog.jolheiser.com/article"
	. "maragu.dev/gomponents"
	. "maragu.dev/gomponents/components"
	. "maragu.dev/gomponents/html"
)

var ref = "main"

func init() {
	if r, ok := os.LookupEnv("BLOG_REF"); ok {
		ref = r
	}
}

func base(title, description string, children ...Node) Node {
	return HTML5(HTML5Props{
		Title:       title,
		Description: description,
		Head: []Node{
			Meta(Property("og:title"), Content(title)),
			Meta(Property("og:description"), Content(description)),
			Link(Rel("alternate"), Type("application/atom+xml"), Href("feed.atom")),
			Link(Rel("stylesheet"), Href("sakura.css")),
			Link(Rel("stylesheet"), Href("chroma.css")),
			Link(Rel("stylesheet"), Href("jolheiser.css")),
		},
		Body: children,
	})
}

func published(articles []article.Article) int {
	var num int
	for _, a := range articles {
		if !a.Draft {
			num++
		}
	}
	return num
}

func IndexHTML(articles article.Articles) Node {
	categories := make([]Node, 0, len(articles))
	for category, articles := range articles {
		if published(articles) > 0 {
			categories = append(categories, Group([]Node{
				H3(Text(category)),
				Ul(Map(articles, func(article article.Article) Node {
					if article.Draft {
						return nil
					}
					return Li(
						A(Href(article.Slug()), Text(article.Title)),
					)
				})),
			}))
		}
	}
	return base("jolheiser's blog", "Hahaha yes.....YES!", []Node{
		Header(
			H1(Text("jolheiser")),
			P(Text("Just a guy living in the middle of nowhere who likes to hack on open-source.")),
		),
		Main(Group(categories)),
	}...)
}

func ArticleHTML(article article.Article) Node {
	return base(article.Title, article.Summary, []Node{
		Header(
			H1(A(Href("/"), Small(Text("jolheiser")))),
			Hr(),
			H2(Text(article.Title)),
			Div(Style("display: flex;"),
				P(Style("flex: auto;"), Em(Text(article.Category))),
				P(Style("flex: auto;"), Em(Title(article.Date.Format("Monday, January 2, 2006")), Text(article.Date.Format("Mon, 02 Jan 2006")))),
			),
		),
		Main(Raw(article.Content)),
		Footer(A(Href(fmt.Sprintf("https://git.jolheiser.com/blog/tree/%s/%s", ref, article.Path)), Text("source"))),
	}...)
}

func Property(property string) Node {
	return Attr("property", property)
}