| |
|
|
| |
| package main |
|
|
| |
|
|
| import "github.com/a-h/templ" |
| import templruntime "github.com/a-h/templ/runtime" |
|
|
| import ( |
| "fmt" |
| ) |
|
|
| func RecipePage(recipe Recipe) templ.Component { |
| return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { |
| templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context |
| if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { |
| return templ_7745c5c3_CtxErr |
| } |
| templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) |
| if !templ_7745c5c3_IsBuffer { |
| defer func() { |
| templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) |
| if templ_7745c5c3_Err == nil { |
| templ_7745c5c3_Err = templ_7745c5c3_BufErr |
| } |
| }() |
| } |
| ctx = templ.InitializeContext(ctx) |
| templ_7745c5c3_Var1 := templ.GetChildren(ctx) |
| if templ_7745c5c3_Var1 == nil { |
| templ_7745c5c3_Var1 = templ.NopComponent |
| } |
| ctx = templ.ClearChildren(ctx) |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"he\"><head><meta charset=\"utf-8\"><title>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var2 string |
| templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Title) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 12, Col: 23} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</title><link rel=\"stylesheet\" href=\"/static/style.css\"></head><body><header><a href=\"/\">Back</a> <center><h1>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var3 string |
| templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Title) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 18, Col: 29} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</h1></center></header><main><article><div class=\"url\"><a href=\"") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var4 templ.SafeURL |
| templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinURLErrs(recipe.URL) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 22, Col: 41} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" target=\"_blank\">Original</a></div>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| if recipe.ImageURL != "" { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<center><figure><img src=\"") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var5 string |
| templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.ImageURL) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 26, Col: 33} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" alt=\"") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var6 string |
| templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Title) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 26, Col: 54} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\"><figcaption>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var7 string |
| templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Title) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 27, Col: 33} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "</figcaption></figure></center> ") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| if recipe.Description != "" { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<section class=\"description\"><h3>ืชืืืืจ</h3><p>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var8 string |
| templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Description) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 34, Col: 29} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</p></section>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| if recipe.Author != "" { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<section class=\"author\"><h3>ืืืืจ</h3><p>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var9 string |
| templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Author) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 40, Col: 24} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</p></section>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| if recipe.AggregateRating > 0 { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<section class=\"rating\"><h3>ืืืจืื</h3><p>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var10 string |
| templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.1f", recipe.AggregateRating)) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 46, Col: 54} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, " โ
(") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var11 string |
| templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.RatingCount) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 46, Col: 82} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " reviews)</p></section>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| if len(recipe.Ingredients) > 0 { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<section class=\"ingredients\"><h3>ืืจืืืืื</h3><ul>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| for _, ingredient := range recipe.Ingredients { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<li>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var12 string |
| templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(ingredient) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 54, Col: 24} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</li>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</ul></section>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| if len(recipe.Instructions) > 0 { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<section class=\"instructions\"><h3>ืืืจืืืช</h3><ol>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| for _, instruction := range recipe.Instructions { |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<li>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var13 string |
| templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(instruction) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 64, Col: 25} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</li>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</ol></section>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<section class=\"raw-json-ld\"><h3>Raw JSON-LD</h3><pre id=\"json_text\">") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| var templ_7745c5c3_Var14 string |
| templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.RawJsonLd) |
| if templ_7745c5c3_Err != nil { |
| return templ.Error{Err: templ_7745c5c3_Err, FileName: `recipe.templ`, Line: 71, Col: 43} |
| } |
| _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</pre></section></article></main></body><script>\r\n\t\t// Function to pretty-print JSON with colors and indentation\r\n\t\tfunction syntaxHighlight(json) {\r\n\t\t\tjson = JSON.stringify(json, undefined, 4);\r\n\t\t\tjson = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\r\n\t\t\treturn json.replace(/(\"(\\\\u[a-zA-Z0-9]{4}|\\\\[^u]|[^\\\\\"])*\"(\\s*:)?)|(\\b(true|false|null)\\b)|(\\b-?\\d+(\\.\\d*)?([eE][+-]?\\d+)?\\b)/g, function (match) {\r\n\t\t\t\tvar cls = 'number';\r\n\t\t\t\tif (/^\"/.test(match)) {\r\n\t\t\t\t\tif (/:$/.test(match)) {\r\n\t\t\t\t\t\tcls = 'key';\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tcls = 'string';\r\n\t\t\t\t\t}\r\n\t\t\t\t} else if (/true|false/.test(match)) {\r\n\t\t\t\t\tcls = 'boolean';\r\n\t\t\t\t} else if (/null/.test(match)) {\r\n\t\t\t\t\tcls = 'null';\r\n\t\t\t\t}\r\n\t\t\t\treturn '<span class=\"' + cls + '\">' + match + '</span>';\r\n\t\t\t});\r\n\t\t}\r\n\t\t// Example usage\r\n\t\ttry {\r\n\t\t\tvar json = JSON.parse(document.getElementById(\"json_text\").innerText);\r\n\t\t\tdocument.getElementById(\"json_text\").innerHTML = '<pre>' + syntaxHighlight(json) + '</pre>';\r\n\t\t} catch (e) {\r\n\t\t\tconsole.error(\"Error parsing JSON:\", e);\r\n\t\t}\r\n\t</script></html>") |
| if templ_7745c5c3_Err != nil { |
| return templ_7745c5c3_Err |
| } |
| return nil |
| }) |
| } |
|
|
| var _ = templruntime.GeneratedTemplate |
|
|