assets dir is part of staticFiles slice

This commit is contained in:
Kirill Zhuravlev 2023-02-14 18:49:59 +01:00 committed by Avelino
parent ed9808b8f1
commit 43fe5dbe66
No known key found for this signature in database
GPG Key ID: B345B4D52E98180A

15
main.go
View File

@ -28,7 +28,13 @@ type Object struct {
// Source // Source
const readmePath = "README.md" const readmePath = "README.md"
const assetsDir = "tmpl/assets"
// NOTE: this files should be copied as is to outDir directory
var staticFiles = []string{
"tmpl/assets",
"tmpl/_redirects",
"tmpl/robots.txt",
}
// Templates // Templates
const tplPath = "tmpl/tmpl.html" const tplPath = "tmpl/tmpl.html"
@ -40,7 +46,6 @@ const tmplSitemap = "tmpl/sitemap-tmpl.xml"
// NOTE: trailing slash is required // NOTE: trailing slash is required
const outDir = "out/" const outDir = "out/"
var outAssetsDir = filepath.Join(outDir, "assets")
var outIndexFile = filepath.Join(outDir, "index.html") var outIndexFile = filepath.Join(outDir, "index.html")
var outSitemapFile = filepath.Join(outDir, "sitemap.xml") var outSitemapFile = filepath.Join(outDir, "sitemap.xml")
@ -95,10 +100,14 @@ func main() {
makeSitemap(objs) makeSitemap(objs)
if err := cp.Copy(assetsDir, outAssetsDir); err != nil { for _, srcFilename := range staticFiles {
dstFilename := filepath.Join(outDir, filepath.Base(srcFilename))
fmt.Printf("Copy static file: %s -> %s\n", srcFilename, dstFilename)
if err := cp.Copy(srcFilename, dstFilename); err != nil {
panic(err) panic(err)
} }
} }
}
func mkdirAll(path string) error { func mkdirAll(path string) error {
_, err := os.Stat(path) _, err := os.Stat(path)