Explorar el Código

Display a tag listing at the bottom

Lucas Stadler %!s(int64=9) %!d(string=hace) años
padre
commit
88692c1c37
Se han modificado 1 ficheros con 33 adiciones y 2 borrados
  1. 33 2
      go/blog/blog.go

+ 33 - 2
go/blog/blog.go

@ -12,6 +12,7 @@ import (
12 12
	"io/ioutil"
13 13
	"net/url"
14 14
	"os"
15
	"sort"
15 16
	"strings"
16 17
	"unicode"
17 18
@ -74,12 +75,12 @@ article img {
74 75
	max-height: 50vh;
75 76
}
76 77
77
article .tags {
78
.tags {
78 79
	list-style-type: none;
79 80
	padding: 0;
80 81
}
81 82
82
article .tags .tag-link {
83
.tags .tag-link {
83 84
	float: left;
84 85
	color: black;
85 86
	margin-right: 0.5em;
@ -92,6 +93,12 @@ article .tags .tag-link:visited {
92 93
article.does-not-match {
93 94
	display: none;
94 95
}
96
97
#tags {
98
	color: #555;
99
	font-size: smaller;
100
	margin-bottom: 1em;
101
}
95 102
`
96 103
97 104
func init() {
@ -159,12 +166,19 @@ func main() {
159 166
		posts = reversePosts
160 167
	}
161 168
169
	tags := map[string]bool{}
162 170
	for i, post := range posts {
163 171
		if post.Id == "" {
164 172
			posts[i].Id = generateId(post)
165 173
			post = posts[i]
166 174
		}
167 175
176
		if post.Tags != nil {
177
			for _, tag := range post.Tags {
178
				tags[tag] = true
179
			}
180
		}
181
168 182
		var err error
169 183
		switch post.Type {
170 184
		case "shell":
@ -197,6 +211,16 @@ func main() {
197 211
		}
198 212
	}
199 213
214
	sortedTags := []string{}
215
	for tag, _ := range tags {
216
		sortedTags = append(sortedTags, tag)
217
	}
218
	sort.Strings(sortedTags)
219
	err = tagsTmpl.Execute(out, sortedTags)
220
	if err != nil {
221
		exit(err)
222
	}
223
200 224
	fmt.Fprintf(out, `
201 225
202 226
	<script>
@ -404,6 +428,13 @@ var videoTmpl = template.Must(baseTmpl.Parse(`
404 428
</article>
405 429
`))
406 430
431
var tagsTmpl = template.Must(baseTmpl.New("tags-list").Parse(`
432
	<section id="tags">
433
		<h1>All tags:</h1>
434
		{{ template "tags" . }}
435
	</section>
436
`))
437
407 438
func exit(err error) {
408 439
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
409 440
	os.Exit(1)