PrimeEdge 主题教程

安装部署

安装 PrimeEdge 主题并部署到线上

安装部署

本章节介绍如何安装 PrimeEdge 主题,以及几种常见的部署方式。

环境要求

  • Hugo Extended 版本 0.120.0 或更高
  • Git

安装主题

方式一:作为 Git Submodule(推荐)

# 进入你的 Hugo 站点根目录
cd your-site

# 初始化 Git(如果还没初始化)
git init

# 添加主题为子模块
git submodule add https://github.com/kok777/PrimeEdge.git themes/PrimeEdge

# 更新主题
git submodule update --remote --merge

使用子模块的好处是后续可以方便地更新主题,同时保留自定义内容。

方式二:直接克隆

git clone https://github.com/kok777/PrimeEdge.git themes/PrimeEdge

这种方式简单直接,但更新主题时需要手动处理。

方式三:下载压缩包

从 GitHub Releases 页面下载主题压缩包,解压到 themes/PrimeEdge 目录。

启用主题

hugo.toml 中配置:

theme = 'PrimeEdge'

创建基础内容

复制主题的示例内容作为起点:

# 复制示例配置
cp themes/PrimeEdge/exampleSite/hugo.toml ./hugo.toml

# 创建基础页面
hugo new content _index.md
hugo new content about.md

本地预览

hugo server -D

访问 http://localhost:1313 预览站点。加上 -D 参数可以同时预览草稿内容。

构建站点

hugo --minify

构建后的文件在 public/ 目录中。

部署方式

部署到 Vercel

  1. 在 Vercel 上导入你的 Git 仓库
  2. 构建命令填写 hugo --minify
  3. 输出目录填写 public
  4. 添加环境变量 HUGO_VERSION,值为你的 Hugo 版本号

部署到 Cloudflare Pages

  1. 在 Cloudflare Pages 连接你的 Git 仓库
  2. 构建命令:hugo --minify
  3. 构建输出目录:public
  4. 添加环境变量 HUGO_VERSION

部署到 GitHub Pages

使用 GitHub Actions 自动构建:

# .github/workflows/deploy.yml
name: Deploy to GitHub Pages

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: 'latest'
          extended: true
      - run: hugo --minify
      - uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public

部署到自有服务器

# 构建
hugo --minify

# 上传到服务器
rsync -avz --delete public/ user@server:/var/www/blog/

更新主题

子模块方式更新

git submodule update --remote --merge
git add themes/PrimeEdge
git commit -m "update theme"

克隆方式更新

cd themes/PrimeEdge
git pull
cd ../..

更新后建议先在本地预览,确认没有问题再部署到线上。

常见问题

Q: 构建报错 “module not found”

确保使用的是 Hugo Extended 版本:

hugo version  # 确认输出中包含 +extended

Q: 样式没有生效

检查 hugo.toml 中是否正确配置了 theme = 'PrimeEdge'

Q: 如何回退主题版本

cd themes/PrimeEdge
git log --oneline  # 查看提交历史
git checkout <commit-hash>  # 切换到指定版本
cd ../..

下一步

评论

0%