mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
fix: css renaming for recursively structured folders
This commit is contained in:
parent
fbe39f45a3
commit
2d065c1346
@ -7,17 +7,26 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Returns all html templates paths from ../templates folder.
|
// Gets file paths from directory recursively.
|
||||||
func getHtmlTemplatePaths() []string {
|
func getFilePathsRecursively(dir string) ([]string, error) {
|
||||||
var paths []string
|
var paths []string
|
||||||
files, err := ioutil.ReadDir("templates")
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
paths = append(paths, "templates/"+file.Name())
|
if file.IsDir() {
|
||||||
|
subdir := dir + "/" + file.Name()
|
||||||
|
subpaths, err := getFilePathsRecursively(subdir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return paths
|
paths = append(paths, subpaths...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
paths = append(paths, dir+"/"+file.Name())
|
||||||
|
}
|
||||||
|
return paths, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns all css files paths in ../static/styles folder.
|
// Returns all css files paths in ../static/styles folder.
|
||||||
@ -80,7 +89,10 @@ func randomString(length int) string {
|
|||||||
// Renames css files to prevent caching old files on production.
|
// Renames css files to prevent caching old files on production.
|
||||||
func RenameCss() {
|
func RenameCss() {
|
||||||
cssMap := createCssMap()
|
cssMap := createCssMap()
|
||||||
htmlTemplatePaths := getHtmlTemplatePaths()
|
htmlTemplatePaths, err := getFilePathsRecursively("templates")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
for origPath, newPath := range cssMap {
|
for origPath, newPath := range cssMap {
|
||||||
renameFile(origPath, newPath)
|
renameFile(origPath, newPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user