Allows to use the recipe metadata to get the recipe title
This commit is contained in:
parent
79de743e58
commit
e85e8b1702
2 changed files with 11 additions and 4 deletions
5
cmd.go
5
cmd.go
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
type generateCmd struct {
|
||||
Path string `arg:"" help:"Path to the directory with the recipes."`
|
||||
Output string `default:"dist" help:"Path to the directory where the files will be generated."`
|
||||
Path string `arg:"" help:"Path to the directory with the recipes."`
|
||||
Output string `default:"dist" help:"Path to the directory where the files will be generated."`
|
||||
NameKey string `default:"name" short:"n" help:"The metadata key for the recipe name."`
|
||||
}
|
||||
|
||||
var cli struct {
|
||||
|
|
|
@ -210,7 +210,6 @@ func (g *generateCmd) Run() error {
|
|||
}
|
||||
|
||||
ext := filepath.Ext(d.Name())
|
||||
recipeName := strings.TrimSuffix(d.Name(), ext)
|
||||
if d.IsDir() {
|
||||
dirpath := filepath.Join(g.Output, relpath)
|
||||
slog.Debug("Directory found, creating output dir", "path", path, "dirpath", dirpath)
|
||||
|
@ -242,7 +241,14 @@ func (g *generateCmd) Run() error {
|
|||
}
|
||||
|
||||
slog.Debug("Parsed file", "path", path, "steps", len(recipe.Steps))
|
||||
recipeDistPath := filepath.Join(g.Output, filepath.Dir(relpath), fmt.Sprintf("%s.html", recipeName))
|
||||
|
||||
filenameWithoutExt := strings.TrimSuffix(d.Name(), ext)
|
||||
recipeName := filenameWithoutExt
|
||||
if name, ok := recipe.Metadata[g.NameKey]; ok {
|
||||
recipeName = name
|
||||
}
|
||||
|
||||
recipeDistPath := filepath.Join(g.Output, filepath.Dir(relpath), fmt.Sprintf("%s.html", filenameWithoutExt))
|
||||
data := map[string]any{"name": recipeName, "recipe": recipe, "path": path, "relpath": getRelpath(relpath)}
|
||||
slog.Debug("Executing template", "recipeName", recipeName, "recipeWebPath", recipeDistPath)
|
||||
if err := executeTemplateToFile("recipe", data, recipeDistPath); err != nil {
|
||||
|
|
Loading…
Reference in a new issue