feat: multi-language blog posts — add blog.es.json, blog.de.json; load by locale with EN fallback

This commit is contained in:
Oliver
2026-03-27 16:40:03 -03:00
parent 3627c2c73d
commit 5bd3c7b398
5 changed files with 106 additions and 27 deletions
+35 -9
View File
@@ -24,7 +24,9 @@ Single-page static landing page for an NGO ERP product.
index.html ← only HTML file — layout + all inline JS + i18n
src/input.css ← Tailwind source (edit here, then rebuild)
assets/site.css ← compiled output — DO NOT edit by hand
blog.json ← blog post data array
blog.json ← English blog posts (canonical + fallback)
blog.es.json ← Spanish blog posts
blog.de.json ← German blog posts
tailwind.config.js ← design tokens (colors, fonts, shadows)
```
@@ -106,7 +108,21 @@ jq empty blog.json && echo "JSON valid"
## Blog Post Schema
`blog.json` is a root-level JSON array. Every post object contains **exactly these five fields**:
### Language-to-file mapping
| Language | File loaded | Fallback |
|---|---|---|
| English (`en`) | `blog.json` | — |
| Spanish (`es`) | `blog.es.json` | `blog.json` |
| German (`de`) | `blog.de.json` | `blog.json` |
The loader in `index.html` fetches the language-specific file automatically when the visitor switches language. If a language file is missing or returns an error, it falls back to `blog.json` silently.
`blog.json` is always the **English source and fallback**. Keep all three files structurally identical — same number of posts, same order, translated content only.
---
`blog.json` (and every language variant) is a root-level JSON array. Every post object contains **exactly these five fields**:
```json
[
@@ -132,21 +148,31 @@ NEVER add extra fields (`slug`, `author`, `tags`, `excerpt`, `hero_image`, etc.)
### Adding a new blog post (jq method)
> Add to **all three files** in the same session. A post that exists in English but not in Spanish/German will silently fall back to the English version for those visitors — which is acceptable temporarily but should be resolved promptly.
```bash
# 1. Pull latest
git pull origin main
# 2. Backup (once per session)
mkdir -p /backup && cp blog.json /backup/blog.json.$(date +%Y%m%d%H%M%S)
# 2. Backup all blog files once per session
mkdir -p /backup
for f in blog.json blog.es.json blog.de.json; do
cp $f /backup/$f.$(date +%Y%m%d%H%M%S)
done
# 3. Prepend new post — $NEW_JSON must be a valid single post object
jq --argjson new "$NEW_JSON" '. = [$new] + .' blog.json > tmp.json && mv tmp.json blog.json
# 3. Prepend new post to each language file
# $NEW_EN, $NEW_ES, $NEW_DE must each be a valid single post object
jq --argjson new "$NEW_EN" '. = [$new] + .' blog.json > tmp.json && mv tmp.json blog.json
jq --argjson new "$NEW_ES" '. = [$new] + .' blog.es.json > tmp.json && mv tmp.json blog.es.json
jq --argjson new "$NEW_DE" '. = [$new] + .' blog.de.json > tmp.json && mv tmp.json blog.de.json
# 4. Validate
jq empty blog.json && echo "JSON valid"
# 4. Validate all three
jq empty blog.json && echo "blog.json OK"
jq empty blog.es.json && echo "blog.es.json OK"
jq empty blog.de.json && echo "blog.de.json OK"
# 5. Commit and push
git add blog.json
git add blog.json blog.es.json blog.de.json
git commit -m "blog: add post <title>"
git push origin main
```