From 2771ec3ef852a71ddb4e2418e62eb1931f67c3e3 Mon Sep 17 00:00:00 2001 From: likhy Date: Sun, 7 Sep 2025 18:47:44 -0700 Subject: [PATCH] Added option whether to display images with or . --- example/settings.toml | 1 + src/microblog.py | 2 +- src/rss.py | 31 +++++++++++++++++++++++++------ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/example/settings.toml b/example/settings.toml index 79c5f46..9795164 100644 --- a/example/settings.toml +++ b/example/settings.toml @@ -80,6 +80,7 @@ local_path_to_avatars="./avatars" # destination folder on pc [rss] enabled = true use_atom = false +images_as_links = true # replace images with text-only links limit = 10 # include the most recent n posts title="Your Microblog Title Here" title_tagged = "#{__tagname__} on {__title__}" diff --git a/src/microblog.py b/src/microblog.py index 1bb197b..3cf724f 100644 --- a/src/microblog.py +++ b/src/microblog.py @@ -550,7 +550,7 @@ if __name__ == "__main__": updated += writepage(tpl, tl, tc, cfg["page"], paginate=True if new_posts is None else False) cfg["rss"]["accepted_images"] = cfg["post"]["accepted_images"] - cfg["rss"]["gallery_path"] = cfg["post"]["gallery"]["path_to_fullsize"] + cfg["rss"]["gallery"] = cfg["post"]["gallery"] if cfg["rss"]["enabled"]: # ensure output directory for feeds exists if not os.path.exists("feeds"): diff --git a/src/rss.py b/src/rss.py index 886d027..228776f 100644 --- a/src/rss.py +++ b/src/rss.py @@ -43,9 +43,10 @@ def _is_image_token(token: str, extensions): def enrich_msg( lines, accepted_images=[], - gallery_path="", + gallery_path=dict(), trailing_punctuation="", desc_len_limit=-1, + is_text_only = True ): content = [] parser = My_Html_Parser([]) @@ -66,8 +67,16 @@ def enrich_msg( words[i] = new_word elif _is_image_token(core, accepted_images): suffix = word[len(core):] - abs_url = urljoin(gallery_path, core) - anchor = f"{escape(abs_url)}" + abs_url = urljoin(gallery_path["full"], core) + foo_url = urljoin(gallery_path["thumb"], core) + + href = escape(abs_url) + if is_text_only: + atext = href + else: + atext = f"" + anchor = f"{atext}" + new_word = anchor + suffix words[i] = new_word words.insert(0,"

") @@ -107,6 +116,17 @@ def write_feed(posts, filename, params, tagname=None): base_url = l TITLE_LEN_LIMIT = 60 DESC_LEN_LIMIT = -1 if params["use_atom"] else 300 + + gpaths = dict() + img_path_full = urljoin( + params["url"], params["gallery"]["path_to_fullsize"] + "/" + ) + gpaths["full"] = img_path_full + img_path_thumb = urljoin( + params["url"], params["gallery"]["path_to_thumb"] + "/" + ) + gpaths["thumb"] = img_path_thumb + for post in posts: # len of post.message is number of lines msg = post.message @@ -115,12 +135,11 @@ def write_feed(posts, filename, params, tagname=None): de = " ".join( enrich_msg( msg, - gallery_path=urljoin( - params["url"], params.get("gallery_path", "") + "/" - ), + gallery_path=gpaths, accepted_images=params["accepted_images"], trailing_punctuation=params["trailing_punctuation"], desc_len_limit=DESC_LEN_LIMIT, + is_text_only = params["images_as_links"] ) ) li = base_url + ("#%i" % post.num)