Quellcode durchsuchen

Support image posts

Lucas Stadler vor 9 Jahren
Ursprung
Commit
17cd1c9b1d
2 geänderte Dateien mit 34 neuen und 0 gelöschten Zeilen
  1. 31 0
      go/blog/blog.go
  2. 3 0
      go/blog/blog.yaml

+ 31 - 0
go/blog/blog.go

@ -33,6 +33,10 @@ var flags struct {
33 33
var dataPath string = "blog.yaml"
34 34
35 35
var defaultStyle = `
36
article {
37
	margin-bottom: 1em;
38
}
39
36 40
article header {
37 41
	display: flex;
38 42
	align-items: center;
@ -46,6 +50,11 @@ article h1 {
46 50
article time {
47 51
	color: #666;
48 52
}
53
54
article img {
55
	max-width: 80vw;
56
	max-height: 50vh;
57
}
49 58
`
50 59
51 60
func init() {
@ -110,6 +119,8 @@ func main() {
110 119
			err = shellTmpl.Execute(os.Stdout, post)
111 120
		case "link":
112 121
			err = linkTmpl.Execute(os.Stdout, post)
122
		case "image":
123
			err = imageTmpl.Execute(os.Stdout, post)
113 124
		default:
114 125
			fmt.Fprintf(os.Stderr, "Error: no output for type '%s'\n", post.Type)
115 126
			os.Exit(1)
@ -134,6 +145,9 @@ var funcs = template.FuncMap{
134 145
	"markdown": func(markdown string) template.HTML {
135 146
		return template.HTML(blackfriday.MarkdownCommon([]byte(markdown)))
136 147
	},
148
	"safe_url": func(s string) template.URL {
149
		return template.URL(s)
150
	},
137 151
}
138 152
139 153
var shellTmpl = template.Must(template.New("shell").
@ -164,6 +178,23 @@ var linkTmpl = template.Must(template.New("link").
164 178
</article>
165 179
`))
166 180
181
var imageTmpl = template.Must(template.New("image").
182
	Funcs(funcs).Parse(`
183
<article id="{{ .Id }}" class="image">
184
	{{- if .Title }}
185
	<header>
186
		<h1>{{ .Title }}</h1>
187
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
188
	</header>
189
	{{- end }}
190
	<img src="{{ safe_url .URL }}" />
191
	{{- if .Content }}
192
193
	{{ markdown .Content }}
194
	{{- end -}}
195
</article>
196
`))
197
167 198
func exit(err error) {
168 199
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
169 200
	os.Exit(1)

+ 3 - 0
go/blog/blog.yaml

@ -11,3 +11,6 @@
11 11
  content: Unfortunately, the ones for 2016 are missing.  I'm not sure if there will be video, I haven't found anything official so far.
12 12
  date: "2016-09-24"
13 13
  type: link
14
- url: file:///home/lu/m/pictures/inspiration/empartridge-anything.jpg
15
  content: By [@empartridge](http://empartridge.tumblr.com).
16
  type: image