返回

从 Halo 到 Docsify:一个简单的博客搭建指南

后端

序言

作为一名技术从业者,拥有一个个人博客来分享自己的经验和心得,已经成为一种普遍的趋势。然而,在博客搭建的过程中,却往往会遇到各种各样的问题,让人头疼不已。

为了解决这些问题,本文将介绍一种简单易行的博客搭建方案,那就是使用 Docsify、Github webhook 和 JGit。这种方案的好处在于,它完全静态,无需任何后端,而且非常容易维护。

搭建步骤

1. 安装 Docsify

首先,我们需要安装 Docsify。Docsify 是一个纯静态的文档生成器,它可以将 Markdown 文件轻松转换为静态网站。

npm install docsify-cli -g

2. 初始化项目

安装完成后,我们可以在本地创建一个新的文件夹,然后使用 Docsify 初始化一个新的项目。

mkdir my-blog
cd my-blog
docsify init

3. 创建内容

初始化完成后,我们就可以在 docs 文件夹下创建 Markdown 文件来作为博客文章了。

mkdir docs
cd docs
touch my-first-post.md

my-first-post.md 文件中,我们可以写下我们的第一篇博客文章。

# 我的第一篇博客文章

## 标题 2

段落 1

段落 2

4. 构建项目

写好博客文章后,我们需要构建项目。

docsify build

构建完成后,我们会在 dist 文件夹下看到一个名为 index.html 的文件。这个文件就是我们的博客首页。

5. 部署项目

接下来,我们需要将项目部署到 Github 上。

git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/your-username/your-blog.git
git push -u origin master

部署完成后,我们就可以通过访问 https://your-username.github.io/your-blog 来访问我们的博客了。

Github webhook

为了使博客能够自动更新,我们需要设置 Github webhook。

https://docsify.js.org/#/advanced?id=github-webhook

设置完成后,每次我们往 Github 上推送代码,Docsify 就会自动构建项目并更新博客。

JGit

如果我们想使用 JGit 来管理博客文章,我们可以按照以下步骤操作:

  1. 安装 JGit。
mvn install:install-file -Dfile=/path/to/jgit-jar-file -DgroupId=com.google.gerrit -DartifactId=jgit -Dversion=X.Y.Z -Dpackaging=jar
  1. 创建一个新的 JGit 仓库。
git clone --bare https://github.com/your-username/your-blog.git
cd your-blog.git
  1. 将 Markdown 文件添加到 JGit 仓库。
git add docs/*.md
git commit -m "Add Markdown files"
git push origin master
  1. 使用 JGit 管理博客文章。

我们可以使用 JGit 来添加、删除和修改博客文章。

git add docs/new-post.md
git commit -m "Add new post"
git push origin master

结语

搭建个人博客,Docsify+Github webhook+JGit解决方案,希望对你有帮助。