]> Sergey Matveev's repositories - sgblog.git/commitdiff
Move templates to external files, make them HTML5 v0.22.0
authorSergey Matveev <stargrave@stargrave.org>
Sun, 3 Oct 2021 08:38:12 +0000 (11:38 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 3 Oct 2021 08:38:12 +0000 (11:38 +0300)
cmd/sgblog/gemini-entry.tmpl [new file with mode: 0644]
cmd/sgblog/gemini-menu.tmpl [new file with mode: 0644]
cmd/sgblog/gemini.go
cmd/sgblog/gopher-entry.tmpl [new file with mode: 0644]
cmd/sgblog/gopher-menu.tmpl [new file with mode: 0644]
cmd/sgblog/gopher.go
cmd/sgblog/http-entry.tmpl [new file with mode: 0644]
cmd/sgblog/http-index.tmpl [new file with mode: 0644]
cmd/sgblog/http.go
common.go
go.mod

diff --git a/cmd/sgblog/gemini-entry.tmpl b/cmd/sgblog/gemini-entry.tmpl
new file mode 100644 (file)
index 0000000..22f7aff
--- /dev/null
@@ -0,0 +1,22 @@
+{{$CR := printf "\r"}}20 text/gemini{{$CR}}
+# {{.Title}}
+What: {{.Commit.Hash.String}}
+When: {{.When}}
+{{if .Topics}}Topics:{{range .Topics}} {{.}}{{end}}{{end}}
+```
+{{.Commit.Message}}```
+{{- if .Note}}
+## Note:
+```
+{{.Note}}
+```
+{{end -}}
+{{- if .Cfg.CommentsEmail}}
+=> mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}} leave comment
+{{end}}{{range $idx, $comment := .Comments}}
+## comment {{$idx}}:
+```
+{{$comment}}
+```
+{{end}}
+Generated by: SGBlog {{.Version}}
diff --git a/cmd/sgblog/gemini-menu.tmpl b/cmd/sgblog/gemini-menu.tmpl
new file mode 100644 (file)
index 0000000..e8f86bc
--- /dev/null
@@ -0,0 +1,17 @@
+{{$CR := printf "\r"}}20 text/gemini{{$CR}}
+# {{.Cfg.Title}} {{if .Topic}}(topic: {{.Topic}}) {{end}}({{.Offset}}-{{.OffsetNext}})
+{{if .Cfg.AboutURL}}=> {{.Cfg.AboutURL}} About{{end}}
+{{if .Offset}}=> /?offset={{.OffsetPrev}}{{if .Topic}}&topic={{.Topic}}{{end}} Prev{{end}}
+{{if not .LogEnded}}=> /?offset={{.OffsetNext}}{{if .Topic}}&topic={{.Topic}}{{end}} Next{{end}}
+
+{{$datePrev := "0001-01-01" -}}
+{{- range .Entries -}}
+{{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
+{{- if ne $dateCur $datePrev}}{{$datePrev = $dateCur}}## {{$dateCur}}
+{{end -}}
+=> /{{.Commit.Hash.String}} [{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}}
+{{end}}
+
+{{range .Topics -}}=> /?topic={{.}} Topic: {{.}}
+{{end}}
+Generated by: SGBlog {{.Version}}
index af95e677b3844726f0b6003395b76915f0886972..5a2f9a349d599acb78b2f6f9ca7dfbeac1f4f6df 100644 (file)
@@ -19,6 +19,7 @@ package main
 
 import (
        "bufio"
+       _ "embed"
        "errors"
        "fmt"
        "io"
@@ -34,48 +35,14 @@ import (
        "go.stargrave.org/sgblog"
 )
 
-const (
-       TmplGemMenu = `{{$CR := printf "\r"}}20 text/gemini{{$CR}}
-# {{.Cfg.Title}} {{if .Topic}}(topic: {{.Topic}}) {{end}}({{.Offset}}-{{.OffsetNext}})
-{{if .Cfg.AboutURL}}=> {{.Cfg.AboutURL}} About{{end}}
-{{if .Offset}}=> /?offset={{.OffsetPrev}}{{if .Topic}}&topic={{.Topic}}{{end}} Prev{{end}}
-{{if not .LogEnded}}=> /?offset={{.OffsetNext}}{{if .Topic}}&topic={{.Topic}}{{end}} Next{{end}}
+var (
+       //go:embed gemini-menu.tmpl
+       TmplGemMenuRaw string
+       //go:embed gemini-entry.tmpl
+       TmplGemEntryRaw string
 
-{{$datePrev := "0001-01-01" -}}
-{{- range .Entries -}}
-{{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
-{{- if ne $dateCur $datePrev}}{{$datePrev = $dateCur}}## {{$dateCur}}
-{{end -}}
-=> /{{.Commit.Hash.String}} [{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}}
-{{end}}
-
-{{range .Topics -}}=> /?topic={{.}} Topic: {{.}}
-{{end}}
-Generated by: SGBlog {{.Version}}
-`
-       TmplGemEntry = `{{$CR := printf "\r"}}20 text/gemini{{$CR}}
-# {{.Title}}
-What: {{.Commit.Hash.String}}
-When: {{.When}}
-{{if .Topics}}Topics:{{range .Topics}} {{.}}{{end}}{{end}}
-` + "```" + `
-{{.Commit.Message}}` + "```" + `
-{{- if .Note}}
-## Note:
-` + "```" + `
-{{.Note}}
-` + "```" + `
-{{end -}}
-{{- if .Cfg.CommentsEmail}}
-=> mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}} leave comment
-{{end}}{{range $idx, $comment := .Comments}}
-## comment {{$idx}}:
-` + "```" + `
-{{$comment}}
-` + "```" + `
-{{end}}
-Generated by: SGBlog {{.Version}}
-`
+       TmplGemMenu  = template.Must(template.New("menu").Parse(TmplGemMenuRaw))
+       TmplGemEntry = template.Must(template.New("entry").Parse(TmplGemEntryRaw))
 )
 
 func makeGemErr(err error) {
@@ -173,12 +140,11 @@ func serveGemini(cfgPath string) {
                                )),
                        })
                }
-               tmpl := template.Must(template.New("menu").Parse(TmplGemMenu))
                offsetPrev := offset - PageEntries
                if offsetPrev < 0 {
                        offsetPrev = 0
                }
-               err = tmpl.Execute(os.Stdout, struct {
+               err = TmplGemMenu.Execute(os.Stdout, struct {
                        Cfg        *Cfg
                        Topic      string
                        Offset     int
@@ -207,9 +173,8 @@ func serveGemini(cfgPath string) {
                if err != nil {
                        log.Fatalln(err)
                }
-               tmpl := template.Must(template.New("entry").Parse(TmplGemEntry))
                title := msgSplit(commit.Message)[0]
-               err = tmpl.Execute(os.Stdout, struct {
+               err = TmplGemEntry.Execute(os.Stdout, struct {
                        Title        string
                        Commit       *object.Commit
                        When         string
diff --git a/cmd/sgblog/gopher-entry.tmpl b/cmd/sgblog/gopher-entry.tmpl
new file mode 100644 (file)
index 0000000..fa17e3b
--- /dev/null
@@ -0,0 +1,20 @@
+What: {{.Commit.Hash.String}}
+When: {{.When}}
+------------------------------------------------------------------------
+{{if .Topics}}Topics:{{range .Topics}} {{.}}{{end}}{{end}}
+------------------------------------------------------------------------
+{{.Commit.Message -}}
+{{- if .Note}}
+------------------------------------------------------------------------
+Note:
+{{.Note}}{{end -}}
+{{- if .Cfg.CommentsEmail}}
+------------------------------------------------------------------------
+leave comment: mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}}
+{{end}}{{range $idx, $comment := .Comments}}
+------------------------------------------------------------------------
+comment {{$idx}}:
+{{$comment}}
+{{end}}
+------------------------------------------------------------------------
+Generated by: SGBlog {{.Version}}
diff --git a/cmd/sgblog/gopher-menu.tmpl b/cmd/sgblog/gopher-menu.tmpl
new file mode 100644 (file)
index 0000000..d1cc7eb
--- /dev/null
@@ -0,0 +1,16 @@
+{{$CR := printf "\r"}}{{$CRLF := printf "\r\n" -}}
+{{- define "domainPort" }}     {{.GopherDomain}}       70{{end}}{{$Cfg := .Cfg -}}
+i{{.Cfg.Title}} {{if .Topic}}(topic: {{.Topic}}) {{end}}({{.Offset}}-{{.OffsetNext}})  err{{template "domainPort" .Cfg}}{{$CRLF -}}
+{{- if .Cfg.AboutURL}}hAbout   URL:{{.Cfg.AboutURL}}{{template "domainPort" .Cfg}}{{$CRLF}}{{end -}}
+{{- if .Offset}}1Prev  {{if .Topic}}{{.Topic}}/{{end}}offset/{{.OffsetPrev}}{{template "domainPort" .Cfg}}{{$CRLF}}{{end -}}
+{{- if not .LogEnded}}1Next    {{if .Topic}}{{.Topic}}/{{end}}offset/{{.OffsetNext}}{{template "domainPort" .Cfg}}{{$CRLF}}{{end -}}
+{{- $datePrev := "0001-01-01" -}}
+{{- range .Entries -}}
+{{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
+{{- if ne $dateCur $datePrev}}{{$datePrev = $dateCur}}
+i{{$dateCur}}  err{{template "domainPort" $Cfg}}{{$CR}}{{end}}
+0[{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}}  /{{.Commit.Hash.String}}{{template "domainPort" $Cfg}}{{$CR}}{{end}}
+{{range .Topics}}
+1Topic: {{.}}  {{.}}/offset/0{{template "domainPort" $Cfg}}{{$CR}}{{end}}
+iGenerated by: SGBlog {{.Version}}     err{{template "domainPort" .Cfg}}{{$CR}}
+.{{$CRLF}}
index 27ad8845167c2a311a26ee29dc5f093b7a2a8d52..f6bc3b4cc7a40aaad0532985653b4c39c077c4d3 100644 (file)
@@ -19,6 +19,7 @@ package main
 
 import (
        "bufio"
+       _ "embed"
        "errors"
        "fmt"
        "io"
@@ -35,44 +36,14 @@ import (
        "go.stargrave.org/sgblog"
 )
 
-const (
-       TmplGopherMenu = `{{$CR := printf "\r"}}{{$CRLF := printf "\r\n" -}}
-{{- define "domainPort" }}     {{.GopherDomain}}       70{{end}}{{$Cfg := .Cfg -}}
-i{{.Cfg.Title}} {{if .Topic}}(topic: {{.Topic}}) {{end}}({{.Offset}}-{{.OffsetNext}})  err{{template "domainPort" .Cfg}}{{$CRLF -}}
-{{- if .Cfg.AboutURL}}hAbout   URL:{{.Cfg.AboutURL}}{{template "domainPort" .Cfg}}{{$CRLF}}{{end -}}
-{{- if .Offset}}1Prev  {{if .Topic}}{{.Topic}}/{{end}}offset/{{.OffsetPrev}}{{template "domainPort" .Cfg}}{{$CRLF}}{{end -}}
-{{- if not .LogEnded}}1Next    {{if .Topic}}{{.Topic}}/{{end}}offset/{{.OffsetNext}}{{template "domainPort" .Cfg}}{{$CRLF}}{{end -}}
-{{- $datePrev := "0001-01-01" -}}
-{{- range .Entries -}}
-{{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
-{{- if ne $dateCur $datePrev}}{{$datePrev = $dateCur}}
-i{{$dateCur}}  err{{template "domainPort" $Cfg}}{{$CR}}{{end}}
-0[{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}}  /{{.Commit.Hash.String}}{{template "domainPort" $Cfg}}{{$CR}}{{end}}
-{{range .Topics}}
-1Topic: {{.}}  {{.}}/offset/0{{template "domainPort" $Cfg}}{{$CR}}{{end}}
-iGenerated by: SGBlog {{.Version}}     err{{template "domainPort" .Cfg}}{{$CR}}
-.{{$CRLF}}`
-       TmplGopherEntry = `What: {{.Commit.Hash.String}}
-When: {{.When}}
-------------------------------------------------------------------------
-{{if .Topics}}Topics:{{range .Topics}} {{.}}{{end}}{{end}}
-------------------------------------------------------------------------
-{{.Commit.Message -}}
-{{- if .Note}}
-------------------------------------------------------------------------
-Note:
-{{.Note}}{{end -}}
-{{- if .Cfg.CommentsEmail}}
-------------------------------------------------------------------------
-leave comment: mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}}
-{{end}}{{range $idx, $comment := .Comments}}
-------------------------------------------------------------------------
-comment {{$idx}}:
-{{$comment}}
-{{end}}
-------------------------------------------------------------------------
-Generated by: SGBlog {{.Version}}
-`
+var (
+       //go:embed gopher-menu.tmpl
+       TmplGopherMenuRaw string
+       //go:embed gopher-entry.tmpl
+       TmplGopherEntryRaw string
+
+       TmplGopherMenu  = template.Must(template.New("gopher-menu").Parse(TmplGopherMenuRaw))
+       TmplGopherEntry = template.Must(template.New("gopher-entry").Parse(TmplGopherEntryRaw))
 )
 
 type TableMenuEntry struct {
@@ -108,7 +79,8 @@ func serveGopher(cfgPath string) {
        selectorParts := strings.Split(selector, "/")
        if strings.HasPrefix(selector, "URL:") {
                selector = selector[len("URL:"):]
-               fmt.Printf(`<html>
+               fmt.Printf(`<!DOCTYPE html>
+<html>
 <head>
        <meta http-equiv="Refresh" content="1; url=%s" />
        <title>Redirect to non-gopher URL</title>
@@ -123,8 +95,7 @@ Redirecting to <a href="%s">%s</a>...
                if err != nil {
                        log.Fatalln(err)
                }
-               tmpl := template.Must(template.New("entry").Parse(TmplGopherEntry))
-               err = tmpl.Execute(os.Stdout, struct {
+               err = TmplGopherEntry.Execute(os.Stdout, struct {
                        Commit       *object.Commit
                        When         string
                        Cfg          *Cfg
@@ -207,12 +178,11 @@ Redirecting to <a href="%s">%s</a>...
                                Topics:      sgblog.ParseTopics(sgblog.GetNote(repo, topicsTree, commit.Hash)),
                        })
                }
-               tmpl := template.Must(template.New("menu").Parse(TmplGopherMenu))
                offsetPrev := offset - PageEntries
                if offsetPrev < 0 {
                        offsetPrev = 0
                }
-               err = tmpl.Execute(os.Stdout, struct {
+               err = TmplGopherMenu.Execute(os.Stdout, struct {
                        Cfg        *Cfg
                        Topic      string
                        Offset     int
diff --git a/cmd/sgblog/http-entry.tmpl b/cmd/sgblog/http-entry.tmpl
new file mode 100644 (file)
index 0000000..3c7fc0a
--- /dev/null
@@ -0,0 +1,50 @@
+{{$Cfg := .Cfg}}<!DOCTYPE html>
+<html>
+<head>
+       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+       <meta name="generator" content="SGBlog {{.Version}}">
+       <title>{{.Title}} ({{.When}})</title>
+       {{with .Cfg.CSS}}<link rel="stylesheet" type="text/css" href="{{.}}">{{end}}
+       {{with .Cfg.Webmaster}}<link rev="made" href="mailto:{{.}}">{{end -}}
+       {{- range .Cfg.GitURLs}}
+       <link rel="vcs-git" href="{{.}}" title="Git repository">{{end}}
+       <link rel="top" href="{{.Cfg.URLPrefix}}/" title="top">
+       <link rel="alternate" title="Comments feed" href="{{.AtomCommentsURL}}" type="application/atom+xml">
+       {{if .Parent}}<link rel="prev" href="{{.Cfg.URLPrefix}}/{{.Parent}}" title="prev">{{end}}
+</head>
+<body>
+{{with .Cfg.AboutURL}}[<a href="{{.}}">about</a>]{{end}}
+[<a href="{{.Cfg.URLPrefix}}/">index</a>]
+{{if .Parent}}[<a href="{{.Cfg.URLPrefix}}/{{.Parent}}">prev</a>]{{end}}
+[<tt><a title="When">{{.When}}</a></tt>]
+[<tt><a title="What">{{.Commit.Hash.String}}</a></tt>]
+
+{{if .Topics}}
+<hr/>
+Topics: {{range .Topics}}[<tt><a href="{{$Cfg.URLPrefix}}?topic={{.}}">{{.}}</a></tt>]{{end}}
+{{end}}
+
+<hr/>
+<h2>{{.Title}}</h2>
+<pre>
+{{range .Lines}}{{. | lineURLize $Cfg.URLPrefix}}
+{{end}}</pre>
+<hr/>
+
+{{if .NoteLines}}Note:<pre>
+{{range .NoteLines}}{{. | lineURLize $Cfg.URLPrefix}}
+{{end}}</pre>
+<hr/>{{end}}
+
+{{if .Cfg.CommentsEmail}}[<a href="mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}}">leave comment</a>]{{end}}
+
+<dl>{{range $idx, $comment := .Comments}}
+<dt><a name="comment{{$idx}}"><a href="#comment{{$idx}}">comment {{$idx}}</a>:</dt>
+<dd><pre>
+{{range $comment.HeaderLines}}{{.}}
+{{end}}{{range $comment.BodyLines}}{{. | lineURLize $Cfg.URLPrefix}}
+{{end}}</pre></dd>
+{{end}}</dl>
+
+</body>
+</html>
diff --git a/cmd/sgblog/http-index.tmpl b/cmd/sgblog/http-index.tmpl
new file mode 100644 (file)
index 0000000..4e012ec
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <meta name="generator" content="SGBlog {{.Version}}">
+    <title>{{.Cfg.Title}} {{if .Topic}}(topic: {{.Topic}}) {{end}}({{.Offset}}-{{.OffsetNext}})</title>
+    {{with .Cfg.CSS}}<link rel="stylesheet" type="text/css" href="{{.}}">{{end}}
+    {{with .Cfg.Webmaster}}<link rev="made" href="mailto:{{.}}">{{end}}
+    {{range .Cfg.GitURLs}}<link rel="vcs-git" href="{{.}}" title="Git repository">{{end}}
+    <link rel="top" href="{{.Cfg.URLPrefix}}/" title="top">
+    <link rel="alternate" title="Posts feed" href="{{.Cfg.AtomBaseURL}}{{.Cfg.URLPrefix}}/{{.AtomPostsFeed}}{{if .Topic}}?topic={{.Topic}}{{end}}" type="application/atom+xml">
+    {{if .CommentsEnabled}}<link rel="alternate" title="Comments feed" href="{{.Cfg.AtomBaseURL}}{{.Cfg.URLPrefix}}/{{.AtomCommentsFeed}}" type="application/atom+xml">{{end}}
+    {{if .Offset}}<link rel="prev" href="{{.Cfg.URLPrefix}}/?offset={{.OffsetPrev}}{{if .Topic}}&topic={{.Topic}}{{end}}" title="prev">{{end}}
+    {{if not .LogEnded}}<link rel="next" href="{{.Cfg.URLPrefix}}/?offset={{.OffsetNext}}{{if .Topic}}&topic={{.Topic}}{{end}}" title="next">{{end}}
+</head>
+<body>
+{{with .Cfg.AboutURL}}[<a href="{{.}}">about</a>]{{end}}
+{{block "links" .}}
+{{if .Offset}}[<a href="{{.Cfg.URLPrefix}}/?offset={{.OffsetPrev}}{{if .Topic}}&topic={{.Topic}}{{end}}">prev</a>]{{end}}
+{{if not .LogEnded}}[<a href="{{.Cfg.URLPrefix}}/?offset={{.OffsetNext}}{{if .Topic}}&topic={{.Topic}}{{end}}">next</a>]{{end}}
+{{end}}
+{{- $Cfg := .Cfg -}}
+{{if .Topics}}<hr/>
+Topics: [<tt><a href="{{$Cfg.URLPrefix}}/">ALL</a></tt>]
+{{range .Topics}}[<tt><a href="{{$Cfg.URLPrefix}}?topic={{.}}">{{.}}</a></tt>]
+{{end}}
+{{end}}
+{{- $TopicsEnabled := .TopicsEnabled -}}
+{{- $datePrev := "0001-01-01" -}}
+<table border=1>
+<tr>
+    <th>N</th><th>When</th><th>Title</th>
+    <th size="5%"><a title="Lines">L</a></th>
+    <th size="5%"><a title="Comments">C</a></th>
+    <th>Linked to</th>
+    {{if .TopicsEnabled}}<th>Topics</th>{{end}}
+</tr>
+{{range .Entries -}}
+{{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
+{{- if ne $dateCur $datePrev -}}
+    <tr><td colspan={{if $TopicsEnabled}}7{{else}}7{{end}}><center><tt>{{$dateCur}}</tt></center></td></tr>
+    {{- $datePrev = $dateCur -}}
+{{- end -}}
+<tr>
+    <td>{{.Num}}</td>
+    <td><tt>{{.Commit.Author.When.Format "15:04"}}</tt></td>
+    <td><a href="{{$Cfg.URLPrefix}}/{{.Commit.Hash.String}}">{{.Title}}</a></td>
+    <td>{{.LinesNum}}</td>
+    <td>{{if .CommentsNum}}{{.CommentsNum}}{{else}}&nbsp;{{end}}</td>
+    <td>{{if .DomainURLs}}{{range .DomainURLs}} {{.}} {{end}}{{else}}&nbsp;{{end}}</td>
+    {{if $TopicsEnabled}}<td>{{if .Topics}}{{range .Topics}} <a href="{{$Cfg.URLPrefix}}/?topic={{.}}">{{.}}</a> {{end}}{{else}}&nbsp;{{end}}</td>{{end}}
+</tr>
+{{end}}</table>
+{{template "links" .}}
+</body>
+</html>
index f1e7404b81da51558c08b824971bbca6e6c00a03..6ec97bb4cc48ca1b1610f32e8f56f641f9ac8d31 100644 (file)
@@ -21,6 +21,7 @@ import (
        "bytes"
        "compress/gzip"
        "crypto/sha1"
+       _ "embed"
        "encoding/hex"
        "encoding/xml"
        "errors"
@@ -46,112 +47,6 @@ import (
 const (
        AtomPostsFeed    = "feed.atom"
        AtomCommentsFeed = "comments.atom"
-       TmplHTMLIndex    = `<html>
-<head>
-       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-       <meta name="generator" content="SGBlog {{.Version}}">
-       <title>{{.Cfg.Title}} {{if .Topic}}(topic: {{.Topic}}) {{end}}({{.Offset}}-{{.OffsetNext}})</title>
-       {{with .Cfg.CSS}}<link rel="stylesheet" type="text/css" href="{{.}}">{{end}}
-       {{with .Cfg.Webmaster}}<link rev="made" href="mailto:{{.}}">{{end}}
-       {{range .Cfg.GitURLs}}<link rel="vcs-git" href="{{.}}" title="Git repository">{{end}}
-       <link rel="top" href="{{.Cfg.URLPrefix}}/" title="top">
-       <link rel="alternate" title="Posts feed" href="{{.Cfg.AtomBaseURL}}{{.Cfg.URLPrefix}}/{{.AtomPostsFeed}}{{if .Topic}}?topic={{.Topic}}{{end}}" type="application/atom+xml">
-       {{if .CommentsEnabled}}<link rel="alternate" title="Comments feed" href="{{.Cfg.AtomBaseURL}}{{.Cfg.URLPrefix}}/{{.AtomCommentsFeed}}" type="application/atom+xml">{{end}}
-       {{if .Offset}}<link rel="prev" href="{{.Cfg.URLPrefix}}/?offset={{.OffsetPrev}}{{if .Topic}}&topic={{.Topic}}{{end}}" title="prev">{{end}}
-       {{if not .LogEnded}}<link rel="next" href="{{.Cfg.URLPrefix}}/?offset={{.OffsetNext}}{{if .Topic}}&topic={{.Topic}}{{end}}" title="next">{{end}}
-</head>
-<body>
-{{with .Cfg.AboutURL}}[<a href="{{.}}">about</a>]{{end}}
-{{block "links" .}}
-{{if .Offset}}[<a href="{{.Cfg.URLPrefix}}/?offset={{.OffsetPrev}}{{if .Topic}}&topic={{.Topic}}{{end}}">prev</a>]{{end}}
-{{if not .LogEnded}}[<a href="{{.Cfg.URLPrefix}}/?offset={{.OffsetNext}}{{if .Topic}}&topic={{.Topic}}{{end}}">next</a>]{{end}}
-{{end}}
-{{- $Cfg := .Cfg -}}
-{{if .Topics}}<hr/>
-Topics: [<tt><a href="{{$Cfg.URLPrefix}}/">ALL</a></tt>]
-{{range .Topics}}[<tt><a href="{{$Cfg.URLPrefix}}?topic={{.}}">{{.}}</a></tt>]
-{{end}}
-{{end}}
-{{- $TopicsEnabled := .TopicsEnabled -}}
-{{- $datePrev := "0001-01-01" -}}
-<table border=1>
-<tr>
-       <th>N</th><th>When</th><th>Title</th>
-       <th size="5%"><a title="Lines">L</a></th>
-       <th size="5%"><a title="Comments">C</a></th>
-       <th>Linked to</th>
-       {{if .TopicsEnabled}}<th>Topics</th>{{end}}
-</tr>
-{{range .Entries -}}
-{{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
-{{- if ne $dateCur $datePrev -}}
-       <tr><td colspan={{if $TopicsEnabled}}7{{else}}7{{end}}><center><tt>{{$dateCur}}</tt></center></td></tr>
-       {{- $datePrev = $dateCur -}}
-{{- end -}}
-<tr>
-       <td>{{.Num}}</td>
-       <td><tt>{{.Commit.Author.When.Format "15:04"}}</tt></td>
-       <td><a href="{{$Cfg.URLPrefix}}/{{.Commit.Hash.String}}">{{.Title}}</a></td>
-       <td>{{.LinesNum}}</td>
-       <td>{{if .CommentsNum}}{{.CommentsNum}}{{else}}&nbsp;{{end}}</td>
-       <td>{{if .DomainURLs}}{{range .DomainURLs}} {{.}} {{end}}{{else}}&nbsp;{{end}}</td>
-       {{if $TopicsEnabled}}<td>{{if .Topics}}{{range .Topics}} <a href="{{$Cfg.URLPrefix}}/?topic={{.}}">{{.}}</a> {{end}}{{else}}&nbsp;{{end}}</td>{{end}}
-</tr>
-{{end}}</table>
-{{template "links" .}}
-</body>
-</html>
-`
-       TmplHTMLEntry = `{{$Cfg := .Cfg}}<html>
-<head>
-       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-       <meta name="generator" content="SGBlog {{.Version}}">
-       <title>{{.Title}} ({{.When}})</title>
-       {{with .Cfg.CSS}}<link rel="stylesheet" type="text/css" href="{{.}}">{{end}}
-       {{with .Cfg.Webmaster}}<link rev="made" href="mailto:{{.}}">{{end -}}
-       {{- range .Cfg.GitURLs}}
-       <link rel="vcs-git" href="{{.}}" title="Git repository">{{end}}
-       <link rel="top" href="{{.Cfg.URLPrefix}}/" title="top">
-       <link rel="alternate" title="Comments feed" href="{{.AtomCommentsURL}}" type="application/atom+xml">
-       {{if .Parent}}<link rel="prev" href="{{.Cfg.URLPrefix}}/{{.Parent}}" title="prev">{{end}}
-</head>
-<body>
-{{with .Cfg.AboutURL}}[<a href="{{.}}">about</a>]{{end}}
-[<a href="{{.Cfg.URLPrefix}}/">index</a>]
-{{if .Parent}}[<a href="{{.Cfg.URLPrefix}}/{{.Parent}}">prev</a>]{{end}}
-[<tt><a title="When">{{.When}}</a></tt>]
-[<tt><a title="What">{{.Commit.Hash.String}}</a></tt>]
-
-{{if .Topics}}
-<hr/>
-Topics: {{range .Topics}}[<tt><a href="{{$Cfg.URLPrefix}}?topic={{.}}">{{.}}</a></tt>]{{end}}
-{{end}}
-
-<hr/>
-<h2>{{.Title}}</h2>
-<pre>
-{{range .Lines}}{{. | lineURLize $Cfg.URLPrefix}}
-{{end}}</pre>
-<hr/>
-
-{{if .NoteLines}}Note:<pre>
-{{range .NoteLines}}{{. | lineURLize $Cfg.URLPrefix}}
-{{end}}</pre>
-<hr/>{{end}}
-
-{{if .Cfg.CommentsEmail}}[<a href="mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}}">leave comment</a>]{{end}}
-
-<dl>{{range $idx, $comment := .Comments}}
-<dt><a name="comment{{$idx}}"><a href="#comment{{$idx}}">comment {{$idx}}</a>:</dt>
-<dd><pre>
-{{range $comment.HeaderLines}}{{.}}
-{{end}}{{range $comment.BodyLines}}{{. | lineURLize $Cfg.URLPrefix}}
-{{end}}</pre></dd>
-{{end}}</dl>
-
-</body>
-</html>
-`
 )
 
 var (
@@ -164,6 +59,16 @@ var (
                "https":  {},
                "telnet": {},
        }
+
+       //go:embed http-index.tmpl
+       TmplHTMLIndexRaw string
+       TmplHTMLIndex    = template.Must(template.New("http-index").Parse(TmplHTMLIndexRaw))
+
+       //go:embed http-entry.tmpl
+       TmplHTMLEntryRaw string
+       TmplHTMLEntry    = template.Must(template.New("http-entry").Funcs(
+               template.FuncMap{"lineURLize": lineURLizeInTemplate},
+       ).Parse(TmplHTMLEntryRaw))
 )
 
 type TableEntry struct {
@@ -436,9 +341,8 @@ func serveHTTP() {
                if offsetPrev < 0 {
                        offsetPrev = 0
                }
-               tmpl := template.Must(template.New("index").Parse(TmplHTMLIndex))
                os.Stdout.Write([]byte(startHeader(etagHash, gzipWriter != nil)))
-               err = tmpl.Execute(out, struct {
+               err = TmplHTMLIndex.Execute(out, struct {
                        Version          string
                        Cfg              *Cfg
                        Topic            string
@@ -790,11 +694,8 @@ func serveHTTP() {
                        notesLines = strings.Split(string(notesRaw), "\n")
                }
 
-               tmpl := template.New("entry")
-               tmpl = tmpl.Funcs(template.FuncMap{"lineURLize": lineURLizeInTemplate})
-               tmpl = template.Must(tmpl.Parse(TmplHTMLEntry))
                os.Stdout.Write([]byte(startHeader(etagHash, gzipWriter != nil)))
-               err = tmpl.Execute(out, struct {
+               err = TmplHTMLEntry.Execute(out, struct {
                        Version         string
                        Cfg             *Cfg
                        Title           string
index 4e0179f61d84a272165365610e6c8d3d95cea482..9eaaeda29455fb390f6a00db6124bc61b21e9e48 100644 (file)
--- a/common.go
+++ b/common.go
@@ -15,7 +15,7 @@ import (
 )
 
 const (
-       Version = "0.21.0"
+       Version = "0.22.0"
        WhenFmt = "2006-01-02 15:04:05Z07:00"
 )
 
diff --git a/go.mod b/go.mod
index 8e2c361af5a520c3bbf698f4faa0c3435cd209b2..6ee5358a01f224fab3b0da6dcefcc5e6d2051f3b 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module go.stargrave.org/sgblog
 
-go 1.13
+go 1.16
 
 require (
        github.com/go-git/go-git/v5 v5.1.0