Przeglądaj źródła

Display a tag listing at the bottom

Lucas Stadler 9 lat temu
rodzic
commit
88692c1c37
1 zmienionych plików z 33 dodań i 2 usunięć
  1. 33 2
      go/blog/blog.go

+ 33 - 2
go/blog/blog.go

12
	"io/ioutil"
12
	"io/ioutil"
13
	"net/url"
13
	"net/url"
14
	"os"
14
	"os"
15
	"sort"
15
	"strings"
16
	"strings"
16
	"unicode"
17
	"unicode"
17
18
74
	max-height: 50vh;
75
	max-height: 50vh;
75
}
76
}
76
77
77
article .tags {
78
.tags {
78
	list-style-type: none;
79
	list-style-type: none;
79
	padding: 0;
80
	padding: 0;
80
}
81
}
81
82
82
article .tags .tag-link {
83
.tags .tag-link {
83
	float: left;
84
	float: left;
84
	color: black;
85
	color: black;
85
	margin-right: 0.5em;
86
	margin-right: 0.5em;
92
article.does-not-match {
93
article.does-not-match {
93
	display: none;
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
func init() {
104
func init() {
159
		posts = reversePosts
166
		posts = reversePosts
160
	}
167
	}
161
168
169
	tags := map[string]bool{}
162
	for i, post := range posts {
170
	for i, post := range posts {
163
		if post.Id == "" {
171
		if post.Id == "" {
164
			posts[i].Id = generateId(post)
172
			posts[i].Id = generateId(post)
165
			post = posts[i]
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
		var err error
182
		var err error
169
		switch post.Type {
183
		switch post.Type {
170
		case "shell":
184
		case "shell":
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
	fmt.Fprintf(out, `
224
	fmt.Fprintf(out, `
201
225
202
	<script>
226
	<script>
404
</article>
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
func exit(err error) {
438
func exit(err error) {
408
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
439
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
409
	os.Exit(1)
440
	os.Exit(1)