Highlight old posts in Hugo

I added a small notice that appears on posts older than a year. It was important to me that this notice not show up on photo-only posts — after all, photos rarely lose their relevance. First I wrote a working version myself, then had a language model further optimize the code. Now I’m running the following variant: {{- /* Tags prüfen */ -}} {{- $tags := default (slice) .Params.tags -}} {{- $tagsLower := apply $tags "lower" "." -}} {{- $hasPhoto := in $tagsLower "photo" -}} {{- /* Relevantes Datum bestimmen und Stichtag berechnen */ -}} {{- $pageDate := time.AsTime (or .Lastmod .PublishDate .Date) -}} {{- $oneYearAgo := (now).AddDate -1 0 0 -}} {{- /*Hinweis nur auf echten Seiten, mit gültigem Datum, älter als 1 Jahr und nicht beim Tag "photo" */ -}} {{- if and .IsPage (not $hasPhoto) (gt ($pageDate.Unix) 0) (lt $pageDate $oneYearAgo) -}} <div class="alert alert-warning"> Hinweis: Dieser Artikel ist über ein Jahr alt. Die Informationen könnten veraltet sein. </div> {{- end -}} The text was automatically translated from German into English. The German quotations were also translated in sense. ...

October 21, 2025 · 1 min · 182 words

Apple Store Notifier

Apple announced new products a few days ago. As always, stock in the stores is limited. If you’re smart, you check online whether the product you want is available at your local Apple Store. If you’re lazy, use the following Python script to automate that. Note: Pushover is required. #!/usr/bin/env python3 import requests import os import time def fetch_availability(product_number, store_id): payload = { "store": store_id, "little": False, "mt": "regular", "parts.0": product_number, "fts": True, } url = "https://www.apple.com/de/shop/fulfillment-messages" r = requests.get(url, params=payload) data = r.json() stores = data["body"]["content"]["pickupMessage"]["stores"] store = next(store for store in stores if store["storeNumber"] == store_id) avail = store["partsAvailability"][product_number] return { "store_name": store.get("storeName"), "available": avail.get("pickupDisplay") != "ineligible", "store_pickup_quote": avail.get("storePickupQuote"), "pickup_search_quote": avail.get("pickupSearchQuote"), "pickup_display": avail.get("pickupDisplay"), } def assemble_availability_text(product_number, store_ids): avail_text = "" for store_id in store_ids: avail = fetch_availability(product_number, store_id) avail_text += f'{avail["store_name"]}: {avail["store_pickup_quote"]}\n' return avail_text def create_file_if_not_exists(filepath): if not os.path.exists(filepath): with open(filepath, "w") as f: f.write("") def do_it(part_no, store_ids, **kwargs): availability_text = assemble_availability_text(part_no, store_ids) create_file_if_not_exists("/tmp/cache.txt") with open("/tmp/cache.txt", "r+", encoding="utf-8") as f: if f.read() == availability_text: print("No Changes", flush=True) else: print("Changes detected", availability_text, flush=True) if kwargs["pushover_enabled"] == "1": requests.post( "https://api.pushover.net/1/messages.json", data={ "token": kwargs["pushover_token"], "user": kwargs["pushover_user"], "message": availability_text, "title": "CHANGES DETECTED", }, headers={"Content-Type": "application/x-www-form-urlencoded"}, ) f.truncate(0) f.seek(0) f.write(availability_text) if __name__ == "__main__": while True: do_it( os.environ["MONITORED_PART_NO"], os.environ["MONITORED_STORES"].split(","), pushover_enabled=os.environ["PUSHOVER_ENABLED"], pushover_token=os.environ["PUSHOVER_TOKEN"], pushover_user=os.environ["PUSHOVER_USER"], ) time.sleep(int(os.environ["POLLING_DELAY_SECONDS"])) The script is in the repository dprandzioch/apple-store-notifier on GitHub. ...

March 19, 2022 · 2 min · 243 words

Ghost Bookmarklet

After switching from Grav to Ghost I have to tweak a few articles. To be able to quickly jump from the frontend to the backend, I wrote a super-simple bookmarklet. Just save the following code as a bookmark. javascript:window.location.href=window.location.href+'/edit'; After you click the bookmark, the browser will navigate to http://DEINEBLOG.URL/edit and, if you’re logged in, you can edit the article directly. The text was automatically translated from German into English. The German quotations were also translated in sense. ...

December 23, 2021 · 1 min · 78 words

CSS Brighter

Like Matsuko, I also sometimes find videos too dark when watching Netflix or YouTube in the evening. Usually I just turn up my screen brightness, but I’d prefer to brighten only the video itself. The following code snippet lets you do exactly that. /* Brighter Netflix and YouTube videos */ video[src^="blob:https://www.netflix.com/"], video[src^="blob:https://www.youtube.com/"] { filter: brightness(1.4); } The text was automatically translated from German into English. The German quotations were also translated in sense. ...

August 6, 2020 · 1 min · 73 words

Hello Darkness

If you’re using a device that supports dark mode, this little blog will now adapt its appearance to match your system settings. With the help of Jeremy Keith’s description, I was able to implement this very quickly. It’s actually incredibly simple. Just drop the following code into your style.css and define whichever CSS properties you want to apply in dark mode. @media (prefers-color-scheme: dark) { /* Dark mode CSS properties go here */ } You might also consider adding a switch to the blog so users can override the default setting. Thomas Steiner explains this quite well here. ...

March 31, 2020 · 1 min · 115 words