|
|
|
@ -21,14 +21,24 @@ import ( |
|
|
|
//go:embed example/.ssgod.json
|
|
|
|
//go:embed example/.ssgod.json
|
|
|
|
var DEFAULT_CONFIG string |
|
|
|
var DEFAULT_CONFIG string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type PageMetaData struct { |
|
|
|
|
|
|
|
pages []string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (meta *PageMetaData) AddPage(path string) { |
|
|
|
|
|
|
|
path = RePrefixPath(path, "/") |
|
|
|
|
|
|
|
path = filepath.ToSlash(path) |
|
|
|
|
|
|
|
meta.pages = append(meta.pages, path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Fatal(err error, format string, v ...any) { |
|
|
|
func Fatal(err error, format string, v ...any) { |
|
|
|
err_format := fmt.Sprintf("ERROR: %v; %s", err, format) |
|
|
|
err_format := fmt.Sprintf("ERROR: %v; %s", err, format) |
|
|
|
log.Fatalf(err_format, v...) |
|
|
|
panic(fmt.Sprintf(err_format, v...)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Fail(err error, format string, v ...any) error { |
|
|
|
func Fail(err error, format string, v ...any) error { |
|
|
|
err_format := fmt.Sprintf("ERROR: %v; %s", err, format) |
|
|
|
err_format := fmt.Sprintf("ERROR: %v; %s", err, format) |
|
|
|
log.Printf(err_format, v...) |
|
|
|
panic(fmt.Sprintf(err_format, v...)) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -64,8 +74,8 @@ func RenderTemplate(out io.Writer, embed string, variables any) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderMetaFiles(pages []string) { |
|
|
|
func RenderMetaFiles(meta *PageMetaData) { |
|
|
|
fmt.Println("PAGES: ", pages) |
|
|
|
fmt.Println("PAGES: ", meta.pages) |
|
|
|
|
|
|
|
|
|
|
|
for _, path := range config.Settings.MetaFiles { |
|
|
|
for _, path := range config.Settings.MetaFiles { |
|
|
|
fmt.Println(">>> META >>>>", path) |
|
|
|
fmt.Println(">>> META >>>>", path) |
|
|
|
@ -75,10 +85,10 @@ func RenderMetaFiles(pages []string) { |
|
|
|
|
|
|
|
|
|
|
|
if ext == ".md" { |
|
|
|
if ext == ".md" { |
|
|
|
RenderMarkdown(path, target_path, |
|
|
|
RenderMarkdown(path, target_path, |
|
|
|
map[string]any{"Pages": pages}) |
|
|
|
map[string]any{"Pages": meta.pages}) |
|
|
|
} else { |
|
|
|
} else if ext == ".html" { |
|
|
|
RenderHTML(path, target_path, |
|
|
|
RenderHTML(path, target_path, |
|
|
|
map[string]any{"Pages": pages}) |
|
|
|
map[string]any{"Pages": meta.pages}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -146,8 +156,14 @@ func MkdirPath(target_path string) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func UnfuckedPathSplit(path string) []string { |
|
|
|
|
|
|
|
path = filepath.ToSlash(path) |
|
|
|
|
|
|
|
// WARN: have to use strings.Split because fsnotify uses /, even on windows
|
|
|
|
|
|
|
|
return strings.Split(path, "/")[1:] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SplitPathExt(path string) (string, string, bool) { |
|
|
|
func SplitPathExt(path string) (string, string, bool) { |
|
|
|
split_path := strings.Split(path, string(os.PathSeparator))[1:] |
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
source_name := strings.Join(split_path, "/") // Render wants / even on windows
|
|
|
|
source_name := strings.Join(split_path, "/") // Render wants / even on windows
|
|
|
|
|
|
|
|
|
|
|
|
ext := filepath.Ext(source_name) |
|
|
|
ext := filepath.Ext(source_name) |
|
|
|
@ -156,24 +172,23 @@ func SplitPathExt(path string) (string, string, bool) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RePrefixPath(path string, new_prefix string) string { |
|
|
|
func RePrefixPath(path string, new_prefix string) string { |
|
|
|
split_path := strings.Split(path, string(os.PathSeparator))[1:] |
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
|
|
|
|
|
|
|
|
prefixed_path := append([]string{new_prefix}, split_path...) |
|
|
|
prefixed_path := append([]string{new_prefix}, split_path...) |
|
|
|
return filepath.Join(prefixed_path...) |
|
|
|
|
|
|
|
|
|
|
|
res := filepath.Join(prefixed_path...) |
|
|
|
|
|
|
|
return res |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SamePath(a string, b string) bool { |
|
|
|
func SamePath(a string, b string) bool { |
|
|
|
return filepath.ToSlash(a) == filepath.ToSlash(b) |
|
|
|
return filepath.ToSlash(a) == filepath.ToSlash(b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ProcessDirEntry(path string, d fs.DirEntry, err error) error { |
|
|
|
func ProcessDirEntry(path string, d fs.DirEntry, meta *PageMetaData) error { |
|
|
|
settings := config.Settings |
|
|
|
settings := config.Settings |
|
|
|
|
|
|
|
var err error = nil |
|
|
|
|
|
|
|
|
|
|
|
if !d.IsDir() && !SamePath(path, config.Settings.Layout) { |
|
|
|
if !d.IsDir() && !SamePath(path, config.Settings.Layout) { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Fail(err, "path: %s", path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source_name, ext, found := SplitPathExt(path) |
|
|
|
source_name, ext, found := SplitPathExt(path) |
|
|
|
|
|
|
|
|
|
|
|
if found && path != settings.Layout { |
|
|
|
if found && path != settings.Layout { |
|
|
|
@ -187,14 +202,15 @@ func ProcessDirEntry(path string, d fs.DirEntry, err error) error { |
|
|
|
// generate a data-testid for all pages based on template name
|
|
|
|
// generate a data-testid for all pages based on template name
|
|
|
|
page_id := strings.ReplaceAll(source_name, "/", "-") + "-page" |
|
|
|
page_id := strings.ReplaceAll(source_name, "/", "-") + "-page" |
|
|
|
|
|
|
|
|
|
|
|
// BUG: make it so we can have a list of extensions
|
|
|
|
if ext == ".html" { |
|
|
|
if ext == ".html" || ext == ".xml" || ext == ".rss" { |
|
|
|
|
|
|
|
err = RenderHTML(path, target_path, |
|
|
|
err = RenderHTML(path, target_path, |
|
|
|
map[string]any{"PageId": page_id}) |
|
|
|
map[string]any{"PageId": page_id}) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return Fail(err, "failed to render %s", path) |
|
|
|
return Fail(err, "failed to render %s", path) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta.AddPage(target_path) |
|
|
|
} else if ext == ".md" { |
|
|
|
} else if ext == ".md" { |
|
|
|
// need to strip the .md and replace with .html
|
|
|
|
// need to strip the .md and replace with .html
|
|
|
|
html_name, _ := strings.CutSuffix(target_path, ext) |
|
|
|
html_name, _ := strings.CutSuffix(target_path, ext) |
|
|
|
@ -206,6 +222,8 @@ func ProcessDirEntry(path string, d fs.DirEntry, err error) error { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return Fail(err, "failed to render markdown %s", path) |
|
|
|
return Fail(err, "failed to render markdown %s", path) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta.AddPage(html_name) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -242,20 +260,14 @@ func SyncStaticDir() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderPages() { |
|
|
|
func RenderPages() { |
|
|
|
pages := make([]string, 0, 100) |
|
|
|
meta := new(PageMetaData) |
|
|
|
|
|
|
|
|
|
|
|
err := filepath.WalkDir(config.Settings.Views, |
|
|
|
err := filepath.WalkDir(config.Settings.Views, |
|
|
|
func(path string, d fs.DirEntry, err error) error { |
|
|
|
func(path string, d fs.DirEntry, err error) error { |
|
|
|
if err != nil { return err } |
|
|
|
if err != nil { return err } |
|
|
|
|
|
|
|
|
|
|
|
create an exclusion/inclusion system that knows if a file |
|
|
|
err = ProcessDirEntry(path, d, meta) |
|
|
|
is a target, and only process it and add to pages if it matches |
|
|
|
if err != nil { return Fail(err, "failed to process %s", path) } |
|
|
|
|
|
|
|
|
|
|
|
err = ProcessDirEntry(path, d, err) |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
|
|
|
// no errors, add to the list
|
|
|
|
|
|
|
|
pages = append(pages, path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err |
|
|
|
return err |
|
|
|
}) |
|
|
|
}) |
|
|
|
@ -264,7 +276,7 @@ func RenderPages() { |
|
|
|
Fatal(err, "can't walk content") |
|
|
|
Fatal(err, "can't walk content") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RenderMetaFiles(pages) |
|
|
|
RenderMetaFiles(meta) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func WatchMatches(name string) bool { |
|
|
|
func WatchMatches(name string) bool { |
|
|
|
|