#!/usr/bin/env python3 """Build lynx-share.com: writes the static pages of website/ from the sources in website/_src/. python3 website/_src/build.py write the pages and the English string files python3 website/_src/build.py --check exit 1 if a written file is out of date (release step) Sources (all in _src/): pages/*.html body of Home, Features, Why, Download updates.json one entry per release catalog.json the built-in plugins (cards + wiki pages), catalog-img.json their picture sizes wiki/*.md + wiki/index.json the manual faq.md the FAQ strings.json English of strings that have no element of their own (plugins.js is not shown on the site any more; scripts/gen-inspired.py still writes it) Output: index.html, features/, why/, instruments-and-effects/, download/, updates/, wiki/, wiki//, wiki/built-in//, faq/ (each an index.html), wiki/search.json, i18n/catalog/en.json, i18n/en.json + i18n/updates/en.json (the English of every data-i18n key: what the translations are checked against) and i18n/latest/.json (the newest release's strings, for the box on Home). Python 3 standard library only. No page needs JavaScript to be read. """ import hashlib import html import json import re import sys from pathlib import Path SRC = Path(__file__).resolve().parent OUT = SRC.parent SITE = "https://lynx-share.com" REPO = "https://github.com/Ka1-S/LYNX-SHARE" KOFI = "https://ko-fi.com/lynxshare" # the donation page (optional; = lynx::links::donate in src/core/Links.h) LOGO_V = "0.1.26-logo2" # cache-buster of the logo pictures (logo by w3teal; its app-icon form since 2026-11-13) # the header/footer logo: at 1x the icon's small-size form (32 px, tools/make_logo.py), at 2x the 64 px icon, above that 256 px LOGO_SRCSET = (f"/assets/img/favicon-32.png?v={LOGO_V} 1x, /assets/img/favicon.png?v={LOGO_V} 2x, " f"/assets/img/logo.png?v={LOGO_V} 4x") LANGS = [["en", "English"], ["zh-Hans", "简体中文"], ["zh-Hant", "繁體中文"], ["nl", "Nederlands"], ["fr", "Français"], ["de", "Deutsch"], ["id", "Bahasa Indonesia"], ["it", "Italiano"], ["ja", "日本語"], ["ko", "한국어"], ["pl", "Polski"], ["pt-BR", "Português (Brasil)"], ["ru", "Русский"], ["es", "Español"], ["tr", "Türkçe"]] OGL = {"zh-Hans": "zh_CN", "zh-Hant": "zh_TW", "nl": "nl_NL", "fr": "fr_FR", "de": "de_DE", "id": "id_ID", "it": "it_IT", "ja": "ja_JP", "ko": "ko_KR", "pl": "pl_PL", "pt-BR": "pt_BR", "ru": "ru_RU", "es": "es_ES", "tr": "tr_TR"} NAV = [("features", "/features/", "nav.features", "Features"), ("learn", "/learn/", "nav.learn", "Learn"), ("why", "/why/", "nav.why", "Why LYNX"), ("cat", "/instruments-and-effects/", "nav.cat", "Plugins"), ("download", "/download/", "nav.download", "Download"), ("updates", "/updates/", "nav.updates", "Updates"), ("wiki", "/wiki/", "nav.wiki", "Wiki"), ("faq", "/faq/", "nav.faq", "FAQ")] # plugin catalogue: type, then its categories (catalog.json "cat") CATS = [("instrument", ["synth", "drums", "sampler"]), ("effect", ["eq", "dynamics", "reverb", "delay", "modulation", "distortion", "pitch", "stereo"]), ("tool", ["controller", "visual", "routing"])] TYPE_OF = {c: t for t, cs in CATS for c in cs} IC = { "win": '', "mac": '', "linux": '', } GLOBE = '' esc = lambda s: html.escape(str(s), quote=True).replace("'", "'") # (attributes are always in double quotes) STR = json.loads((SRC / "strings.json").read_text(encoding="utf-8")) T = {**STR["js"], **STR["text"]} # English by key, for strings written from here def tr(key, *args, tag="span", cls="", count=None): """An element carrying a translatable string: English.""" text = T[key] for i, a in enumerate(args): text = text.replace("{%d}" % i, str(a)) a = " data-args='%s'" % html.escape(json.dumps([str(x) for x in args], ensure_ascii=False), quote=True) if args else "" c = ' class="%s"' % cls if cls else "" if count is not None: # assets/motion.js counts this number up once, when it scrolls in a += ' data-count="%d"' % count return '<%s%s data-i18n="%s"%s>%s' % (tag, c, key, a, text, tag) # ---------------------------------------------------------------- markdown (the subset the wiki and the FAQ use) def inline(s): out, pos = [], 0 for m in re.finditer(r"`([^`]+)`", s): # code spans first: nothing inside them is markup out.append(_inline(s[pos:m.start()])) out.append("%s" % esc(m.group(1))) pos = m.end() out.append(_inline(s[pos:])) return "".join(out) def _inline(s): s = esc(s).replace("'", "'") s = re.sub(r"!\[([^\]]*)\]\(([^)\s]+)\)", r'\1', s) s = re.sub(r"\[([^\]]+)\]\(([^)\s]+)\)", r'\1', s) s = re.sub(r"\*\*([^*]+)\*\*", r"\1", s) s = re.sub(r"(?\1", s) return s def slug(s): return re.sub(r"[^a-z0-9]+", "-", s.lower()).strip("-") def markdown(text, ids=None): """ids: the heading ids to use, in order (a translated body keeps the English anchors).""" lines, out, i = text.strip("\n").split("\n"), [], 0 while i < len(lines): ln = lines[i] if not ln.strip(): i += 1 elif ln.startswith("```"): j = i + 1 while j < len(lines) and not lines[j].startswith("```"): j += 1 out.append("
%s
" % esc("\n".join(lines[i + 1:j]))) i = j + 1 elif re.match(r"#{2,3} ", ln): n = len(ln.split(" ")[0]) t = ln[n + 1:].strip() out.append('%s' % (n, next(ids, "") if ids is not None else slug(t), inline(t), n)) i += 1 elif ln.startswith("|"): rows = [] while i < len(lines) and lines[i].startswith("|"): rows.append([c.strip() for c in re.split(r"(?%s" % "".join("%s" % inline(c.replace("\\|", "|")) for c in r) for r in rows[2:]) head = "".join("%s" % inline(c) for c in rows[0]) out.append('
%s%s
' % (head, body)) elif re.match(r"(- |\d+\. )", ln): tag = "ul" if ln.startswith("- ") else "ol" pat = r"- " if tag == "ul" else r"\d+\. " items = [] while i < len(lines) and (re.match(pat, lines[i]) or (lines[i].startswith(" ") and items)): if re.match(pat, lines[i]): items.append(re.sub("^" + pat, "", lines[i])) else: items[-1] += " " + lines[i].strip() i += 1 out.append("<%s>%s" % (tag, "".join("
  • %s
  • " % inline(x) for x in items), tag)) elif ln.startswith("> "): buf = [] while i < len(lines) and lines[i].startswith(">"): buf.append(lines[i].lstrip("> ").strip()) i += 1 out.append("

    %s

    " % inline(" ".join(buf))) else: buf = [] while i < len(lines) and lines[i].strip() and not re.match(r"(#{2,3} |```|\||- |\d+\. |> )", lines[i]): buf.append(lines[i].strip()) i += 1 p = inline(" ".join(buf)) if re.fullmatch(r']+>', p): # a picture on its own line opens full size src = re.search(r'src="([^"]+)"', p).group(1) p = '
    %s
    ' % (src, p) out.append(p) else: out.append("

    %s

    " % p) return "\n".join(out) def front(path): text = path.read_text(encoding="utf-8") m = re.match(r"---\n(.*?)\n---\n(.*)", text, re.S) if not m: sys.exit("build: %s has no front matter" % path) meta = dict((k.strip(), v.strip()) for k, v in (ln.split(":", 1) for ln in m.group(1).splitlines() if ":" in ln)) return meta, m.group(2) # ---------------------------------------------------------------- shared page frame def head_script(version): # language before first paint: ?lang= > saved choice > browser languages > English (same rules as src/ui/I18nLocale.h) return """""" % (json.dumps(LANGS, ensure_ascii=False, separators=(",", ":")), version) SIZES = json.loads((SRC / "img-sizes.json").read_text(encoding="utf-8")) # written by import-shots.py SIZES.update({"/assets/img/plugins/%s.webp" % k: v[:2] for k, v in json.loads((SRC / "catalog-img.json").read_text(encoding="utf-8")).items()}) def dense_srcset(tag): """srcset with the @2x file when scripts/site-shots.sh drew one (twice the size, drawn by the program at 2x) for a picture of the site's own outside plugins/ (the plugin cards choose their srcset themselves, see plugin_img).""" src = re.search(r'\ssrc="(/assets/img/(?!plugins/)[^"?]+?)\.(webp|png)(\?[^"]*)?"', tag) if " srcset=" in tag or not src or not (OUT / (src.group(1) + "@2x." + src.group(2))[1:]).is_file(): return tag one = "%s.%s%s" % (src.group(1), src.group(2), src.group(3) or "") two = "%s@2x.%s%s" % (src.group(1), src.group(2), src.group(3) or "") return tag.replace(src.group(0), '%s srcset="%s 1x, %s 2x"' % (src.group(0), one, two), 1) def sized(page): """width and height on every picture of the site's own that lacks them: nothing is stretched, nothing jumps on load.""" def fix(m): tag = dense_srcset(m.group(0)) src = re.search(r'\ssrc="([^"?]+)', tag) if " width=" in tag or not src or src.group(1) not in SIZES: return tag return '%s width="%d" height="%d">' % (tag[:-1], *SIZES[src.group(1)]) return re.sub(r"]*>", fix, page) HERO_H1 = re.compile(r'(

    )(.*?)\s*(.*?)

    ', re.S) def hero_words(m): """The headline word by word (site.css animates .w in turn; assets/site.js writes the same for other languages).""" ws = m.group(2).split() return "%s%s %s" % ( m.group(1), " ".join('%s' % (i, w) for i, w in enumerate(ws)), len(ws), m.group(3)) def frame(path, cur, title_key, desc_key, body, version, scripts=(), part="", home=False, wt=""): """title_key: a string key, or ("", "Plain title") for a title that is the same in every language.""" plain = title_key[1] if isinstance(title_key, tuple) else None title_key = "" if plain else title_key title = T[title_key] if home else (plain or T[title_key]) + " · LYNX SHARE" desc = re.sub(r"<[^>]+>", "", T[desc_key]) url = SITE + path alts = "".join('\n' % (l, url, "" if l == "en" else "?lang=" + ("pt" if l == "pt-BR" else l)) for l, _ in LANGS) ogl = "".join('\n' % v for v in OGL.values()) nav = "".join('%s' % (h, ' aria-current="page"' if k == cur else "", key, en) for k, h, key, en in NAV if k != "download") attrs = (' data-title="%s"' % title_key if title_key else "") + ' data-desc="%s"' % desc_key + (' data-dict="%s"' % part if part else "") + (' data-home' if home else "") + (' data-wt="%s"' % wt if wt else "") js = "".join('\n' % (s, version) for s in ("/assets/site.js",) + tuple(scripts) + ("/assets/motion.js",)) body = HERO_H1.sub(hero_words, body) return f""" {title} {ogl} {alts} {head_script(version)}
    LYNX SHARE
    {body}
    LYNX SHARE © 2026 · AGPL-3.0 Logo by w3teal
    {js} """ # ---------------------------------------------------------------- updates def vkey(rel): return "u." + rel["version"].split("-")[0] # u.0.1.25 def item(text): return _inline_item(text) def _inline_item(s): return inline(s) GROUPS = [("new", "up.new", "n"), ("better", "up.better", "b"), ("fixed", "up.fixed", "f"), ("known", "up.known", "k")] def render_updates(rels): jump = "".join('%s' % (r["tag"], r["version"].split("-")[0]) for r in rels) out = ['

    %s

    %s

    ' % (T["up.h1"], T["up.sub"], jump), '
    '] for r in rels: k = vkey(r) num, _, stage = r["version"].partition("-") parts = ['

    %s%s

    %s
    ' % (r["tag"], r["tag"], num, "%s" % stage if stage else "", r["date"], r["date"], esc(r["url"]), T["up.gh"]), '

    %s

    %s

    ' % (k, inline(r["title"]), k, inline(r["summary"]))] if r.get("shots"): parts.append('
    %s
    ' % "".join( '
    %s
    ' % (s["src"], s["src"], esc(s["alt"])) for s in r["shots"])) for g, gkey, short in GROUPS: items = r.get(g) or [] if items: parts.append('

    %s

      %s
    ' % (g, gkey, T[gkey], "".join( '
  • %s
  • ' % (k, short, i, inline(x)) for i, x in enumerate(items)))) parts.append("
    ") out.append("".join(parts)) out.append("
    ") return "\n".join(out) def render_latest(r): k = vkey(r) items = "".join('
  • %s
  • ' % (k, i, inline(x)) for i, x in enumerate((r.get("new") or [])[:4])) return ('
    %s
    %s
    ' '

    %s

    %s

      %s
    ' '

    %s

    ' % (r["version"], r["date"], r["date"], esc(r["url"]), T["up.gh"], k, inline(r["title"]), k, inline(r["summary"]), items, r["tag"], T["home.latestAll"])) # ---------------------------------------------------------------- built-in plugin catalogue def catalog(): """catalog.json: one entry per built-in plugin of the released version; catalog-img.json: picture sizes (import-shots.py).""" items = json.loads((SRC / "catalog.json").read_text(encoding="utf-8")) dims = json.loads((SRC / "catalog-img.json").read_text(encoding="utf-8")) order = [c for _, cs in CATS for c in cs] for p in items: p["type"] = TYPE_OF[p["cat"]] p["dim"] = dims.get(p["id"]) T["c." + p["id"]] = inline(p["desc"]) items.sort(key=lambda p: (order.index(p["cat"]), p["name"].lower())) return items def plugin_tags(p): out = '%s%s' % ( p["type"], p["type"], T["cat.t." + p["type"]], p["cat"], T["cat.c." + p["cat"]]) if p.get("flp"): out += tr("cat.flp", esc(p["flp"]), cls="tag flp") return out def plugin_img(p, lazy=True, card=False): """width/height are the picture's own size, so it is never shown larger. Editors that 0.1.25 could also draw at twice the size have @2x.webp for dense screens; a card is small enough for the first file unless it is narrow.""" if not p["dim"]: return '%s' % esc(p["name"]) # no picture of this editor: a name plate, not a fake src = "/assets/img/plugins/%s.webp" % p["id"] dense = ' srcset="%s 1x, %s 2x"' % (src, src.replace(".webp", "@2x.webp")) if len(p["dim"]) > 2 and not (card and p["dim"][0] >= 720) else "" return '%s' % (src, dense, esc(p["name"]), p["dim"][0], p["dim"][1], ' loading="lazy"' if lazy else "") def render_catalog(cat, version): n = lambda f: sum(1 for p in cat if f(p)) chips = ['%s%d' % (T["cat.all"], len(cat), len(cat))] body = [] for ty, cs in CATS: chips.append('%s%d' % (ty, ty, ty, T["cat.g." + ty], n(lambda p: p["type"] == ty), n(lambda p: p["type"] == ty))) body.append('

    %s %d

    ' % (ty, ty, ty, T["cat.g." + ty], n(lambda p: p["type"] == ty), n(lambda p: p["type"] == ty))) for c in cs: mine = [p for p in cat if p["cat"] == c] if not mine: continue chips.append('%s%d' % (c, c, c, T["cat.c." + c], len(mine))) cards = [] for p in mine: href = "/wiki/built-in/%s/" % p["id"] if p.get("wiki") else "" pic = plugin_img(p, card=True) name = esc(p["name"]) cards.append('
    %s

    %s

    %s

    %s
    ' % ( p["id"], '' % (href, pic) if href else '
    %s
    ' % pic, '%s' % (href, name) if href else name, p["id"], T["c." + p["id"]], plugin_tags(p))) body.append('

    %s %d

    %s
    ' % (c, ty, c, T["cat.c." + c], len(mine), "".join(cards))) return ('

    %s

    %s
    ' '
    %s

    %s

    ' % (T["cat.h1"], tr("cat.sub", len(cat), version, tag="p", count=len(cat)), "".join(chips), "".join(body), T["cat.tm"])) def render_whyrow(cat): cells = "".join('%s%s' % (a, k, T["why.%s.t" % k], k, T["why.%s.l" % k]) for a, k in (("online", "online"), ("projects", "projects"), ("fl-settings", "fl"), ("workflows", "work"), ("crash", "crash"), ("free", "free"))) cells += '%s%s' % (tr("home.catT", len(cat), tag="b", count=len(cat)), T["home.catL"]) return '
    %s
    ' % cells # ---------------------------------------------------------------- wiki + FAQ def wiki_pages(): index = json.loads((SRC / "wiki/index.json").read_text(encoding="utf-8")) pages = {} for g in index: for s in g["pages"] + g.get("hidden", []): meta, body = front(SRC / "wiki" / (s + ".md")) pages[s] = {"slug": s, "meta": meta, "body": body, "prose": markdown(body)} T["wk.%s.t" % s] = meta["title"] T["wk.%s.s" % s] = meta["summary"] T[g["key"]] = g["title"] return index, pages def wiki_order(index, cat): """Every wiki page in reading order: (address, title key or "", English title, group key).""" out = [] for g in index: out += [("/wiki/%s/" % s, "wk.%s.t" % s, T["wk.%s.t" % s], g["key"]) for s in g["pages"]] if g.get("catalog"): out += [("/wiki/built-in/%s/" % p["id"], "", p["name"], g["key"]) for p in cat if p.get("wiki")] return out def wlink(e, cur="", tag=""): url, key, title = e[0], e[1], e[2] inner = '<%s%s>%s' % (tag or "span", ' data-i18n="%s"' % key if key else "", esc(title), tag or "span") if (tag or key) else esc(title) if not tag and key: return '%s' % (url, ' aria-current="page"' if url == cur else "", key, esc(title)) return '%s' % (url, ' aria-current="page"' if url == cur else "", inner) SEARCH = ('
    ' 'Ctrl K
    ') def wiki_nav(index, cat, cur): out = ['") return "".join(out) def enonly(url): """The "English only" note, on pages some language has no translated body for (html.wt hides it for the others).""" return "" if len(BODY_LANGS.get(url, ())) == len(LANGS) - 1 else '

    %s

    ' % T["wiki.enOnly"] def wiki_shell(index, cat, order, url, head, prose, toc): n = [e[0] for e in order].index(url) if url in [e[0] for e in order] else -1 prev = '%s%s' % (order[n - 1][0], T["wiki.prev"], wlink(order[n - 1], tag="b")[len('' % order[n - 1][0]):-4]) if n > 0 else "" nxt = '%s%s' % (order[n + 1][0], T["wiki.next"], wlink(order[n + 1], tag="b")[len('' % order[n + 1][0]):-4]) if 0 <= n < len(order) - 1 else "" tocbox = "" if len(toc) > 1: tocbox = '' % ( T["wiki.toc"], "".join('
  • %s
  • ' % (i, ' data-i18n="%s"' % k if k else "", t) for i, k, t in toc)) return ('
    %s
    %s%s' '%s
    %s
    %s
    ' % (wiki_nav(index, cat, url), T["wiki.all"], head, enonly(url), " hastoc" if tocbox else "", tocbox, prose, prev, nxt)) def render_wiki_page(index, cat, order, pages, s): p = pages[s] short = ' %s' % T["wiki.short"] if p["meta"].get("status") == "short" else "" head = '

    %s%s

    %s

    ' % (s, esc(T["wk.%s.t" % s]), short, s, esc(T["wk.%s.s" % s])) prose = p["prose"] toc = [(i, "", t) for i, t in re.findall(r'

    (.*?)

    ', prose)] p["heads"] = [re.sub(r"<[^>]+>", "", t) for _, _, t in toc] return wiki_shell(index, cat, order, "/wiki/%s/" % s, head, prose, toc) def plugin_prose(p, cat, w): """The body of a plugin's page from its texts w (English, or a translation of them); returns (html, toc).""" parts = [] if p["dim"]: src = "/assets/img/plugins/%s%s.webp" % (p["id"], "@2x" if len(p["dim"]) > 2 else "") parts.append('
    %s
    ' % (src, plugin_img(p, lazy=False))) parts.append("

    %s

    " % inline(w["intro"])) toc = [] if w.get("controls"): toc.append(("controls", "wiki.controls", T["wiki.controls"])) parts.append('

    %s

    %s
    %s%s
    ' % (T["wiki.controls"], T["wiki.control"], T["wiki.does"], "".join("%s%s" % (inline(a), inline(b)) for a, b in w["controls"]))) if w.get("tips"): toc.append(("tips", "wiki.tips", T["wiki.tips"])) parts.append('

    %s

      %s
    ' % (T["wiki.tips"], "".join("
  • %s
  • " % inline(t) for t in w["tips"]))) toc.append(("related", "wiki.related", T["wiki.related"])) parts.append('' % (T["wiki.related"], T["wiki.relOverview"], p["cat"], tr("wiki.relCat", len(cat)))) return "".join(parts), toc def render_plugin_page(index, cat, order, p): head = '

    %s

    %s

    %s
    ' % (esc(p["name"]), p["id"], T["c." + p["id"]], plugin_tags(p)) prose, toc = plugin_prose(p, cat, p["wiki"]) return wiki_shell(index, cat, order, "/wiki/built-in/%s/" % p["id"], head, prose, toc) # ---------------------------------------------------------------- translated wiki bodies BODY_LANGS = {} # page address -> the languages that have its body def digest(text): return hashlib.sha1(text.strip().encode("utf-8")).hexdigest()[:10] def plugin_source(w): """What a plugin page's translation was made from (its digest goes into the translation as "source").""" return json.dumps([w["intro"], w.get("controls", []), w.get("tips", [])], ensure_ascii=False) def wiki_bodies(index, pages, cat, learn=None): """The wiki bodies in other languages, shown in place of the English body by assets/site.js. Articles: _src/wiki//.md (front matter "source": digest of the English body it was made from). Plugin pages: _src/catalog-wiki/.json {plugin id: {"source", "intro", "controls", "tips"}}. A body whose source no longer matches the English is left out (scripts/check-site-i18n.py reports it). Written to i18n/wiki//.html and built-in/.html, plus heads.json for the search.""" files = {} for lang, _ in LANGS[1:]: heads = {} for s, p in pages.items(): f = SRC / "wiki" / lang / (s + ".md") if not f.exists(): continue meta, body = front(f) if meta.get("source") != digest(p["body"]): continue ids = re.findall(r']+>", "", t)] for i, t in re.findall(r'

    (.*?)

    ', prose)] BODY_LANGS.setdefault(url, []).append(lang) for s, p in (learn or {}).items(): # tutorial pages: _src/learn//.md f = SRC / "learn" / lang / (s + ".md") if not f.exists(): continue meta, body = front(f) if meta.get("source") != digest(p["body"]): continue ids = re.findall(r'%s%s' % (s, s, esc(T["wk.%s.t" % s]), s, esc(T["wk.%s.s" % s])) for s in g["pages"]] count = len(g["pages"]) if g.get("catalog"): withpage = [p for p in cat if p.get("wiki")] count += len(withpage) for ty, _ in CATS: rows.append('
  • %s (%d)
  • ' % (ty, ty, T["cat.g." + ty], sum(1 for p in withpage if p["type"] == ty))) rows.append('
  • %s
  • ' % tr("wiki.catLink", len(cat))) rows += ['
  • %s
  • ' % (h, k, en) for h, k, en in g.get("links", [])] cards.append('

    %s

    %s

    %s

      %s
    ' % (g["key"], esc(g["title"]), tr("wiki.pages", count, count=count), g["key"], T[g["key"] + ".d"], "".join(rows))) return ('

    %s

    %s

    %s
    ' '
    ' '%s
    %s
    ' % (T["wiki.h1"], T["wiki.sub"], SEARCH % (T["ws.ph"], T["ws.ph"]), enonly("/wiki/"), "".join(cards))) def render_faq(): meta, body = front(SRC / "faq.md") out = ['

    %s

    %s

    ' % (T["faq.h1"], T["faq.sub"])] for n, sec in enumerate(re.split(r"^## ", body, flags=re.M)[1:], 1): q, _, a = sec.partition("\n") out.append('

    %s

    %s
    ' % (slug(q)[:48].strip("-"), n, inline(q.strip()), n, markdown(a).replace("\n", ""))) out.append("
    ") return "".join(out) # ---------------------------------------------------------------- learn: tutorials (a video + its written steps) # _src/learn/index.json: the tutorials in order; _src/learn/.md: title, summary and the written steps (the same # markdown as the wiki; translations in _src/learn//.md with the "source" digest, shown by assets/site.js # from i18n/wiki//learn/.html like a wiki body); _src/learn/media.json: the big files (MP4) that live on the # repository's `media` branch under site/ and are put into the site by scripts/site-media.sh (deploy-site.sh runs it). MEDIA = "/assets/media/learn/" LAYOUT_KEYS = {"simple": "lr.l.simple", "pattern": "lr.l.pattern", "clipLaunch": "lr.l.clip", "any": "lr.l.any"} def learn_data(): data = json.loads((SRC / "learn/index.json").read_text(encoding="utf-8")) pages = {} for t in data["tutorials"]: s = t["slug"] meta, body = front(SRC / "learn" / (s + ".md")) pages[s] = {"slug": s, "meta": meta, "body": body, "prose": markdown(body), "t": t} T["lt.%s.t" % s] = meta["title"] T["lt.%s.s" % s] = meta["summary"] for i, (_, name) in enumerate(t.get("chapters", [])): T["lt.%s.c%d" % (s, i)] = name return data, pages def media_files(): """The files of _src/learn/media.json (site address -> {"size", "sha256"}): on the `media` branch, not in this tree.""" f = SRC / "learn/media.json" return json.loads(f.read_text(encoding="utf-8")) if f.exists() else {} def youtube_id(url): m = re.search(r"(?:youtu\.be/|[?&]v=|/shorts/|/embed/)([\w-]{11})", url or "") return m.group(1) if m else "" def mmss(sec): sec = int(round(float(sec))) return "%d:%02d" % (sec // 60, sec % 60) def mb(n): return "%.1f MB" % (n / 1e6) def tutorial_video(t, files): """The self-hosted video: the 1080p file on wide screens, else 720p; captions in every language that has a .vtt. Nothing loads before Play (preload="none"); width/height + aspect-ratio keep the page from moving. assets/learn.js swaps in the narration of the reader's language (t["voices"]) and turns its captions on. A YouTube address in index.json adds a click-to-load player: nothing comes from YouTube before that click.""" v, voices = t["video"], t["voices"] caps = [l for l, _ in LANGS if (OUT / ("assets/media/learn/%s-%s.vtt" % (v, l))).is_file()] names = dict(LANGS) src = lambda l, q: "%s%s-%s-%s.mp4" % (MEDIA, v, l, q) sources = ('' % (src("en", "1080"), src("en", "720"))) tracks = "".join('' % (l, esc(names[l]), MEDIA, v, l) for l in caps) yt = {l: youtube_id(u) for l, u in (t.get("youtube") or {}).items() if youtube_id(u)} attrs = ' data-voices="%s" data-v="%s"' % (" ".join(voices), v) + (" data-yt='%s'" % esc(json.dumps(yt)) if yt else "") dl = " · ".join('%s' % (src("en", q), "%sp, %s" % (q, mb(files.get(src("en", q)[1:], {}).get("size", 0)))) for q in ("720", "1080")) ytb = ('

    ' 'The YouTube player loads only after this click.

    ') if yt else "" return ('
    ' '
    Download the video: %s · Captions in every language of this site (CC button).
    %s
    ' % (attrs, v, sources, tracks, dl, ytb)) def tutorial_meta(t): return '%s · %s · %s' % ( LAYOUT_KEYS[t["layout"]], T[LAYOUT_KEYS[t["layout"]]], mmss(t["length"]), t["level"], T["lr.lv." + t["level"]]) def render_tutorial(data, pages, s, files): p = pages[s] t = p["t"] order = [x["slug"] for x in data["tutorials"]] n = order.index(s) chapters = "".join('
  • ' % (c[0], mmss(c[0]), s, i, esc(c[1])) for i, c in enumerate(t.get("chapters", []))) pn = lambda k, key, align: ('%s%s' % ( k, ' style="text-align:right"' if align else "", key, T[key], k, esc(T["lt.%s.t" % k]))) prev = pn(order[n - 1], "wiki.prev", False) if n > 0 else "" nxt = pn(order[n + 1], "wiki.next", True) if n < len(order) - 1 else "" url = "/learn/%s/" % s return ('

    Learn

    ' '

    %s

    %s

    %s

    ' '
    %s
    ' '
    %s
    %s
    ' % (s, esc(T["lt.%s.t" % s]), s, esc(T["lt.%s.s" % s]), tutorial_meta(t), tutorial_video(t, files), chapters, enonly(url), p["prose"], prev, nxt)) COMING = [ # the "Coming from..." cards of the Learn hub: wiki page, string key, English ("coming-from-bandlab", "lr.from.mobile", "BandLab, FL Studio Mobile or GarageBand"), ("coming-from-fl-studio", "lr.from.fl", "FL Studio"), ("coming-from-ableton", "lr.from.live", "Ableton Live or Bitwig"), ("coming-from-other-daws", "lr.from.other", "Logic, Cubase or Reaper"), ] def render_learn(data, pages): cards = [] for t in data["tutorials"]: s = t["slug"] cards.append('' % (s, t["video"], mmss(t["length"]), s, s, esc(T["lt.%s.t" % s]), s, esc(T["lt.%s.s" % s]), tutorial_meta(t))) froms = "".join('Coming from%s' % (w, k, en) for w, k, en in COMING) froms += 'New to music software?Start with the Simple layout' return ('

    Learn LYNX SHARE

    Short videos with the same steps written out, and a page for each program you may be coming from.

    ' '
    ' '
    1. DownloadFree for Windows, macOS and Linux. Download page
    2. ' '
    3. Pick how you like to workThe first start asks where you are coming from and opens the layout that fits. Later: View › Layout style.
    4. ' '
    5. Watch a first videoOne minute: make a beat in the Simple layout.
    ' '

    Tutorials

    %s
    ' '

    Coming from another program?

    What is the same, what is different, which layout to pick and where things are.

    %s
    ' '

    Program names on this page are trademarks of their owners. LYNX SHARE is an independent program, not affiliated with or endorsed by them.

    ' '

    More in the wiki: your first song, the three layouts and every shortcut.

    ' '
    ' % ("".join(cards), froms)) # ---------------------------------------------------------------- English strings out of the built pages ELEM = re.compile(r'<(\w+)\b([^>]*?)\sdata-i18n="([^"]+)"([^>]*)>(.*?)', re.S) def fill_args(page): """Elements written with data-args in a page source hold {0}-style English: show the filled text.""" def sub(m): attrs = m.group(2) + m.group(4) a = re.search(r"data-args='([^']*)'", attrs) if not a or "{0}" not in m.group(5): return m.group(0) text = m.group(5) T.setdefault(m.group(3), text) for i, v in enumerate(json.loads(html.unescape(a.group(1)))): text = text.replace("{%d}" % i, v) return "<%s%s data-i18n=\"%s\"%s>%s" % (m.group(1), m.group(2), m.group(3), m.group(4), text, m.group(1)) return ELEM.sub(sub, page) def collect(page, en, where): def put(k, v): if k in T and "{0}" in T[k]: v = T[k] # the template, not this element's filled text if en.setdefault(k, v) != v: sys.exit("build: '%s' has two different English texts (%s):\n %s\n %s" % (k, where, en[k], v)) for m in ELEM.finditer(page): put(m.group(3), m.group(5)) for v, k in re.findall(r'alt="([^"]*)" data-i18n-alt="([^"]+)"', page): put(k, v) for v, k in re.findall(r'aria-label="([^"]*)"[^>]*data-i18n-aria="([^"]+)"', page): put(k, v) for v, k in re.findall(r'placeholder="([^"]*)" data-i18n-ph="([^"]+)"', page): put(k, v) m = re.search(r'

    (.*?)

    ', page, re.S) if m: put(m.group(1), re.sub(r'\s*(.*?)', r"|\1", m.group(2))) def main(): check = "--check" in sys.argv rels = json.loads((SRC / "updates.json").read_text(encoding="utf-8")) latest = rels[0] index, pages = wiki_pages() cat = catalog() order = wiki_order(index, cat) ldata, lpages = learn_data() mfiles = media_files() body_files = wiki_bodies(index, pages, cat, lpages) full = [l for l, _ in LANGS[1:] if all(l in BODY_LANGS.get(e[0], ()) for e in order)] if full: BODY_LANGS["/wiki/"] = full # the index page: languages with every body collect((SRC / "pages/why.html").read_text(encoding="utf-8"), T, "why") # Home's row reuses the Why page's headings sub = {"VER_UP": latest["version"].upper(), "VER_LINE": "v" + latest["version"], "LATEST": render_latest(latest), "IC_WIN": IC["win"], "IC_MAC": IC["mac"], "IC_LINUX": IC["linux"], "OS_BTNS": "".join('%s%s%s' % (o, o, REPO, IC[o], name, k, T[k]) for o, name, k in (("win", "Windows", "dl.fInstaller"), ("mac", "macOS", "dl.fUniversal"), ("linux", "Linux", "dl.fAppImage"))), "WHYROW": render_whyrow(cat), "CAT_SUB": tr("cat.sub", len(cat), latest["version"].split("-")[0], tag="p", count=len(cat)), "WHY_FL_P1": T["why.fl.p1"], "WHY_FL_X2": T["why.fl.x2"], "KOFI": KOFI} def page(name): body = (SRC / "pages" / (name + ".html")).read_text(encoding="utf-8") body = re.sub(r"\{\{(\w+)\}\}", lambda m: sub[m.group(1)], body) return fill_args(body) bodies = [ # path, nav item, title key, description key, body, scripts, extra dictionary ("/", "home", "m.home.t", "m.home.d", page("home"), (), "latest"), ("/features/", "features", "fe.h1", "m.features.d", page("features"), ("/assets/features.js",), ""), ("/download/", "download", "dlp.h1", "m.download.d", page("download"), (), ""), ("/why/", "why", "why.h1", "m.why.d", page("why"), (), ""), ("/fixes/", "fixes", "fix.h1", "m.fixes.d", page("fixes"), (), ""), ("/instruments-and-effects/", "cat", "cat.h1", "m.cat.d", render_catalog(cat, latest["version"].split("-")[0]), ("/assets/catalog.js",), "catalog"), ("/updates/", "updates", "up.h1", "m.updates.d", render_updates(rels), (), "updates"), ("/wiki/", "wiki", "wiki.h1", "m.wiki.d", render_wiki_index(index, cat, pages), ("/assets/wiki.js",), ""), ("/faq/", "faq", "faq.h1", "m.faq.d", render_faq(), (), ""), ("/learn/", "learn", "lr.h1", "m.learn.d", render_learn(ldata, lpages), (), ""), ] + [("/learn/%s/" % s, "learn", "lt.%s.t" % s, "lt.%s.s" % s, render_tutorial(ldata, lpages, s, mfiles), ("/assets/learn.js",), "") for s in lpages] + [("/wiki/%s/" % s, "wiki", "wk.%s.t" % s, "wk.%s.s" % s, render_wiki_page(index, cat, order, pages, s), ("/assets/wiki.js",), "") for g in index for s in g["pages"] + g.get("hidden", []) ] + [("/wiki/built-in/%s/" % p["id"], "wiki", ("", p["name"]), "c." + p["id"], render_plugin_page(index, cat, order, p), ("/assets/wiki.js",), "catalog") for p in cat if p.get("wiki")] # the wiki search: address, title key, English title, group key, headings heads = {"/wiki/%s/" % s: pages[s].get("heads", []) for s in pages} search = [[u, k, t, g, heads.get(u, [])] for u, k, t, g in order] en = dict(T) for b in bodies: collect(b[4], en, b[0]) T.update(en) collect(frame("/", "", "m.home.t", "m.home.d", "", "0", home=True), en, "frame") ui = {k: v for k, v in en.items() if not k.startswith(("u.", "c."))} upd = {k: v for k, v in en.items() if k.startswith("u.")} cen = {k: v for k, v in en.items() if k.startswith("c.")} dump = lambda d: json.dumps(d, ensure_ascii=False, indent=0) + "\n" files = dict(body_files) files.update({"i18n/en.json": dump({"ui": ui, "featured": {}, "insp": {}}), "i18n/updates/en.json": dump(upd), "i18n/catalog/en.json": dump(cen), "wiki/search.json": json.dumps({"g": {g["key"]: g["title"] for g in index}, "p": search}, ensure_ascii=False, separators=(",", ":")) + "\n"}) lk = vkey(latest) + "." for f in sorted((OUT / "i18n/updates").glob("*.json")) if (OUT / "i18n/updates").is_dir() else []: d = upd if f.stem == "en" else json.loads(f.read_text(encoding="utf-8")) files["i18n/latest/%s.json" % f.stem] = dump({k: v for k, v in d.items() if k.startswith(lk)}) files["i18n/latest/en.json"] = dump({k: v for k, v in upd.items() if k.startswith(lk)}) # one version stamp for css/js/json addresses: changes when any of them does stamp = hashlib.sha1() for name in ("assets/site.css", "assets/site.js", "assets/features.js", "assets/catalog.js", "assets/wiki.js", "assets/learn.js", "assets/motion.js"): stamp.update((OUT / name).read_bytes()) for name in sorted(files): stamp.update(files[name].encode()) for f in sorted((OUT / "i18n").glob("*.json")) + sorted((OUT / "i18n/catalog").glob("*.json")): if f.name != "en.json": stamp.update(f.read_bytes()) version = stamp.hexdigest()[:8] for path, cur, tk, dk, body, scripts, part in bodies: files[(path.strip("/") + "/index.html").lstrip("/")] = frame(path, cur, tk, dk, body, version, scripts, part, home=path == "/", wt=" ".join(BODY_LANGS.get(path, ())) if path.startswith(("/wiki/", "/learn/")) else "") files = {name: sized(text) if name.endswith(".html") else text for name, text in files.items()} stale = [str(f.relative_to(OUT)) for f in sorted((OUT / "i18n/wiki").glob("**/*.*")) if str(f.relative_to(OUT)) not in files] if not check: for name in stale: # bodies whose translation is gone or out of date (OUT / name).unlink() for name, text in files.items(): f = OUT / name if not f.exists() or f.read_text(encoding="utf-8") != text: stale.append(name) if not check: f.parent.mkdir(parents=True, exist_ok=True) f.write_text(text, encoding="utf-8") if check and stale: print("build: out of date:", ", ".join(stale), "(run website/_src/build.py)") return 1 print("build: %d files, %d strings + %d update strings + %d catalogue strings, %s" % (len(files), len(ui), len(upd), len(cen), "up to date" if check else "%d written" % len(stale))) return 0 if __name__ == "__main__": sys.exit(main())