update @ Thu Dec 26 05:02:33 EET 2024

Signed-off-by: Ari Archer <ari@ari.lt>
This commit is contained in:
Arija A. 2024-12-26 05:02:33 +02:00
parent a88de4e345
commit 7b99b05b35
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: A50D5B4B599AF8A2
3 changed files with 100 additions and 25 deletions

View file

@ -10,7 +10,8 @@
"credit": "Ari Archer",
"ext": "jpeg",
"mime": "image/jpeg",
"uploaded": 1734269521.436514
"uploaded": 1734269521.436514,
"size": 47100
},
"0867cea01b7f0dda58de112b78d19a2ef5b0c06102a8526b2157d14ec9e3db24": {
"type": "image",
@ -23,7 +24,8 @@
"credit": "Ari Archer",
"ext": "png",
"mime": "image/png",
"uploaded": 1734473202.686761
"uploaded": 1734473202.686761,
"size": 35687
},
"2f279788d90f6ddae8d49c49674ac899f078bb94243b1b0aabf711e17fc3f482": {
"type": "image",
@ -36,7 +38,8 @@
"credit": "Ari Archer",
"ext": "png",
"mime": "image/png",
"uploaded": 1734473932.694922
"uploaded": 1734473932.694922,
"size": 225263
},
"43fef629105fdc1cd04e6f400abed839d988c23f67223a8d3fe1674fe02e42e1": {
"type": "image",
@ -49,7 +52,8 @@
"credit": "Ari Archer",
"ext": "png",
"mime": "image/png",
"uploaded": 1734474105.967359
"uploaded": 1734474105.967359,
"size": 384198
},
"a22e9a8beb3154523ba368302bedede134df659950925a9968b49cc265cefb7a": {
"type": "image",
@ -62,7 +66,8 @@
"credit": "Ari Archer",
"ext": "png",
"mime": "image/png",
"uploaded": 1734474254.159669
"uploaded": 1734474254.159669,
"size": 219103
},
"783a5e8cb6fcc3626a0ebfb08d2c35defa5e4fbfa48f17ebcb3596bffad01cd3": {
"type": "image",
@ -75,7 +80,8 @@
"credit": "Ari Archer (image), Terry A. Davis (quote)",
"ext": "png",
"mime": "image/png",
"uploaded": 1734474455.015919
"uploaded": 1734474455.015919,
"size": 27982
},
"7039b8fd6868afe631aa97acb95222f21a64e1ddee38779142d9f098141bb4c4": {
"type": "image",
@ -88,7 +94,8 @@
"credit": "Author unknown",
"ext": "png",
"mime": "image/png",
"uploaded": 1734474610.104147
"uploaded": 1734474610.104147,
"size": 277327
},
"14a5361b38cd74a9b6d8cd5e2fa63d9ea4a6a813d7780ffb6454a4871ecec996": {
"type": "image",
@ -101,7 +108,8 @@
"credit": "Ari Archer",
"ext": "png",
"mime": "image/png",
"uploaded": 1734474772.543329
"uploaded": 1734474772.543329,
"size": 156664
},
"0916be4b05235a7551cffd393b9f92925aaa6695e21c1db6b4ffa0f9a59e76d0": {
"type": "image",
@ -114,7 +122,8 @@
"credit": "Ari Archer",
"ext": "png",
"mime": "image/png",
"uploaded": 1734474892.128002
"uploaded": 1734474892.128002,
"size": 30893
},
"86b362afea5c76f61ed65da4762b91fda1a99d302f814b48fbf79a8b1f6bcc94": {
"type": "image",
@ -127,7 +136,8 @@
"credit": "Author unknown",
"ext": "png",
"mime": "image/png",
"uploaded": 1734475065.128174
"uploaded": 1734475065.128174,
"size": 261948
},
"b9abe926ef51ca448d61381d2d8ffd1822363cbe289ac458c4b1d2fdae01b469": {
"type": "image",
@ -140,7 +150,8 @@
"credit": "LDA",
"ext": "png",
"mime": "image/png",
"uploaded": 1734527486.868667
"uploaded": 1734527486.868667,
"size": 142450
},
"d4d01a7052822c08567dc62578a5574b26e15792c713da83a1a96830b378d568": {
"type": "image",
@ -153,7 +164,8 @@
"credit": "Ari Archer",
"ext": "jpeg",
"mime": "image/jpeg",
"uploaded": 1734527643.644962
"uploaded": 1734527643.644962,
"size": 77209
},
"f304b3ee8dfdc51d91fe2819b64a45a8d49ad918329b8fb0aabac1166385d465": {
"type": "image",
@ -166,7 +178,8 @@
"credit": "Ari Archer",
"ext": "jpeg",
"mime": "image/jpeg",
"uploaded": 1734527808.637102
"uploaded": 1734527808.637102,
"size": 76582
},
"467da37b61b8edee2e7ba9f5cd871d5e766d589e3d4a4ba0d077e3d656ccbab1": {
"type": "image",
@ -179,7 +192,8 @@
"credit": "Ari Archer, truity.com",
"ext": "png",
"mime": "image/png",
"uploaded": 1734528001.909138
"uploaded": 1734528001.909138,
"size": 27200
},
"9b9a2aff1530592cf4eae3e4bffa4e09a2f424343f8f9b85922d81488c97e110": {
"type": "image",
@ -192,7 +206,8 @@
"credit": "Ari Archer, Netlify",
"ext": "jpeg",
"mime": "image/jpeg",
"uploaded": 1734528120.500828
"uploaded": 1734528120.500828,
"size": 26250
},
"974aaeaf72e8958f6d612e3d39d59dc9389b453f01e7d31a5e528de3e490cc48": {
"type": "image",
@ -205,6 +220,7 @@
"credit": "Author unknown",
"ext": "jpeg",
"mime": "image/jpeg",
"uploaded": 1734528317.965137
"uploaded": 1734528317.965137,
"size": 297557
}
}

View file

@ -32,7 +32,7 @@ from mistune.renderers.html import HTMLRenderer
from mistune.util import safe_entity
from pygments import highlight
from pygments.formatters import HtmlFormatter, html
from pygments.lexers import get_lexer_by_name, guess_lexer, TextLexer
from pygments.lexers import TextLexer, get_lexer_by_name, guess_lexer
from readtime import of_markdown as read_time_of_markdown # type: ignore
from readtime.result import Result as MarkdownResult # type: ignore
@ -729,9 +729,7 @@ def s_to_str(seconds: float) -> str:
else:
readable_text = time_periods[0]
return (
f"{readable_text} ({round(seconds, 2)} second{'' if seconds == 1 else 's'})"
)
return f"{readable_text} ({round(seconds, 2)} second{'' if seconds == 1 else 's'})"
# markdown
@ -1582,11 +1580,15 @@ def rss(config: dict[str, typing.Any]) -> int:
etree.SubElement(item, "link").text = (
link := f"{config['blog']}/{config['posts-dir']}/{slug}"
)
etree.SubElement(item, "description").text = post["description"] + (
etree.SubElement(item, "description").text = (
post["description"]
+ (
f" [edited at {datetime.datetime.utcfromtimestamp(created).strftime(ftime)}]"
if created
else ""
) + f" - read about it at {link} :)"
)
+ f" - read about it at {link} :)"
)
etree.SubElement(item, "pubDate").text = datetime.datetime.utcfromtimestamp(
post["created"],
).strftime(ftime)
@ -1595,6 +1597,25 @@ def rss(config: dict[str, typing.Any]) -> int:
f"{config['author']} <{config['email']}>"
)
if "preview" in post and post["preview"] in MEDIA_INDEX:
url: str = (
f"{config['blog']}/media/{post['preview']}.{MEDIA_INDEX[post['preview']]['ext']}"
)
m = MEDIA_INDEX[post["preview"]]
if m["type"] != "image":
continue
thm = etree.SubElement(item, "media:thumbnail")
thm.set("url", url)
thm.set("width", str(m["width"]))
thm.set("height", str(m["height"]))
enc = etree.SubElement(item, "enclosure")
enc.set("url", url)
enc.set("type", m["mime"])
enc.set("length", str(m["size"]))
etree.ElementTree(root).write(
config["rss-file"], encoding="UTF-8", xml_declaration=True
)
@ -1931,6 +1952,7 @@ def media(config: dict[str, typing.Any]) -> int:
"ext": ext,
"mime": mime,
"uploaded": datetime.datetime.utcnow().timestamp(),
"size": os.path.getsize(path),
}
)

37
scripts/v2-media.py Normal file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""fixes filesize"""
import json
import os
from warnings import filterwarnings as filter_warnings
def t(title: str):
if title:
title = title[0].upper() + title[1:]
title = title.replace("Doml #", "DOML #")
return title
def main() -> int:
"""entry / main function"""
with open("media/media.json", "r") as fp:
media = json.load(fp)
for h in media:
media[h]["size"] = os.path.getsize(f"media/{h}.{media[h]['ext']}")
with open("media/media.json", "w") as fp:
json.dump(media, fp, indent=2)
return 0
if __name__ == "__main__":
assert main.__annotations__.get("return") is int, "main() should return an integer"
filter_warnings("error", category=Warning)
raise SystemExit(main())