mirror of
https://git.ari.lt/ari.lt/blog.ari.lt.git
synced 2025-02-04 09:39:25 +01:00
update @ Sun Dec 15 13:59:44 EET 2024
Signed-off-by: Ari Archer <ari@ari.lt>
This commit is contained in:
parent
bdd01ea27e
commit
84c9c43cab
4 changed files with 85 additions and 21 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 123 KiB |
|
@ -1 +1,15 @@
|
|||
{}
|
||||
{
|
||||
"b97a4bd25804d1315833a59d353c7af1716c1c55a811f05dcd35460d73f79b84": {
|
||||
"type": "image",
|
||||
"width": 720,
|
||||
"height": 1280,
|
||||
"alt": "A black cat sitting in a box peacefully.",
|
||||
"purpose": "To have a cute cat who looks over blog.ari.lt!",
|
||||
"title": "Tina in a box (2019-2020, I think)",
|
||||
"license": "CC-BY-SA",
|
||||
"credit": "Ari Archer",
|
||||
"ext": "jpeg",
|
||||
"mime": "image/jpeg",
|
||||
"uploaded": 1734256615.75018
|
||||
}
|
||||
}
|
|
@ -230,7 +230,7 @@ POST_TEMPLATE: typing.Final[str] = (
|
|||
<title>{blog_title} -> {post_title}</title>
|
||||
<meta name="description" content="{post_title} by {author} at {post_creation_time} GMT -- {post_description}" />
|
||||
<meta property="article:read_time" content="{post_read_time}" />
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="og:type" content="article" /> {image_meta}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -551,7 +551,21 @@ def select_posts(posts: dict[str, dict[str, typing.Any]]) -> tuple[str, ...]:
|
|||
)
|
||||
|
||||
|
||||
def select_medias() -> tuple[str, ...]:
|
||||
def select_medias(type: typing.Optional[str] = None) -> tuple[str, ...]:
|
||||
if type:
|
||||
return tuple(
|
||||
map(
|
||||
lambda opt: opt.split("|", maxsplit=1)[0].strip(),
|
||||
select_multi(
|
||||
tuple(
|
||||
f"{mdx} | {mdy['type']}, {mdy['alt']} for {mdy['purpose']} | {mdy['title']}, {mdy['credit']}"
|
||||
for mdx, mdy in MEDIA_INDEX.items()
|
||||
if mdy["type"] == type
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
return tuple(
|
||||
map(
|
||||
lambda opt: opt.split("|", maxsplit=1)[0].strip(),
|
||||
|
@ -881,6 +895,21 @@ def keywords(post: dict[str, typing.Any]) -> int:
|
|||
)
|
||||
return OK
|
||||
|
||||
@ecmds.new
|
||||
def preview(post: dict[str, typing.Any]) -> int:
|
||||
"""edit preview"""
|
||||
|
||||
if yn("image preview"):
|
||||
pv: tuple[str, ...] = select_medias("image")
|
||||
|
||||
if pv:
|
||||
post["preview"] = pv[0]
|
||||
else:
|
||||
if "preview" in post:
|
||||
del post["preview"]
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
# normal commands
|
||||
|
||||
|
@ -968,16 +997,22 @@ def new(config: dict[str, typing.Any]) -> int:
|
|||
|
||||
description: str = iinput("post description")
|
||||
|
||||
lnew(f"saving blog post {slug!r}")
|
||||
|
||||
posts[slug] = {
|
||||
"title": title,
|
||||
"description": description.strip(),
|
||||
"content": content,
|
||||
"keywords": keywords,
|
||||
"uploaded": datetime.datetime.utcnow().timestamp(),
|
||||
"created": datetime.datetime.utcnow().timestamp(),
|
||||
}
|
||||
|
||||
if yn("image preview"):
|
||||
pv: tuple[str, ...] = select_medias("image")
|
||||
|
||||
if pv:
|
||||
posts[slug]["preview"] = pv[0]
|
||||
|
||||
lnew(f"saved blog post {slug!r}")
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
|
@ -1128,6 +1163,12 @@ def build(config: dict[str, typing.Any]) -> int:
|
|||
pd[dt.day] += 1
|
||||
ph[dt.hour] += 1
|
||||
|
||||
image_meta: str = ""
|
||||
if "preview" in post and post["preview"] in MEDIA_INDEX:
|
||||
src: str = f"/media/{post['preview']}.{MEDIA_INDEX[post['preview']]['ext']}"
|
||||
image_meta = f"""<meta property="og:image" content="{src}" />
|
||||
<meta name="twitter:image" content="{src}" />"""
|
||||
|
||||
with open(f"{post_dir}/index.html", "w") as html:
|
||||
html.write(
|
||||
web_mini.html.minify_html(
|
||||
|
@ -1170,6 +1211,7 @@ def build(config: dict[str, typing.Any]) -> int:
|
|||
license=config["license"],
|
||||
email=config["email"],
|
||||
legal=config["legal"],
|
||||
image_meta=image_meta,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
@ -1740,7 +1782,7 @@ def media(config: dict[str, typing.Any]) -> int:
|
|||
"credit": credit,
|
||||
"ext": ext,
|
||||
"mime": mime,
|
||||
"created": datetime.datetime.utcnow().timestamp(),
|
||||
"uploaded": datetime.datetime.utcnow().timestamp(),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -1789,6 +1831,11 @@ def purgemedia(config: dict[str, typing.Any]) -> int:
|
|||
used: bool = False
|
||||
|
||||
for post in posts:
|
||||
# Seperated for readability reasons
|
||||
if "preview" in post and post["preview"] == mdx:
|
||||
used = True
|
||||
break
|
||||
|
||||
if f"<@{mdx}>" in post["content"]:
|
||||
used = True
|
||||
break
|
||||
|
@ -1802,7 +1849,7 @@ def purgemedia(config: dict[str, typing.Any]) -> int:
|
|||
del MEDIA_INDEX[mdy]
|
||||
|
||||
for file in os.listdir("media"):
|
||||
if file == "media.json": # Ignore index file
|
||||
if file == "media.json" or file == "media_json_hash.txt": # Ignore index file
|
||||
continue
|
||||
|
||||
pid: str = os.path.splitext(os.path.basename(file))[0]
|
||||
|
|
Loading…
Add table
Reference in a new issue