Ver Código Fonte

Add support for text posts

Lucas Stadler 9 anos atrás
pai
commit
ed6770579f
2 arquivos alterados com 51 adições e 0 exclusões
  1. 16 0
      go/blog/blog.go
  2. 35 0
      go/blog/blog.yaml

+ 16 - 0
go/blog/blog.go

@ -123,6 +123,8 @@ func main() {
123 123
			err = imageTmpl.Execute(os.Stdout, post)
124 124
		case "song":
125 125
			err = songTmpl.Execute(os.Stdout, post)
126
		case "text":
127
			err = textTmpl.Execute(os.Stdout, post)
126 128
		default:
127 129
			fmt.Fprintf(os.Stderr, "Error: no output for type '%s'\n", post.Type)
128 130
			os.Exit(1)
@ -216,6 +218,20 @@ var songTmpl = template.Must(template.New("song").
216 218
</article>
217 219
`))
218 220
221
var textTmpl = template.Must(template.New("text").
222
	Funcs(funcs).Parse(`
223
<article id="{{ .Id }}" class="text">
224
	<header>
225
		<h1>{{ .Title }}</h1>
226
		{{- if .Date }}<time>{{ .Date }}</time>{{ end -}}
227
	</header>
228
	{{- if .Content }}
229
230
	{{ markdown .Content }}
231
	{{- end -}}
232
</article>
233
`))
234
219 235
func exit(err error) {
220 236
	fmt.Fprintf(os.Stderr, "Error: %s\n", err)
221 237
	os.Exit(1)

+ 35 - 0
go/blog/blog.yaml

@ -18,3 +18,38 @@
18 18
  content: Shook, by [DRALMS](https://dralms.bandcamp.com/).
19 19
  date: "2016-09-25"
20 20
  type: song
21
- title: Introduction
22
  content: |
23
    `blog` is a tiny tool that generates your (link)blog.
24
    It takes a [YAML](https://yaml.org) file as input, and produces
25
    a single HTML file on stdout, which you could then upload to your
26
    server, place on your Desktop, or pass along to friends.
27
28
    `blog` is not meant to be a feature-rich program.  It does the
29
    bare minimum necessary to host a blog with different post types,
30
    and not more.  Whichever additional features you need you can
31
    add to your version of it.
32
33
    ## How to use it
34
35
    All posts are written in a single file `blog.yaml`, which contains
36
    a list of entries.
37
38
    The most basic post type is `text`, written as follows:
39
40
        - title: An example post
41
          content: You can use *Markdown* here...
42
43
    Optionally you can specify a `date` field.
44
45
    There are a few other types of posts:
46
47
    * `shell`, similar to text, but `title` is a shell command
48
    * `link`, with an additional `url` field
49
    * `image`, where `url` is the source of an image
50
    * `song`, where `url` is the source of the song
51
52
    With the exception of the `shell` type, `title` and `content`
53
    are optional.
54
  date: "2016-09-25"
55
  type: text