~poptart/x

x/cmd/hosakahashi.go -rw-r--r-- 2.0 KiB
53aeea26 — poptart Updated the UA to use the omahaproxy release info 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main

import (
	"bufio"
	"os"
	"strconv"
	"text/template"
)

const tmpl = `<html>
        <head>
                <meta charset="utf-8" />
                <meta name="viewport" content="width=device-width" />
                <title>{{.Title}}</title>
                <link rel="stylesheet" href="slides.css" type="text/css" />
        </head>
        <body>
	{{range .SlideDeck}}
	<section id="{{.Id}}">{{if .Prev}}<a class="prev" href="#{{.PrevId}}"></a><a class="restart" href="#start"></a>{{- end}}{{if .Next}}<a class="next" href="#{{.NextId}}"></a>{{- end}}{{if .IsEnd}}<a class="home" href={{.NextId}}></a>{{- end}}<pre>{{.Content}}</pre>
	</section>{{end}}
	</body>
</html>		
`

type Slide struct {
	Content  string
	Position int
	Id       string
	Prev     bool
	Next     bool
	PrevId   string
	NextId   string
	IsEnd    bool
}

type SlideSet struct {
	SlideDeck []Slide
	Title     string
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var slides SlideSet
	var us Slide
	for {
		line, _, err := reader.ReadLine()
		if err != nil {
			us.Next = false
			us.IsEnd = true
			us.NextId = "/"
			slides.SlideDeck = append(slides.SlideDeck, us)
			break
		}
		if len(slides.SlideDeck) == 0 {
			slides.Title = us.Content
			us.Prev = false
			us.Next = true
			us.IsEnd = false
			us.Id = "start"
			us.Position = 0
			us.NextId = "slide" + strconv.Itoa(us.Position+1)
		}
		if string(line) == "" {
			slides.SlideDeck = append(slides.SlideDeck, us)
			us.Content = ""
			us.Next = true
			us.Prev = true
			us.Position++
			us.NextId = "slide" + strconv.Itoa(us.Position+1)
			us.PrevId = "slide" + strconv.Itoa(us.Position-1)
			us.Id = "slide" + strconv.Itoa(us.Position)
		} else {
			switch string(line[0]) {
			case "@":
				line = []byte("<img src='" + string(line[1:]) + "'/>")
			case `"`:
				line = []byte{}
			}
			if us.Content == "" {
				us.Content = string(line)
			} else {
				us.Content = us.Content + "\n" + string(line)
			}
		}
	}
	t := template.Must(template.New("slides").Parse(tmpl))
	t.Execute(os.Stdout, slides)
}