diff --git a/cmd.go b/cmd.go index 0218a30..2f31c15 100644 --- a/cmd.go +++ b/cmd.go @@ -1,10 +1,11 @@ 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."` - NameKey string `default:"name" short:"n" help:"The metadata key for the recipe name."` - Title string `default:"Recipes directory" short:"t" help:"The title to use at the recipe index."` + 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."` + Title string `default:"Recipes directory" short:"t" help:"The title to use at the recipe index."` + IngredientsTitle string `default:"Ingredients" short:"i" help:"The title to use at the list of ingredients of each recipe"` } var cli struct { diff --git a/sandwitchboard.go b/sandwitchboard.go index aa73d73..63ec741 100644 --- a/sandwitchboard.go +++ b/sandwitchboard.go @@ -10,6 +10,7 @@ import ( "log/slog" "os" "path/filepath" + "sort" "strings" "github.com/alecthomas/kong" @@ -69,6 +70,15 @@ var funcMap = template.FuncMap{ return template.HTML(str) }, + "sortedMetadataKeys": func(m cooklang.Metadata) []string { + keys := []string{} + for k := range m { + keys = append(keys, k) + } + + sort.Strings(keys) + return keys + }, } func recipeImageForStep(recipepath string, step int) string { @@ -257,7 +267,14 @@ func (g *generateCmd) Run() error { htmlPath := filepath.Join(filepath.Dir(relpath), fmt.Sprintf("%s.html", filenameWithoutExt)) recipeFiles = append(recipeFiles, &RecipeFile{Name: recipeName, Path: htmlPath}) recipeDistPath := filepath.Join(g.Output, htmlPath) - data := map[string]any{"name": recipeName, "recipe": recipe, "path": path, "relpath": getRelpath(relpath)} + data := map[string]any{ + "name": recipeName, + "recipe": recipe, + "path": path, + "relpath": getRelpath(relpath), + "nameKey": g.NameKey, + "ingredientsTitle": g.IngredientsTitle, + } slog.Debug("Executing template", "recipeName", recipeName, "recipeWebPath", recipeDistPath) if err := executeTemplateToFile("recipe", data, recipeDistPath); err != nil { return fmt.Errorf("cannot execute template \"recipe\" to file %q: %w", recipeDistPath, err) diff --git a/templates/recipe.html.tmpl b/templates/recipe.html.tmpl index d830a2b..164ebc5 100644 --- a/templates/recipe.html.tmpl +++ b/templates/recipe.html.tmpl @@ -15,14 +15,28 @@ {{end}} - {{if ne (len .recipe.Steps) 0}} + {{if ne (len .recipe.Metadata) 0}}