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 @@
{{$m := .recipe.Metadata}}
{{$nameKey := .nameKey}}
+ {{$urlKey := .urlKey}}
{{range $k := sortedMetadataKeys $m}}
- {{if ne $k $nameKey}}
+ {{if and (ne $k $nameKey) (ne $k $urlKey)}}
- {{$k}}: {{index $m $k}}
{{end}}
{{end}}