diff --git a/divan/README.md b/divan/README.md new file mode 100644 index 000000000..a4a7a0edf --- /dev/null +++ b/divan/README.md @@ -0,0 +1,12 @@ +# Divan-owned content + +Works edited or published in Divan, kept here so the daily Wikisource sync never overwrites them +(Divan's copy takes precedence; see the divan app, docs/content-model.md). + +- `.dtx`: the work in Divan text, the readable source (one misra or paragraph per line, + so git diffs show exactly what changed). Written by the Divan app when a moderator's change is + published. +- `.json`: generated from the `.dtx` by the app: `Title`, `Verses` (the site's verse layout) + and `Edited` (who and when). `export_divan.py` uses it in place of the Wikisource text. + +The work url is the site path, e.g. `p266/ghazal/sh7870` for `/p266/ghazal/sh7870`. diff --git a/export_divan.py b/export_divan.py index e3f759d9c..1cf39ce1e 100644 --- a/export_divan.py +++ b/export_divan.py @@ -118,6 +118,20 @@ def ghazal_marks(v): return {**out, "Radif": " ".join(cs[0][1][0].split()[-n:]) if n else "", "Matla": cs[0][0]} +# Divan-owned content (#30): works edited in Divan live in divan/ as .dtx (the readable source, +# written by the Divan app) and .json (generated from it: Title, Verses, Edited). Their text +# takes precedence over Wikisource; the Wikisource sync keeps running but never overwrites them. +DIVAN_DIR = os.path.join(D, "divan") + + +def owned(url): + path = os.path.join(DIVAN_DIR, url.lstrip("/") + ".json") + if not os.path.exists(path): + return None + with open(path, encoding="utf-8") as f: + return json.load(f) + + def main(): for p in ("poets", "index"): shutil.rmtree(os.path.join(D, p), ignore_errors=True) @@ -161,11 +175,18 @@ def main(): c = cat(path) wid = gid("poem", title) shown = ud(title.replace("/", " ۔ ")) - v, couplets = verses(ud(text), kind == "prose") fmt = "Ghazal" if any("غزل" in s for s in path) else None purl_ = f"{c['FullUrl']}/sh{wid}" + own = owned(purl_) # Divan's version takes precedence over Wikisource's + if own: + v = own["Verses"] + couplets = len({x["CoupletIndex"] for x in v}) + shown = own.get("Title") or shown + else: + v, couplets = verses(ud(text), kind == "prose") full_title = " » ".join([name, *map(ud, path), shown]) write(f"poets{purl_}.json", { + **({"DivanOwned": True, "Edited": own.get("Edited")} if own else {}), "Id": wid, "CatId": c["Id"], "Title": shown, "FullTitle": full_title, "FullUrl": purl_, "RhymeLetters": None, "SourceName": "ویکی ماخذ", "SourceUrlSlug": "wikisource", "SourceUrl": url, "Language": "ur-PK", "PoemSummary": None, "Metre": None,