Added option whether to display images with <img> or <a>.
This commit is contained in:
parent
6de5347d71
commit
2771ec3ef8
@ -80,6 +80,7 @@ local_path_to_avatars="./avatars" # destination folder on pc
|
|||||||
[rss]
|
[rss]
|
||||||
enabled = true
|
enabled = true
|
||||||
use_atom = false
|
use_atom = false
|
||||||
|
images_as_links = true # replace images with text-only links
|
||||||
limit = 10 # include the most recent n posts
|
limit = 10 # include the most recent n posts
|
||||||
title="Your Microblog Title Here"
|
title="Your Microblog Title Here"
|
||||||
title_tagged = "#{__tagname__} on {__title__}"
|
title_tagged = "#{__tagname__} on {__title__}"
|
||||||
|
@ -550,7 +550,7 @@ if __name__ == "__main__":
|
|||||||
updated += writepage(tpl, tl, tc, cfg["page"],
|
updated += writepage(tpl, tl, tc, cfg["page"],
|
||||||
paginate=True if new_posts is None else False)
|
paginate=True if new_posts is None else False)
|
||||||
cfg["rss"]["accepted_images"] = cfg["post"]["accepted_images"]
|
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"]:
|
if cfg["rss"]["enabled"]:
|
||||||
# ensure output directory for feeds exists
|
# ensure output directory for feeds exists
|
||||||
if not os.path.exists("feeds"):
|
if not os.path.exists("feeds"):
|
||||||
|
31
src/rss.py
31
src/rss.py
@ -43,9 +43,10 @@ def _is_image_token(token: str, extensions):
|
|||||||
def enrich_msg(
|
def enrich_msg(
|
||||||
lines,
|
lines,
|
||||||
accepted_images=[],
|
accepted_images=[],
|
||||||
gallery_path="",
|
gallery_path=dict(),
|
||||||
trailing_punctuation="",
|
trailing_punctuation="",
|
||||||
desc_len_limit=-1,
|
desc_len_limit=-1,
|
||||||
|
is_text_only = True
|
||||||
):
|
):
|
||||||
content = []
|
content = []
|
||||||
parser = My_Html_Parser([])
|
parser = My_Html_Parser([])
|
||||||
@ -66,8 +67,16 @@ def enrich_msg(
|
|||||||
words[i] = new_word
|
words[i] = new_word
|
||||||
elif _is_image_token(core, accepted_images):
|
elif _is_image_token(core, accepted_images):
|
||||||
suffix = word[len(core):]
|
suffix = word[len(core):]
|
||||||
abs_url = urljoin(gallery_path, core)
|
abs_url = urljoin(gallery_path["full"], core)
|
||||||
anchor = f"<a href=\"{escape(abs_url)}\">{escape(abs_url)}</a>"
|
foo_url = urljoin(gallery_path["thumb"], core)
|
||||||
|
|
||||||
|
href = escape(abs_url)
|
||||||
|
if is_text_only:
|
||||||
|
atext = href
|
||||||
|
else:
|
||||||
|
atext = f"<img src=\"{foo_url}\">"
|
||||||
|
anchor = f"<a href=\"{href}\">{atext}</a>"
|
||||||
|
|
||||||
new_word = anchor + suffix
|
new_word = anchor + suffix
|
||||||
words[i] = new_word
|
words[i] = new_word
|
||||||
words.insert(0,"<p>")
|
words.insert(0,"<p>")
|
||||||
@ -107,6 +116,17 @@ def write_feed(posts, filename, params, tagname=None):
|
|||||||
base_url = l
|
base_url = l
|
||||||
TITLE_LEN_LIMIT = 60
|
TITLE_LEN_LIMIT = 60
|
||||||
DESC_LEN_LIMIT = -1 if params["use_atom"] else 300
|
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:
|
for post in posts:
|
||||||
# len of post.message is number of lines
|
# len of post.message is number of lines
|
||||||
msg = post.message
|
msg = post.message
|
||||||
@ -115,12 +135,11 @@ def write_feed(posts, filename, params, tagname=None):
|
|||||||
de = " ".join(
|
de = " ".join(
|
||||||
enrich_msg(
|
enrich_msg(
|
||||||
msg,
|
msg,
|
||||||
gallery_path=urljoin(
|
gallery_path=gpaths,
|
||||||
params["url"], params.get("gallery_path", "") + "/"
|
|
||||||
),
|
|
||||||
accepted_images=params["accepted_images"],
|
accepted_images=params["accepted_images"],
|
||||||
trailing_punctuation=params["trailing_punctuation"],
|
trailing_punctuation=params["trailing_punctuation"],
|
||||||
desc_len_limit=DESC_LEN_LIMIT,
|
desc_len_limit=DESC_LEN_LIMIT,
|
||||||
|
is_text_only = params["images_as_links"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
li = base_url + ("#%i" % post.num)
|
li = base_url + ("#%i" % post.num)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user