Hugo多语言博客搭建与维护指南

博客搭建和管理流程

本指南详细记录了如何在 GitHub Pages 上撰写、上传、删除中英文博客的步骤,以及相关 Git 命令。

1. 博客内容撰写(包括中英文)

(1) 创建或修改博客文章

  1. 定位到 Hugo 博客内容目录: 博客内容存储在 content/posts/ 目录下。每篇文章应创建一个独立的文件夹,支持多语言版本。

  2. 创建新文章

    • 英文文章:
      1
      
      hugo new posts/my-new-post/index.en.md
      
    • 中文文章:
      1
      
      hugo new posts/my-new-post/index.zh-cn.md
      

    my-new-post即为新文章的标题。

  3. 编辑文章: 使用你喜欢的文本编辑器打开 index.en.mdindex.zh-cn.md 文件,进行博客撰写。

  4. 添加文章的 Front Matter: 在文章顶部添加必要字段:

    1
    2
    3
    4
    5
    6
    
    ---
    title: "My New Post"
    date: 2025-05-09T12:00:00+08:00
    draft: true
    language: en
    ---
    

(2) 本地查看和预览博客:

  • 启动本地开发服务器:
    1
    
    hugo server -D
    
    在浏览器中访问 http://localhost:1313 查看预览效果。

2. 提交和上传博客到 GitHub

(1) 确保所有文件被 Git 跟踪:

1
git add .

(2) 提交更改:

1
git commit -m "Add new blog post or update"

(3) 推送到 GitHub 仓库:

  • 如未配置远程仓库:
    1
    
    git remote add origin https://github.com/KeqiYe/myblog.git
    
  • 推送:
    1
    
    git push origin main
    

3. 删除博客文章 111

(1) 删除文章目录:

1
git rm -r content/posts/my-old-post

(2) 提交删除操作:

1
git commit -m "Remove old blog post"

4. 查看和调试部署结果

5. 常见问题解决

  • 文章不显示

    • 检查 Front Matter 的 language 字段。
    • 确认 GitHub Actions 已成功构建部署。
  • 链接错误

    • 确认 baseURL 配置正确:https://keqiye.github.io/
    • 检查部署分支和 GitHub Pages 设置。

6. 其他常用 Git 命令

  • 查看状态:
    1
    
    git status
    
  • 查看历史:
    1
    
    git log
    
  • 撤销已添加文件:
    1
    
    git restore --staged <file>
    
  • 撤销未提交修改:
    1
    
    git restore <file>
    
Licensed under CC BY-NC-ND 4.0
🪐 本站总访问量 次 | 📖 本文阅读量
使用 Hugo 构建
主题 StackJimmy 设计