椒盐豆豉

Add random post picker to Hugo without json index

September 20, 2023
重启电脑 | English
code | project | tutorial | hugo | blog

I want to add a random article picker to my blog as another way to discover past posts, aside from categories and tags on the right side and making it easier on mobile.

I couldn’t find a simple enough solution that suits my needs after brief Googling. The options I found were either to randomize at build time, which means the article doesn’t change with each click or refresh, or to generate a JSON index, which I had trouble with probably because my lack of understanding of Hugo.

I thought such a simple feature should be achievable with just JS + HTML, so I decided to write my own. Performance shouldn’t be an issue for a blog with a few tens to thousands of articles. Here’s a solution I came up with for reference.

...


给 Hugo 博客添加随机文章入口

September 20, 2023
重启电脑
code | project | tutorial | hugo | blog

我想给自己的博客加一个随机文章入口,作为页面右边的分类和 tag 之外的另一个发掘文章入口,移动端也更容易。在网上一搜,Google 第一页没有看到太显眼的简单适合我博客的答案:要么是最简单的 build time randomize,不能每次点击/刷新都出新文章;要么要生成 json 索引,对 hugo 语言和 config 不是很熟悉的我折腾了一下没搞出来,遂放弃。

想说这么简单个功能不至于不能纯拿 JS + html 写吧,博客少则几十多则几千的随机数性能应该也不成问题,随自己折腾出来个方案供大家参考。

...


又双叒叕一篇小白个人博客选什么工具或平台

June 11, 2023
重启电脑
tutorial | patreon | wordpress | hugo | code | blog

之前忘记在哪看到一篇建站教程 ,给了类似这么一张图,实在找不到原文/图了,大意翻译一下:

其实就是自嘲了一下博客圈都喜欢捣腾建站啦 refactor 啦什么的,建站教程/折腾日志写得越欢的实际后续博客文章数量越少。

(后来象友评论补充了我想找的那张原图在这里

本写了二十年博客的话痨今天就来打破一下 stereotype,建完站之后的因为新鲜劲和 performance improvement 倒是已经井喷了三篇文章了。

趁着前两天刚捣腾过一次建站还记忆犹新,也来老生常谈又双叒叕写一篇面向小白的“个人博客选什么工具或平台“的建站文。

本文其实是我 6 月 Patreon 博客选题投票 trending 胜出选项,没想到吧因为新博客表达欲过于旺盛已经学会抢答了(highly unlikely 但是万一最后另一个选项胜出大不了两篇都写),以前不拖到当月结束就不错了。7 月博客投票提前释出敬请投票!

  • 我就是不想 grow —— 一份码农生涯躺平挣扎记录
  • 电驭游宅好伴侣,Aer 背包全家桶体验
  • 纯远程工作讨厌做饭厨渣如何糊弄吃饭问题

TLDR #

本文受众是纯小白,有一定技术基础的相信可以根据自己需求选择。简化起见在此只讨论几种最常见的建博客方式:Github Pages,Wordpress 自建站,免费第三方托管(Medium, wordpress.com,telegra.ph 等),Notion(其实也是第三方托管的一种),付费第三方托管(wordpress.com, squarespace 等)。

私以为纯博客的话只有如下两种选择 make sense:

  • 刚开始/还没开始写博客,想培养写作习惯,不会/不想花时间在学习 git 和一些 command line 基本操作:Notion
  • 有写作习惯,或熟悉 git 和 command line 基本操作的人:无脑选静态生成(其中 github pages 是最流行且免费的托管平台)
...