-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (54 loc) · 1.37 KB
/
main.go
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
package main
import (
"bufio"
"fmt"
"log"
"os"
"text/template"
"github.com/sivukhin/godjot/djot_parser"
"github.com/sivukhin/godjot/html_writer"
)
func main() {
outDir := "public"
err := os.RemoveAll(outDir)
if err != nil {
log.Fatal(err)
}
err = os.MkdirAll(outDir, 0750)
if err != nil {
log.Fatal(err)
}
file, err := os.Create(fmt.Sprintf("%s/index.html", outDir))
if err != nil {
log.Fatal(err)
}
writer := bufio.NewWriter(file)
tmpl := template.Must(template.New("layout.html").ParseFiles("templates/layout.html", "templates/index.html"))
tmpl.Execute(writer, nil)
writer.Flush()
data, err := os.ReadFile("content/now.dj")
if err != nil {
log.Fatal(err)
}
ast := djot_parser.BuildDjotAst(data)
content := djot_parser.NewConversionContext(
"html",
djot_parser.DefaultConversionRegistry,
map[djot_parser.DjotNode]djot_parser.Conversion{},
).ConvertDjotToHtml(&html_writer.HtmlWriter{}, ast...)
err = os.MkdirAll(fmt.Sprintf("%s/now", outDir), 0750)
if err != nil {
log.Fatal(err)
}
file, err = os.Create(fmt.Sprintf("%s/now/index.html", outDir))
if err != nil {
log.Fatal(err)
}
writer = bufio.NewWriter(file)
tmpl = template.Must(template.New("layout.html").ParseFiles("templates/layout.html", "templates/now.html"))
tmpl.Execute(writer, map[string]string{
"Content": content,
})
writer.Flush()
os.CopyFS(outDir, os.DirFS("static"))
}