|
|
package main |
|
|
|
|
|
import ( |
|
|
"fmt" |
|
|
) |
|
|
|
|
|
templ Index(recipes []Recipe, tags map[string]int) { |
|
|
<!doctype html> |
|
|
<html lang="he"> |
|
|
<head> |
|
|
<meta charset="utf-8"> |
|
|
<title>Hebrew Recipes Viewer</title> |
|
|
<link rel="stylesheet" href="/static/style.css"> |
|
|
</head> |
|
|
<body> |
|
|
<header> |
|
|
<h1>Hebrew Recipes Viewer</h1> |
|
|
<form action="/search" method="get" class="search-form"> |
|
|
<input name="q" placeholder="Search recipes..."> |
|
|
<button type="submit">Search</button> |
|
|
</form> |
|
|
</header> |
|
|
<main> |
|
|
<section id="results"> |
|
|
<h2>Top recipes</h2> |
|
|
@ListFragment(recipes,tags) |
|
|
</section> |
|
|
</main> |
|
|
</body> |
|
|
</html> |
|
|
} |
|
|
|
|
|
templ ListFragment(recipes []Recipe, tags map[string]int) { |
|
|
<ul class="recipes"> |
|
|
if len(recipes) == 0 { |
|
|
<li><em>No recipes found</em></li> |
|
|
} else { |
|
|
for _, recipe := range recipes { |
|
|
<li> |
|
|
<p><a href={ fmt.Sprintf("/recipe/%d", recipe.ID) }>{ recipe.Title }</a> { fmt.Sprintf("%.1f", recipe.AggregateRating) } ★ ({ recipe.RatingCount } reviews)</p> |
|
|
<div class="tags"> |
|
|
for _, keyword := range recipe.Keywords { |
|
|
// format the keyword as a tag with tag(count) |
|
|
//formatted_tag := fmt.Sprintf("<span class=\"tag\">%s (%d)</span>", keyword, tags[keyword]) |
|
|
<a href={ fmt.Sprintf("/tag?q=%s", keyword) }> { fmt.Sprintf("[%s(%d)]", keyword, tags[keyword]) } </a> |
|
|
} |
|
|
</div> |
|
|
</li> |
|
|
} |
|
|
} |
|
|
</ul> |
|
|
} |
|
|
|