Improve path management
This commit is contained in:
parent
2a17689a9f
commit
79de743e58
2 changed files with 32 additions and 1 deletions
|
@ -170,6 +170,10 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isExcluded(name string) bool {
|
||||||
|
return strings.HasPrefix(strings.ToUpper(name), "README")
|
||||||
|
}
|
||||||
|
|
||||||
func (g *generateCmd) Run() error {
|
func (g *generateCmd) Run() error {
|
||||||
fi, err := os.Stat(g.Output)
|
fi, err := os.Stat(g.Output)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
@ -189,7 +193,22 @@ func (g *generateCmd) Run() error {
|
||||||
|
|
||||||
walkErr := filepath.WalkDir(g.Path, func(path string, d fs.DirEntry, err error) error {
|
walkErr := filepath.WalkDir(g.Path, func(path string, d fs.DirEntry, err error) error {
|
||||||
slog.Debug("Walking through file", "path", path)
|
slog.Debug("Walking through file", "path", path)
|
||||||
relpath := filepath.Join(strings.Split(path, "/")[1:]...)
|
|
||||||
|
if isExcluded(d.Name()) {
|
||||||
|
slog.Debug("Excluded file, skipping", "name", d.Name())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
apath, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot get the abs path for %q: %w", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
relpath, err := filepath.Rel(g.Path, apath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot get relative path for %s: %w", apath, err)
|
||||||
|
}
|
||||||
|
|
||||||
ext := filepath.Ext(d.Name())
|
ext := filepath.Ext(d.Name())
|
||||||
recipeName := strings.TrimSuffix(d.Name(), ext)
|
recipeName := strings.TrimSuffix(d.Name(), ext)
|
||||||
if d.IsDir() {
|
if d.IsDir() {
|
||||||
|
|
|
@ -2,3 +2,15 @@ body {
|
||||||
background-color: lightgrey;
|
background-color: lightgrey;
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ingredient {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cookware {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timer {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue