Put files in subdirectories, bootstrap css
This commit is contained in:
parent
83d55a2fe5
commit
d291d281a2
35
main.go
35
main.go
@ -38,15 +38,22 @@ func (n *Node) writeIndex(w io.Writer) {
|
||||
<ul>
|
||||
{{ range $index, $element := .Children}}
|
||||
<li>
|
||||
<a href="{{$element.Data.Id}}.html">{{ $element.Data.Title }}</a>
|
||||
<a href="pages/{{$element.Data.Id}}.html">{{ $element.Data.Title }}</a>
|
||||
{{ template "tree" $element }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
<html>
|
||||
{{ template "tree" . }}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
{{ template "tree" . }}
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
if err != nil {
|
||||
@ -84,13 +91,28 @@ func (n *Node) addChild(child *Node) {
|
||||
}
|
||||
|
||||
func writeHTML(n *Node) {
|
||||
os.Chdir("pages")
|
||||
f, err := os.Create(n.Data.Id + ".html")
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating file for ID %v", n.Data.Id)
|
||||
}
|
||||
defer f.Close()
|
||||
log.Printf("Writing file %v", f.Name())
|
||||
f.Write([]byte(n.Data.Body))
|
||||
log.Printf("Writing file %v containing page: %v", f.Name(), n.Data.Title)
|
||||
html := `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
`
|
||||
html += n.Data.Body
|
||||
html += "</body></html>"
|
||||
_, err = f.Write([]byte(html))
|
||||
if err != nil {
|
||||
log.Fatalf("Error writing file for ID %v", n.Data.Id)
|
||||
}
|
||||
}
|
||||
|
||||
type spaceResult struct {
|
||||
@ -310,6 +332,9 @@ func main() {
|
||||
root := createPageTree(&result)
|
||||
|
||||
fname := "index.html"
|
||||
os.Mkdir("content", 0744)
|
||||
os.Mkdir("content/pages", 0744)
|
||||
os.Chdir("content")
|
||||
f, err := os.Create(fname)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open %v", fname)
|
||||
|
Loading…
x
Reference in New Issue
Block a user