返回

使用Hugo + GitHub Pages + Cusdis搭建免费的个人博客系统

搭建一个免费的个人博客系统,可以使用 Hugo 静态网站生成器、GitHub Pages 作为托管平台以及 Cusdis 作为评论系统。以下是详细的步骤和示例代码:

1. 安装 Hugo

首先,你需要在你的计算机上安装 Hugo。你可以从 Hugo 官网 下载并安装适合你操作系统的版本。

2. 创建一个新的 Hugo 站点

打开终端或命令提示符,运行以下命令来创建一个新的 Hugo 站点:

hugo new site myblog
cd myblog

这将创建一个名为 myblog 的新目录,其中包含一些默认的配置文件和文件夹。

3. 添加主题

选择一个你喜欢的 Hugo 主题。这里以 ananke 为例:

git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo 'theme: "ananke"' >> config.toml

4. 配置 Cusdis 评论系统

config.toml 文件中添加 Cusdis 的配置信息:

[params]
    cusdis = {
        appId = "your_cusdis_app_id"
        host = "https://cusdis.com"
        scriptSrc = "//cdn.cusdis.com/js/cusdis.es.js"
    }

你需要在 Cusdis 注册账号并创建一个应用来获取 appId

5. 编写内容

使用 Hugo 的命令来创建新的文章:

hugo new posts/my-first-post.md

编辑 content/posts/my-first-post.md 文件,添加你的文章内容和标题等。

6. 本地预览

运行以下命令来启动本地服务器预览你的网站:

hugo server -D

访问 http://localhost:1313 查看你的博客。

7. 部署到 GitHub Pages

首先,初始化你的 Git 仓库并提交你的更改:

git init
git add .
git commit -m "Initial commit"

然后,将你的仓库推送到 GitHub:

git remote add origin https://github.com/yourusername/yourrepository.git
git push -u origin master

在 GitHub 仓库的设置中,找到 "Pages" 部分,选择 master 分支作为 GitHub Pages 的源。

8. 完成

现在,你的博客已经成功部署到了 GitHub Pages,并且集成了 Cusdis 评论系统。每当你更新内容并推送到 GitHub,GitHub Pages 会自动更新你的网站。