66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
zord_tree "g.arns.lt/zordsdavini/zord-tree"
|
|
)
|
|
|
|
var config = zord_tree.NewConfig(
|
|
[]string{".md"},
|
|
"__a",
|
|
customMeta,
|
|
[]string{"\\.sync_.{12}\\.db"},
|
|
map[string]zord_tree.AppCallback{"gallery": gallery},
|
|
)
|
|
|
|
func gallery(dir string, content string, info os.FileInfo) (string, error) {
|
|
if info.Name() != "index.md" {
|
|
return content, nil
|
|
}
|
|
|
|
fullPath := path.Join(dir, info.Name())
|
|
_, _, fileMeta, err := zord_tree.GetFileParams(fullPath, meta)
|
|
if err != nil {
|
|
return content, err
|
|
}
|
|
|
|
if !strings.HasPrefix(fileMeta["app"], "gallery") {
|
|
return content, nil
|
|
}
|
|
|
|
entries, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
return content, err
|
|
}
|
|
|
|
content += "\n"
|
|
for _, e := range entries {
|
|
if e.Name() != "index.md" {
|
|
content += fmt.Sprintf(
|
|
"\n",
|
|
strings.TrimSuffix(e.Name(), filepath.Ext(e.Name())),
|
|
e.Name(),
|
|
)
|
|
}
|
|
}
|
|
|
|
return content, nil
|
|
}
|
|
|
|
func Collect() {
|
|
log.Println("Collect: start")
|
|
if _, err := os.Stat(source); os.IsNotExist(err) {
|
|
log.Print(err)
|
|
panic("Source directory does not exist.")
|
|
}
|
|
|
|
log.Println("Collect: pre")
|
|
_ = zord_tree.PopulateTree(source, meta, config)
|
|
log.Println("Collect: post")
|
|
}
|