From 432be8dfb26c685a2faeccf34b751fada9a205a1 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Sat, 3 Aug 2024 08:48:56 +0200 Subject: [PATCH] Adds external URL to the recipe --- cmd.go | 1 + sandwitchboard.go | 6 ++++++ templates/recipe.html.tmpl | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd.go b/cmd.go index 2f31c15..49deccf 100644 --- a/cmd.go +++ b/cmd.go @@ -4,6 +4,7 @@ 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."` + URLKey string `default:"url" short:"u" help:"The metadata key for the recipe URL."` 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"` } diff --git a/sandwitchboard.go b/sandwitchboard.go index 63ec741..19435c0 100644 --- a/sandwitchboard.go +++ b/sandwitchboard.go @@ -263,16 +263,22 @@ func (g *generateCmd) Run() error { if name, ok := recipe.Metadata[g.NameKey]; ok { recipeName = name } + recipeURL := "" + if url, ok := recipe.Metadata[g.URLKey]; ok { + recipeURL = url + } 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, + "url": recipeURL, "recipe": recipe, "path": path, "relpath": getRelpath(relpath), "nameKey": g.NameKey, + "urlKey": g.URLKey, "ingredientsTitle": g.IngredientsTitle, } slog.Debug("Executing template", "recipeName", recipeName, "recipeWebPath", recipeDistPath) diff --git a/templates/recipe.html.tmpl b/templates/recipe.html.tmpl index b92b90b..673dcba 100644 --- a/templates/recipe.html.tmpl +++ b/templates/recipe.html.tmpl @@ -12,6 +12,10 @@

{{.name}}

+ {{if ne .url ""}} + External URL + {{end}} + {{$recipeImage := recipeImage .path}} {{if ne $recipeImage ""}} @@ -21,8 +25,9 @@