Divan-owned content takes precedence over Wikisource #1

Merged
anas merged 1 commits from feature/divan-owned-content into main 2026-10-09 12:33:09 +00:00
2 changed files with 34 additions and 1 deletions

12
divan/README.md Normal file
View File

@ -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).
- `<work url>.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.
- `<work url>.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`.

View File

@ -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]} 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 <work url>.dtx (the readable source,
# written by the Divan app) and <work url>.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(): def main():
for p in ("poets", "index"): for p in ("poets", "index"):
shutil.rmtree(os.path.join(D, p), ignore_errors=True) shutil.rmtree(os.path.join(D, p), ignore_errors=True)
@ -161,11 +175,18 @@ def main():
c = cat(path) c = cat(path)
wid = gid("poem", title) wid = gid("poem", title)
shown = ud(title.replace("/", " ۔ ")) shown = ud(title.replace("/", " ۔ "))
v, couplets = verses(ud(text), kind == "prose")
fmt = "Ghazal" if any("غزل" in s for s in path) else None fmt = "Ghazal" if any("غزل" in s for s in path) else None
purl_ = f"{c['FullUrl']}/sh{wid}" 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]) full_title = " » ".join([name, *map(ud, path), shown])
write(f"poets{purl_}.json", { 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_, "Id": wid, "CatId": c["Id"], "Title": shown, "FullTitle": full_title, "FullUrl": purl_,
"RhymeLetters": None, "SourceName": "ویکی ماخذ", "SourceUrlSlug": "wikisource", "SourceUrl": url, "RhymeLetters": None, "SourceName": "ویکی ماخذ", "SourceUrlSlug": "wikisource", "SourceUrl": url,
"Language": "ur-PK", "PoemSummary": None, "Metre": None, "Language": "ur-PK", "PoemSummary": None, "Metre": None,