Add an exclude config to avoid crashes when Go template system uses recursive functions on templates with {{embed}} in them.

master v0.2.1
Zed A. Shaw 1 month ago
parent a3dce447f9
commit bd06b9cae3
  1. 1
      config/loader.go
  2. 1
      example/.ssgod.json
  3. 15
      main.go

@ -13,6 +13,7 @@ type config struct {
WatchDelay string `json:"watch_delay"` WatchDelay string `json:"watch_delay"`
SyncDir string `json:"sync_dir"` SyncDir string `json:"sync_dir"`
MetaFiles []string `json:"meta_files"` MetaFiles []string `json:"meta_files"`
Exclude []string `json:"exclude"`
} }
var Settings config var Settings config

@ -4,6 +4,7 @@
"target": "public", "target": "public",
"watch_delay": "500ms", "watch_delay": "500ms",
"sync_dir": "static", "sync_dir": "static",
"exclude": [],
"meta_files": [ "meta_files": [
"pages/sitemap.html" "pages/sitemap.html"
] ]

@ -13,6 +13,8 @@ import (
"strings" "strings"
"text/template" "text/template"
"time" "time"
"regexp"
"slices"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/yuin/goldmark" "github.com/yuin/goldmark"
@ -187,6 +189,17 @@ func SamePath(a string, b string) bool {
return filepath.ToSlash(a) == filepath.ToSlash(b) return filepath.ToSlash(a) == filepath.ToSlash(b)
} }
func ExcludedPath(fp string) bool {
is_layout := fp == config.Settings.Layout
is_excluded := slices.ContainsFunc(config.Settings.Exclude, func (s string) bool {
matches, err := regexp.MatchString(s, fp)
if err != nil { log.Panic("invalid excludes regex", s, "error: ", err) }
return matches
})
return is_layout || is_excluded
}
func ProcessDirEntry(path string, d fs.DirEntry, meta *PageMetaData) error { func ProcessDirEntry(path string, d fs.DirEntry, meta *PageMetaData) error {
settings := config.Settings settings := config.Settings
var err error = nil var err error = nil
@ -194,7 +207,7 @@ func ProcessDirEntry(path string, d fs.DirEntry, meta *PageMetaData) error {
if !d.IsDir() && !SamePath(path, config.Settings.Layout) { if !d.IsDir() && !SamePath(path, config.Settings.Layout) {
source_name, ext, found := SplitPathExt(path) source_name, ext, found := SplitPathExt(path)
if found && path != settings.Layout { if found && !ExcludedPath(path) {
target_path := RePrefixPath(path, settings.Target) target_path := RePrefixPath(path, settings.Target)
err = MkdirPath(target_path) err = MkdirPath(target_path)

Loading…
Cancel
Save