From b669a2104b12a7587578733e9fdc3634f924b5e8 Mon Sep 17 00:00:00 2001 From: gauthiier Date: Fri, 12 Aug 2022 13:21:59 +0200 Subject: [PATCH] indexurl --- pppadump/commands/index.py | 63 +++++++++++++++++++++++++++----------- pppadump/commands/init.py | 10 ++++++ 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/pppadump/commands/index.py b/pppadump/commands/index.py index b203d0c..48408dd 100644 --- a/pppadump/commands/index.py +++ b/pppadump/commands/index.py @@ -98,6 +98,8 @@ def main (args): p.add_argument("--files", default=False, action="store_true", help="include files (experimental)") + p.add_argument("--filebased", default=False, action="store_true", help="uses (reconstructed) urls instead of file paths") + pg = p.add_argument_group('template variables') pg.add_argument("--feedurl", default="feed.xml", help="rss: to use as feeds own (self) link, default: feed.xml") pg.add_argument("--siteurl", default=None, help="rss: to use as channel's site link, default: the etherpad url") @@ -291,30 +293,55 @@ def main (args): except KeyError as e: pass + + # Below is somehow a mess since one the one hand I'm trying to keep the file based publiching + # ethos while my setup is not really (reverse proxy, etc.) + # Fix (1): settings.json has indexurl which stands for the base URL + # Fix (2): added argument - # Not sure this goes here but fixing relpaths with output is quite nice... if args.output: - outpath = Path(args.output).parent - for v in p["versions"]: - if v["type"] != "pad": - vpath = Path(v["path"]) - try: - # 2 types (pathlib or os.path) - # v["path"] = vpath.parent.relative_to(outpath).joinpath(vpath.name) - v["path"] = os.path.join(os.path.relpath(vpath.parent, outpath), vpath.name) - # path or url??? if it's a file based publishing ethos, it should be path non? - # puttting this here since templates are using url... - v["url"] = v["path"] + if args.filebased: + + # work with paths + + outpath = Path(args.output).parent + for v in p["versions"]: + + if v["type"] != "pad": + vpath = Path(v["path"]) + + try: + v["path"] = os.path.join(os.path.relpath(vpath.parent, outpath), vpath.name) + v["url"] = v["path"] + except Exception as e: + pass + + if not p["link"].startswith("http"): + vpath = Path(p["link"]) + try: + p["link"] = os.path.join(os.path.relpath(vpath.parent, outpath), vpath.name) except Exception as e: pass - if not p["link"].startswith("http"): - vpath = Path(p["link"]) - try: - p["link"] = os.path.join(os.path.relpath(vpath.parent, outpath), vpath.name) - except Exception as e: - pass + else: + + # work with URLs + + indexurl = info["indexurl"] + outpath = Path(args.output).parent + + for v in p["versions"]: + + if v["type"] != "pad": + + vpath = Path(v["url"]) + + # strip output dir.... + relpath = Path(*vpath.parts[1:]) + + v["url"] = os.path.join(indexurl, relpath) + diff --git a/pppadump/commands/init.py b/pppadump/commands/init.py index 372cb9c..b843414 100644 --- a/pppadump/commands/init.py +++ b/pppadump/commands/init.py @@ -73,6 +73,7 @@ def main(args): p.add_argument("arg", nargs="*", default=[], help="optional positional args: path etherpadurl") p.add_argument("--path", default=None, help="path to initialize") p.add_argument("--padurl", default=None, help="") + p.add_argument("--indexurl", default=None, help="") p.add_argument("--apikey", default=None, help="") p.add_argument("--verbose", default=False, action="store_true", help="") p.add_argument("--reinit", default=False, action="store_true", help="") @@ -114,6 +115,15 @@ def main(args): break apiurl = input("Please type the URL of the etherpad: ").strip() padinfo["apiurl"] = apiurl + + + indexurl = args.indexurl + while True: + if indexurl: + break + indexurl = input("Please type the URL of the index to be generated (i.e. should differ from padurl): ").strip() + padinfo["indexurl"] = indexurl + apikey = args.apikey while True: if apikey: