diff --git a/README.md b/README.md index 21a80a7..ba03bcd 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,50 @@ vars: cta: text: "Contact" href: "mailto:info@example.de" + +schema: + type: Person + name: "Erika Mustermann" + url: "https://example.de/" + jobTitle: "Patentanwältin" + sameAs: + - https://www.linkedin.com/in/erika-mustermann/ + - https://github.com/erika-mustermann ``` +## Schema.org / JSON-LD (GEO/SEO) + +Templated sites can declare a `schema:` block in `site.yaml`. `render.sh` emits it as `` inside `
` (slot `{{schema_jsonld}}` in `templates/base.html`). See `docs/geo-seo-guideline.md` §3.3 for rationale. + +### Conventions + +- `schema.type` → `@type` (the YAML key is `type`, the rendered key is `@type`). +- `@context: https://schema.org` is added automatically. +- Nested objects use the JSON-LD form directly: write `"@type": Organization` (quoted because of the `@`). +- Array fields like `sameAs:` are passed through as JSON arrays. +- If `schema:` is absent, no `" + fi +fi + # Read template file and extract CSS/body sections template_content=$(cat "$TEMPLATE_FILE") @@ -184,6 +211,7 @@ echo "$css_animations" > "$tmpdir/css_animations" echo "$css_noise" > "$tmpdir/css_noise" echo "$template_css" > "$tmpdir/template_css" printf '%b' "$template_body" > "$tmpdir/template_body" +printf '%s' "$schema_jsonld" > "$tmpdir/schema_jsonld" # Use awk for reliable multiline substitution awk -v vars="$tmpdir/css_variables" \ @@ -192,6 +220,7 @@ awk -v vars="$tmpdir/css_variables" \ -v noise="$tmpdir/css_noise" \ -v tcss="$tmpdir/template_css" \ -v tbody="$tmpdir/template_body" \ + -v schema="$tmpdir/schema_jsonld" \ -v fonts_file=<(echo "$fonts") \ ' function read_file(path, line, content) { @@ -200,6 +229,15 @@ function read_file(path, line, content) { close(path) return content } +# Literal string replace — avoids gsub replacement-string interpretation of & and \ +function lreplace(haystack, needle, repl, pos, out) { + out = "" + while ((pos = index(haystack, needle)) > 0) { + out = out substr(haystack, 1, pos - 1) repl + haystack = substr(haystack, pos + length(needle)) + } + return out haystack +} BEGIN { cv = read_file(vars) cr = read_file(resp) @@ -207,15 +245,18 @@ BEGIN { cn = read_file(noise) tc = read_file(tcss) tb = read_file(tbody) + sc = read_file(schema) } { - gsub(/\{\{css_variables\}\}/, cv) - gsub(/\{\{css_responsive\}\}/, cr) - gsub(/\{\{css_animations\}\}/, ca) - gsub(/\{\{css_noise\}\}/, cn) - gsub(/\{\{template_css\}\}/, tc) - gsub(/\{\{body\}\}/, tb) - print + line = $0 + line = lreplace(line, "{{css_variables}}", cv) + line = lreplace(line, "{{css_responsive}}", cr) + line = lreplace(line, "{{css_animations}}", ca) + line = lreplace(line, "{{css_noise}}", cn) + line = lreplace(line, "{{template_css}}", tc) + line = lreplace(line, "{{body}}", tb) + line = lreplace(line, "{{schema_jsonld}}", sc) + print line } ' <<< "$output" | sed \ -e "s|{{title}}|${title}|g" \ diff --git a/templates/base.html b/templates/base.html index 2148d21..bb7372a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,6 +8,7 @@ {{fonts}} +{{schema_jsonld}}