Hugo的自定义主题实现和使用介绍,主要包括自定义模板,HintBox, Tab, Anchor Navigation, Code Copy, 等功能。以及如何修改默认表格样式等。
Hugo常用功能
Archetypes
原型 (Archetype)本质上是一个预定义的 Markdown 文件模板。它包含了新内容文件创建时应有的默认前置元数据
字段和值,以及可选的初始 Markdown 内容
- 原型文件存放在 Hugo 项目(或主题)根目录下的
archetypes/
文件夹中 - 可以创建多个原型,可以通过
--kind
(或-k
) 标志明确指定要使用的原型名称(不含.md
后缀)
hugo new posts/demo.md --kind blog
# Hugo 会查找 archetypes/blog.md
除了上述的明确指定原型名称外,Hugo 在执行 hugo new 命令时,会按照以下顺序(大致)来查找和选择原型文件:
-
根据内容所在的区段 (Section): Hugo 会首先在该区段对应的原型目录中查找。 例如:
content/posts/some-subdir/new.md
Hugo 是一个基于 Go 语言的现代的静态站点生成器。Hugo 提供了 强大的模板引擎 和 灵活的主题系统,并支持 Shortcodes 和 Hooks 扩展功能。
Hugo Introduction
Hugo
v0.146.0
模板系统变更
layouts/_default/
目录已移除,所有文件移至layouts/
根目录layouts/partials/
→layouts/_partials/
layouts/shortcodes/
→layouts/_shortcodes/
安装和初始化
下面将介绍 Windows 下的安装方式,其他平台参照:MacOS, Linux
方式一:在 Git Bash
或 PowerShell
中使用 winget
命令安装:
winget install Hugo.Hugo.Extended
卸载命令:winget uninstall --name "Hugo (Extended)"
PostgreSQL 是一个开源的对象关系型数据库管理系统(ORDBMS)。它最初于1986年在加州大学伯克利分校作为 POSTGRES 项目启动,并于1996年更名为 PostgreSQL,以反映其对 SQL 标准的支持。
- 核心特性:完全符合SQL标准,插件丰富。且有 Neon 和 supadata 两家免费的数据库云服务
- 图形化管理工具 - pgAdmin:官方的 PostgreSQL 图形化管理工具,功能全面,支持复杂查询、监控、调试、ERD 工具等。
- 资源和文档:PostgreSQL Documentation, PostgreSQL Exercises, PostgreSQL Tutorial (by Neon)
PostgreSQL基础
psql命令行工具
psql
是 PostgreSQL 的官方命令行交互式客户端工具。 提供了许多元命令和各种类似 shell 的功能,以方便编写脚本和自动化各种任务。
psql
通常作为 PostgreSQL 服务器或客户端软件包的一部分进行安装。
- Debian/Ubuntu:
sudo apt install postgresql-client
- RHEL/CentOS:
sudo dnf install postgresql
- macOS (Homebrew):
brew install libpq
(然后可能需要链接psql
) 或brew install postgresql
- Windows: 通过官方的 EnterpriseDB 安装程序安装。
基本用法:
MySQL5.7在compose部署时内存异常Bug
Bug 描述
在使用 Docker Compose(version v2.35.1)
部署 MySQL 5.7
时,发现我16G的内存几乎被耗尽,通过 docker stats
命令查看,发现MySQL5.7对应的容器占用了几乎所有的内存。
尝试通过 docker run
来部署结果也一样 (docker version: 28.1.1
)
不死心的我于是通过限制资源,在docker-compose.yml
中添加了内存大小限制,内容如下:
deploy:
resources:
limits:
memory: 2G
但接下来问题更离谱了,MySQL5.7对应的容器甚至不能正常启动了,一直不断重启,通过 docker compose logs mysql57
查看日志,内容如下:
mysql5_7 | 2025-05-20 14:56:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
mysql5_7 | 2025-05-20 14:56:43+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
mysql5_7 | command was: mysqld --verbose --help
看起来似乎是因为配置文件的问题,但实际上并没有那么简单。在不联网搜索的情形下询问过多个大模型均不能给出正确答案,只有 Gemini 2.5 Pro 选中联网搜索时,找到了相关的信息。其实通过普通搜索引擎也能找到答案,不少人都遇到过类似的问题。
NUC8黑苹果
- 硬改方案:
- 原装硬件
NUC8安装Ubuntu
Intel的NUC8i5BEK用来搞黑苹果性能还是不太够,所以打算换个Ubuntu试试。
准备工作
-
下载Ubuntu镜像(如:
ubuntu-24.10-desktop-amd64.iso
):华为云下载 -
制作/烧录安装U盘, 我使用的是 balenaEtcher, 下载完工具后插入U盘,然后选择镜像文件,点击
Flash!
即可。
安装Ubuntu
启动NUC8,按下F2
进入BIOS设置,将 U 盘的启动优先级设置为最高,然后保存并退出。
选择安装系统后开始安装,安装过程中会有一些设置,这里不再赘述,如果发现 wifi 和蓝牙相关驱动报错先无视即可,安装完成后再手动安装相应驱动
安装完成后,可以安装一些常用的软件:
sudo apt install -y openssh-server
sudo apt install net-tools -y
注意:安装完成后,如果没有没有网线,可利用手机的 USB共享网络 来连接网络。
安装三方驱动
由于我的 NUC 买的时候就是硬改过的,所以 wifi 和 蓝牙 Ubuntu原生并没有驱动,安装系统后需要手动安装下驱动
常用网站导航 | 资源分享 | 项目 | 优质Blog
Develop
数据结构
数据结构图例:https://www.cs.usfca.edu/~galles/visualization/Algorithms.html
Java
Project
大麦网:https://javaup.chat/
充电桩:https://www.yuque.com/cwnait/zno126/zhrgs2mzhkdbosxw 密码:xfhe
Java面试
K:
https://wi1v74w740.feishu.cn/docx/S05pdyvrHoOy42xQYe7cgKgnn8e
图灵:
100万字面试题资料:https://www.yuque.com/tulingzhouyu/db22bv 密码:cns8
《2024面试项目场景题合集》 :https://www.yuque.com/aaron-wecc3/dqt601?# 密码:gk0n
p5-p7学习路径:https://www.processon.com/view/link/653b5c2403971068579f8dcf
视频资源
UI设计
常用工具导航
软件资源分享地址:https://flowus.cn/share/9ac54361-fb97-4f19-88e5-6c8178df964e
电子书格式转换:https://www.neat-reader.cn/converter/docx-zhuan-txt 流氓软件清理:https://github.com/qundao/mirror-softcnkiller kun_tools: https://wwx.lanzouk.com/b03kil8bc 密码:6i5t ,夸克:https://pan.quark.cn/s/17b5704f08e5 图压 混剪辑 Datatool.vip image-matting AI抠图:https://github.com/pangxiaobin/image-matting mindppt(小程序) saltyleo 电子书 pixpin 截图:https://pixpin.cn/ IFIXIT (修理电子设备的网站) flix 文件传输 oeasy教程 小丸工具箱 password protect video master algermusic
深藏不露的Bug:当Kryo序列化遇上toString()
在软件开发中,我们时常与各种Bug不期而遇。有些Bug显而易见,错误日志直指病灶;而另一些则如冰山一角,表面现象可能误导我们偏离真正的根源。
本文将详细复盘一个在Java项目中,因错误处理Kryo序列化字节流而导致的Bug: ClassNotFoundException
,揭示一个使用Kryo序列化后又使用 toString()
导致的Bug。
项目背景和问题分析
AI工具日趋强大,为了熟悉Spring AI和体验现在AI编程工具的潜力,我选择了使用AI来辅助我开发一个基于Spring AI的项目。
一个令人困惑的Bug
在使用Spring AI构建聊天功能时,实现对话记忆(ChatMemory
)时计划采用Kryo进行序列化,并存储于Redis中。
于是我在IDEA中通过 AI 插件实现了 RedisChatMemory
类,以实现基于Redis的AI对话记忆功能。代码如下:
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.io.Input;
import org.objenesis.strategy.StdInstantiatorStrategy;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
@Component
public class RedisChatMemory implements ChatMemory {
private final StringRedisTemplate redisTemplate;
private static final Kryo kryo = new Kryo();
static {
kryo.setRegistrationRequired(false);
// 设置实例化策略
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
}
@Autowired
public RedisChatMemory(StringRedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
@Override
public void add(String conversationId, List<Message> messages) {
List<Message> conversationMessages = getOrCreateConversation(conversationId);
conversationMessages.addAll(messages);
saveConversation(conversationId, conversationMessages);
}
@Override
public List<Message> get(String conversationId, int lastN) {
List<Message> allMessages = getOrCreateConversation(conversationId);
return allMessages.stream()
.skip(Math.max(0, allMessages.size() - lastN))
.toList();
}
@Override
public void clear(String conversationId) {
redisTemplate.delete(conversationId);
}
private List<Message> getOrCreateConversation(String conversationId) {
String data = redisTemplate.opsForValue().get(conversationId);
if (data != null && !data.isEmpty()) {
try (Input input = new Input(new ByteArrayInputStream(data.getBytes()))) {
return kryo.readObject(input, ArrayList.class);
} catch (Exception e) {
e.printStackTrace();
}
}
return new ArrayList<>();
}
private void saveConversation(String conversationId, List<Message> messages) {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
Output output = new Output(bos)) {
kryo.writeObject(output, messages);
output.flush();
redisTemplate.opsForValue().set(conversationId, bos.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
然而,系统在运行中突然抛出异常:
Markdown 是一种轻量级标记语言,创始人为约翰·格鲁伯(John Gruber)。它允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文档。
常用语法
- 标题: 使用
#
号,例如# 一级标题
,## 二级标题
。 - 列表: 使用
*
,+
, 或-
创建无序列表,使用数字加点创建有序列表。 - 链接:
[链接文本](链接地址)
- 图片:

高级特性
代码块,表格