Use path/filepath instead of path

This commit is contained in:
adnano 2022-02-09 12:36:59 -05:00
parent e3a39e45ee
commit 3aee5385e9

21
main.go
View file

@ -8,7 +8,6 @@ import (
"io/fs" "io/fs"
"log" "log"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
) )
@ -139,23 +138,23 @@ func copyAll(srcDir, dstDir string) error {
var builtin embed.FS var builtin embed.FS
func newSite(name string) { func newSite(name string) {
name = path.Clean(name) name = filepath.Clean(name)
os.Mkdir(name, 0755) os.Mkdir(name, 0755)
os.Mkdir(path.Join(name, "content"), 0755) os.Mkdir(filepath.Join(name, "content"), 0755)
os.Mkdir(path.Join(name, "templates"), 0755) os.Mkdir(filepath.Join(name, "templates"), 0755)
os.Mkdir(path.Join(name, "templates/_default"), 0755) os.Mkdir(filepath.Join(name, "templates", "_default"), 0755)
os.Mkdir(path.Join(name, "static"), 0755) os.Mkdir(filepath.Join(name, "static"), 0755)
os.Mkdir(path.Join(name, "public"), 0755) os.Mkdir(filepath.Join(name, "public"), 0755)
config, _ := builtin.ReadFile("config.toml") config, _ := builtin.ReadFile("config.toml")
os.WriteFile(path.Join(name, "config.toml"), config, 0644) os.WriteFile(filepath.Join(name, "config.toml"), config, 0644)
index := []byte("---\ntitle: Hello, world!\n---\n") index := []byte("---\ntitle: Hello, world!\n---\n")
os.WriteFile(path.Join(name, "content/_index.gmi"), index, 0644) os.WriteFile(filepath.Join(name, "content", "_index.gmi"), index, 0644)
templates := []string{"atom.xml", "index.gmi", "page.gmi"} templates := []string{"atom.xml", "index.gmi", "page.gmi"}
for _, template := range templates { for _, template := range templates {
b, _ := builtin.ReadFile(path.Join("templates/_default", template)) b, _ := builtin.ReadFile(filepath.Join("templates", "_default", template))
os.WriteFile(path.Join(name, "templates/_default", template), b, 0644) os.WriteFile(filepath.Join(name, "templates", "_default", template), b, 0644)
} }
} }