基于 hugo 构建个人博客

基于 hugo 构建个人技术博客剥离了数据库和动态脚本的复杂性,让你能完全专注于写作和技术分享。另外,hugo 的工作方式可以非常自然地借助 git 对文章进行版本管理,特别适合有一定命令行基础的人。 1. 准备工作,安装必要工具 需要安装两个基础软件: Git:用于文档版本管理和后续的主题安装。 Hugo (扩展版):核心的静态网站生成器。建议安装带有“extended”后缀的版本,以确保支持Sass/SCSS等现代主题特性。 macOS用户:brew install hugo 国内用户可能需要为 brew 配置 proxy,例如为 brew 配置 SOCKS5 代理: export all_proxy=socks5://$HOST:$PORT 或者为 brew 配置 HTTP 代理: export http_proxy=http://$HOST:$PORT Windows用户:可以使用 scoop install hugo-extended,或从Hugo GitHub Releases页面下载。 安装完成后,在终端输入 hugo version 验证是否成功。 注意:不同 hugo 主题对 hugo 的版本有一定需求,可以从 Hugo GitHub Releases 页面下载特定版本 2. 搭建博客骨架 在终端执行以下命令,Hugo会为你生成一个包含所有必要目录的站点骨架。 # 创建一个名为 "my-blog" 的站点(可替换为你喜欢的名字) hugo new site my-blog Congratulations! Your new Hugo site was created in ./my-blog. Just a few more steps... 1. Change the current directory to ./my-blog. 2. Create or install a theme: - Create a new theme with the command "hugo new theme <THEMENAME>" - Or, install a theme from https://themes.gohugo.io/ 3. Edit hugo.toml, setting the "theme" property to the theme name. 4. Create new content with the command "hugo new content <SECTIONNAME>/<FILENAME>.<FORMAT>". 5. Start the embedded web server with the command "hugo server --buildDrafts". See documentation at https://gohugo.io/. # 进入站点目录 cd my-blog # 目录下生成了 `archetypes`、`content`、`themes`等文件夹和 `hugo.toml` 配置文件 tree . ├── archetypes │ └── default.md ├── assets ├── content ├── data ├── hugo.toml ├── i18n ├── layouts ├── static └── themes 8 directories, 2 files # 初始化Git仓库,方便后续管理主题和代码 git init # 为项目配置 .gitignore 文件 .gitignore 文件示例: # 构建输出目录 /public/ # 本地构建缓存与锁文件 /resources/ /.hugo_build.lock # 编辑器/IDE辅助文件 /assets/jsconfig.json /hugo_stats.json # 操作系统无关文件 .DS_Store Thumbs.db 3. 选择并配置主题 Hugo本身不带默认样式,你需要选择一个主题。 ...

March 2, 2026 · 2 min · Carl Cui