Compare commits
5 Commits
7ab7b06bb2
...
68a5b2be65
Author | SHA1 | Date | |
---|---|---|---|
|
68a5b2be65 | ||
|
a372df0951 | ||
|
77499c700d | ||
|
07fdf16686 | ||
5044b2b0e9 |
@ -21,7 +21,8 @@ settings:
|
|||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm ./pages/*.html
|
- rm -f ./pages/*.html
|
||||||
rm ./tags/*/*.html
|
- rm -f ./tags/*/*.html
|
||||||
rm ./webring/*.html
|
- rm -f ./webring/*.html
|
||||||
rmdir ./pages ./tags/* ./tags ./webring
|
- rm -f ./feeds/*.xml
|
||||||
|
- rmdir ./pages ./tags/* ./tags ./webring ./feeds
|
||||||
|
@ -85,3 +85,4 @@ title="Your Microblog Title Here"
|
|||||||
title_tagged = "#{__tagname__} on {__title__}"
|
title_tagged = "#{__tagname__} on {__title__}"
|
||||||
url = "https://yourdomain.tld/microblog/"
|
url = "https://yourdomain.tld/microblog/"
|
||||||
description = "Your description here."
|
description = "Your description here."
|
||||||
|
trailing_punctuation = ".,)!?>];:"
|
||||||
|
@ -549,6 +549,8 @@ if __name__ == "__main__":
|
|||||||
updated = []
|
updated = []
|
||||||
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"]["gallery_path"] = cfg["post"]["gallery"]["path_to_fullsize"]
|
||||||
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"):
|
||||||
|
46
src/rss.py
46
src/rss.py
@ -2,6 +2,8 @@ from microblog import My_Html_Parser
|
|||||||
# from html.parser import HTMLParser
|
# from html.parser import HTMLParser
|
||||||
from html import escape
|
from html import escape
|
||||||
import sys, traceback, dateutil.parser
|
import sys, traceback, dateutil.parser
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import feedgenerator
|
import feedgenerator
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -11,7 +13,7 @@ except ImportError:
|
|||||||
print("\trss disabled - missing dependency", file=sys.stderr)
|
print("\trss disabled - missing dependency", file=sys.stderr)
|
||||||
print("\tYour microblog still may have been generated.", file=sys.stderr)
|
print("\tYour microblog still may have been generated.", file=sys.stderr)
|
||||||
|
|
||||||
def line2words(lines, limit):
|
def line2words(lines, limit, trailing_punctuation):
|
||||||
output = []
|
output = []
|
||||||
char_count = 0
|
char_count = 0
|
||||||
break_outer_loop = False
|
break_outer_loop = False
|
||||||
@ -29,15 +31,22 @@ def line2words(lines, limit):
|
|||||||
# last char of last word
|
# last char of last word
|
||||||
last_char = output[-1].strip()[-1]
|
last_char = output[-1].strip()[-1]
|
||||||
# print(output[-1], file=sys.stderr)
|
# print(output[-1], file=sys.stderr)
|
||||||
punctuation = [".", ")", ",", "!", "?", ">", ']']
|
if last_char not in trailing_punctuation:
|
||||||
if last_char not in punctuation:
|
|
||||||
output.append("...")
|
output.append("...")
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def _is_image_token(token: str, extensions):
|
||||||
|
parts = token.rsplit('.', 1)
|
||||||
|
return len(parts) == 2 and parts[1] in extensions
|
||||||
|
|
||||||
# this is similar to the markup function in microblog
|
# this is similar to the markup function in microblog
|
||||||
def enrich_msg(lines, is_atom=True):
|
def enrich_msg(
|
||||||
if not is_atom:
|
lines,
|
||||||
return lines
|
accepted_images=[],
|
||||||
|
gallery_path="",
|
||||||
|
trailing_punctuation="",
|
||||||
|
desc_len_limit=-1,
|
||||||
|
):
|
||||||
content = []
|
content = []
|
||||||
parser = My_Html_Parser([])
|
parser = My_Html_Parser([])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -47,6 +56,7 @@ def enrich_msg(lines, is_atom=True):
|
|||||||
words = line.split()
|
words = line.split()
|
||||||
for i in range(len(words)):
|
for i in range(len(words)):
|
||||||
word = words[i]
|
word = words[i]
|
||||||
|
core = word.rstrip(trailing_punctuation)
|
||||||
if word.find("src=") == 0 \
|
if word.find("src=") == 0 \
|
||||||
or word.find("href=") == 0:
|
or word.find("href=") == 0:
|
||||||
continue
|
continue
|
||||||
@ -54,6 +64,12 @@ def enrich_msg(lines, is_atom=True):
|
|||||||
w = escape(word)
|
w = escape(word)
|
||||||
new_word = ("<a href=\"%s\">%s</a>") % (w, w)
|
new_word = ("<a href=\"%s\">%s</a>") % (w, w)
|
||||||
words[i] = new_word
|
words[i] = new_word
|
||||||
|
elif _is_image_token(core, accepted_images):
|
||||||
|
suffix = word[len(core):]
|
||||||
|
abs_url = urljoin(gallery_path, core)
|
||||||
|
anchor = f"<a href=\"{escape(abs_url)}\">{escape(abs_url)}</a>"
|
||||||
|
new_word = anchor + suffix
|
||||||
|
words[i] = new_word
|
||||||
words.insert(0,"<p>")
|
words.insert(0,"<p>")
|
||||||
words.append("</p>")
|
words.append("</p>")
|
||||||
content.append(" ".join(words))
|
content.append(" ".join(words))
|
||||||
@ -95,12 +111,18 @@ def write_feed(posts, filename, params, tagname=None):
|
|||||||
# len of post.message is number of lines
|
# len of post.message is number of lines
|
||||||
msg = post.message
|
msg = post.message
|
||||||
ti = " ".join(
|
ti = " ".join(
|
||||||
line2words(msg,TITLE_LEN_LIMIT))
|
line2words(msg, TITLE_LEN_LIMIT, params["trailing_punctuation"]))
|
||||||
if params["use_atom"]:
|
de = " ".join(
|
||||||
de = " ".join(enrich_msg(msg))
|
enrich_msg(
|
||||||
else:
|
msg,
|
||||||
de = " ".join(
|
gallery_path=urljoin(
|
||||||
line2words(msg,DESC_LEN_LIMIT))
|
params["url"], params.get("gallery_path", "") + "/"
|
||||||
|
),
|
||||||
|
accepted_images=params["accepted_images"],
|
||||||
|
trailing_punctuation=params["trailing_punctuation"],
|
||||||
|
desc_len_limit=DESC_LEN_LIMIT,
|
||||||
|
)
|
||||||
|
)
|
||||||
li = base_url + ("#%i" % post.num)
|
li = base_url + ("#%i" % post.num)
|
||||||
p = dateutil.parser.parse(post.timestamp)
|
p = dateutil.parser.parse(post.timestamp)
|
||||||
if params["use_atom"]:
|
if params["use_atom"]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user