惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
IT之家
IT之家
Vercel News
Vercel News
C
Check Point Blog
Google DeepMind News
Google DeepMind News
月光博客
月光博客
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog

kmcd.dev

Joining Buf Let The Gravity of Ashburn, Virginia The CPU Cost of Protobuf Varints in Go It Beating Go gRPC-Web Should Have Fixed gRPC Making Dynamic Protobuf Fast in Go Proxy, Record, and Mock gRPC APIs with FauxRPC Exploring Protocol Buffers Interactively Introducing ProtoDocs Ghost in the Shell: The Manga Behind the Anime The Hidden Cost of google.protobuf.Value Why Networking Built Its Own Data Modeling Language Zero-Friction Demos with WASM Let's Learn About BGP ConnectRPC: Where is it now? Building APIs with Contracts The Case for Greppable Code Unknown Fields in Protobuf IRC Log: Reactionary Faking protobuf data in Go Y'all are Sleeping on Mise-en-Place IRC Log: Standup 2 HTTP/2 From Scratch: Part 4 IRC Log: rm -rf /var/opt/gitlab/postgresql/data HTTP/2 From Scratch: Part 3 Building a Live BGP Map HTTP/2 From Scratch: Part 2 IRC Log: The Cloud Scale Incident
Daily Prompts
2024-06-04 · via kmcd.dev

You may have noticed from my mastodon feed or from a link on the website’s navigation that I have added daily prompts. Each day is a new question to answer. You can respond to the post on Mastodon and it will appear (after some minutes) on this website. I’ve been doing it for the entire month of May and I intend to keep doing it to spur my thoughts and maybe others. I feel like having a question to answer each day helps give others context on who I am, what I’m doing and how I see the world. I have also found that it acts as a good way to reflect on things. I’ve wanted some answers to be different… so I now have some motivation to make them different.

So go and check out the prompts page.

The rest of this article talks about all of the pieces that went into making this happen behind the scenes, besides actually writing the prompts.

I wanted to show a banner image for the prompts… but using the same one every day seemed boring… So now I have a set of 6 banner images that I rotate through. Here’s how I did that with Hugo:

layouts/partials/prompts/load-cover.html

{{- $images := (resources.Match "images/prompt_covers/*") -}}
{{- return (index $images (mod .Date.Day (len $images))) -}}

This piece of code picks a new cover based on the day of the month, so the first of every month will have the same cover, for example. As I add more covers, the covers might shift over some number of days but I hope to eventually make 31 covers so each day of the month is unique. Notice that I used the return statement. This is a special Hugo-specific statement that allows you to return values from partials.

Here’s an example how how I use this partial in another template:

layouts/prompts/single.html

{{- $cover := (partial "prompts/load-cover.html" .).Fill "1520x400 Center webp q100" -}}
<figure>
    <img src="{{ $cover.RelPermalink }}" alt="{{ $cover.Title }}" />
</figure>

Mastodon “Comments”

I’ve changed a lot about how this website is deployed lately and hopefully, no one noticed… The biggest change was switching from GitHub Pages to Cloudflare Pages. At first, this was just a temporary change, because Cloudflare was going to make me wait an entire week before allowing me to use kmcd.dev with the pages website, so I adjusted the Github Action to publish to Cloudflare Pages instead and everything went pretty great with that. That got me thinking… I was scheduling GitHub Actions to post daily updates and I also had a separate posting schedule for Tuesday to publish a new post. That seemed both wasteful and limiting at the same time. So I came up with a plan.

Instead of using Github Actions or Cloudflare Workers to deploy my static website, I’m just going to do it myself, from my Synology NAS. This allowed me to have a much more frequent update schedule for my website if there were changes. You may ask: what does it mean to “have changes” for a static website? Changes can be one of the following:

  • I committed some changes that affected the website output
  • A scheduled post becomes live
  • A new mastodon post happened on my feed or there are other changes with the post (likes, favorites, boosts, edits etc.)
graph TD
    deployment[Deployment Script]
    cloudflarepages[fa:fa-cloud Cloudflare Pages]
    hugo[Hugo]
    deployment -- Git --> commits[Git Commits]
    deployment -- Git --> schedule[Scheduled Content]
    deployment -- Mastodon API --> mastodon[Mastodon Updates]
    commits --> hugo
    schedule --> hugo
    mastodon --> hugo
    hugo -- Wrangler --> cloudflarepages
  

I have a simple script that checks for new changes in my Github repo periodically and does a rebuild to see if there are any scheduled changes. However, you may be wondering how I add mastodon posts to my “static” website. If you experiment enough, you may see that replies get added to my website within 10 minutes (if posted during the day in the European CEST timezone, otherwise it waits until the morning). I made this happen by writing some code with Go and a library called go-mastodon that scans through my previous mastodon posts and puts the updated statuses into a Github repo which is updated for each build of my website. If I want to block content from appearing on my website, I can block the user or mute the reply.

The system works out pretty well. I can improve this, however. I could use a webhook to trigger builds more quickly when there are changes to my Github repo or if there are new posts on mastodon. As it stands, I have to wait up to 10 minutes to see the changes reflected… which isn’t bad, it could just be better. This doesn’t help with scheduled posts, but it would reduce the frequency that I have to check for updates on a timer.

I intend to polish the script that I use to pull down Mastodon updates and publish it as a tool that others can use. I may try to also add support for Blue Sky as well but I make no promises!

Enjoy

I do hope that others find the prompts useful. If you have a suggestion for a prompt or any questions about my setup, please let me know in the comments for this post!