From a190487ef793aeeb0937322cf98383b7505b5ceb Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 18 Apr 2022 11:22:33 +0200 Subject: Add a cookbook section --- content/recipes/_index.md | 9 +++++ layouts/_default/baseof.html | 21 ++++++------ layouts/_default/list.html | 8 ++--- layouts/recipes/list.html | 17 ++++++++++ layouts/recipes/single.html | 78 ++++++++++++++++++++++++++++++++++++++++++++ static/js/cookbook.js | 34 +++++++++++++++++++ 6 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 content/recipes/_index.md create mode 100644 layouts/recipes/list.html create mode 100644 layouts/recipes/single.html create mode 100644 static/js/cookbook.js diff --git a/content/recipes/_index.md b/content/recipes/_index.md new file mode 100644 index 0000000..337e63b --- /dev/null +++ b/content/recipes/_index.md @@ -0,0 +1,9 @@ +--- +title: Cookbook +--- + +People have often asked me to share recipes for various meals and snacks I've +served over time, so I've started writing down my recipes. This section of my +blog covers these recipes in my own personal cookbook. If you want to stay up to +date with the latest additions, subscribe to the [RSS +feed](/recipes/index.xml). diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index a88cca2..c61432e 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -5,30 +5,29 @@ - - - {{ range .AlternativeOutputFormats -}} - - {{ end }} - + {{- range .AlternativeOutputFormats }} + + {{- end }} {{ .Page.Title }} - {{ .Site.Title }} + {{- block "head" . }} + {{- end }} - {{ block "body" . }} + {{- block "body" . }}
- {{ block "main" . }}{{ end }} + {{- block "main" . }}{{ end }}
- {{ end }} + {{- end }} diff --git a/layouts/_default/list.html b/layouts/_default/list.html index a9698f8..6ba66fc 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,11 +1,11 @@ -{{ define "main" }} +{{- define "main" }}

{{ .Title }}

{{ .Content }} -{{ end }} +{{- end }} diff --git a/layouts/recipes/list.html b/layouts/recipes/list.html new file mode 100644 index 0000000..0565d93 --- /dev/null +++ b/layouts/recipes/list.html @@ -0,0 +1,17 @@ +{{- define "main" }} +

{{ .Title }}

+{{ .Content }} + +{{- end }} diff --git a/layouts/recipes/single.html b/layouts/recipes/single.html new file mode 100644 index 0000000..36981ce --- /dev/null +++ b/layouts/recipes/single.html @@ -0,0 +1,78 @@ +{{ define "head" }} + +{{ end }} + +{{ define "main" }} +
+
+

{{ .Title }}

+ {{- range .Params.tags }} + #{{ . }} + {{- end }} +
+
+ {{ .Content }} + + + + + + + + + + + + + + + +
Preparation time{{ .Params.preptime }} minutes
Cooking time{{ .Params.cooktime }} minutes
Serves{{ .Params.serves }}
+

Ingredients

+ + + + + + + + + + + {{- range .Params.ingredients }} + + + + {{- if .unit }} + + + {{- else }} + + {{- end }} + + {{- end }} + +
 IngredientAmountUnit
+ + {{ .label }}{{ .amount }}{{ .unit }}{{ .amount }}
+

Instructions

+ {{- range .Params.stages }} +

{{ .label }}

+
    + {{- range .steps }} +
  1. + {{ . | $.Page.RenderString }} +
  2. + {{- end }} +
+ {{- end }} +
+ +
+{{ end }} diff --git a/static/js/cookbook.js b/static/js/cookbook.js new file mode 100644 index 0000000..fc2177c --- /dev/null +++ b/static/js/cookbook.js @@ -0,0 +1,34 @@ +"use strict"; + +// Kindly copied from MartijnBraam's fathub sources +// https://sr.ht/~martijnbraam/fathub.org/ + +var serve_fraction = 1.0; + +function update_ingredient_list() { + var ingredients = document.querySelectorAll('td[data-amount]'); + for (var i = 0; i < ingredients.length; i++) { + var ingredient = ingredients[i]; + ingredient.innerText = ingredient.dataset.amount * serve_fraction; + } +} + +function adjust_serves() { + serve_fraction = this.value / this.dataset.original; + update_ingredient_list(); +} + +function add_dynamic_controls() { + var serves = document.querySelector("td[data-serves]"); + var spinner = document.createElement('INPUT'); + spinner.type = 'number'; + spinner.dataset.original = serves.dataset.serves; + spinner.value = serves.dataset.serves; + spinner.addEventListener('change', adjust_serves); + serves.innerHTML = ''; + serves.appendChild(spinner); +} + +document.addEventListener("DOMContentLoaded", function () { + add_dynamic_controls(); +}); -- cgit v1.1