网盘博客搭建参考简略教程
目录
本文记录了在 CentOS 7 环境下,从零搭建 Hugo Extended + LoveIt 主题 博客,并将文章存储目录放置在 坚果云挂载目录 中参考过程,回忆记录包含所有关键配置,避免踩坑。
关键词:CentOS7 Hugo(Extended) LoveIt主题 坚果云挂载
1. 系统环境说明
| 项目 | 说明 |
|---|---|
| 系统 | CentOS 7 (其他linux版本同样适用) |
| Hugo | Extended 版本(必须支持 SCSS 编译) |
| 主题 | LoveIt |
| 文章存储 | VPS 本地 + 坚果云挂载目录 |
| 访问入口 | https://www.edu365.site/ |
| 部署模式 | hugo server 实时更新 |
2. 安装基础依赖
yum -y install git wget gcc make golang
注:可在其他centos7环境下安装编译,编译完成后将编译好的二进制hugo版本复制至当前系统
3. 编译并安装 Hugo Extended
git clone https://github.com/gohugoio/hugo.git
cd hugo
go install --tags extended
cp ~/go/bin/hugo /opt/hugo/hugo
chmod +x /opt/hugo/hugo
验证:
/opt/hugo/hugo version
输出中必须包含 extended。
go version
go version go1.22.4 linux/amd64
注:centos7下载go1.22版本后进行编译hugo extended,其他linux(如debian12,支持glibc2.33)可直接下载官网已编译好的版本即可,无需自行编译。
4. 创建博客并添加 LoveIt 主题
cd /opt
hugo new site blog
cd blog
git init
git submodule add https://github.com/dillonzq/LoveIt themes/LoveIt
注:搭建过程未使用Git,实际下载源码LoveIt解压至themes目录下
5.文章目录与坚果云挂载映射 挂载目录示例:
ln -s /mnt/jianguoyun/blog /opt/blog/content/posts/blog
使用 Module Mount 映射目录(避免软链接不生效) 编辑 hugo.toml:
[module]
[[module.mounts]]
source = "content/posts"
target = "content/posts"
[[module.mounts]]
source = "content/about"
target = "content/about"
[[module.mounts]]
source = "/mnt/jianguoyun/blog"
target = "content/posts/blog"
注:本教程以坚果云为例,实际替换为其他webdav协议网盘或NFS协议服务器共享目录同样适用,不局限于坚果云网盘。
6. 修复 About 页面无法访问问题 编辑 content/about/index.zh-cn.md:
---
title: "关于"
draft: false
type: "page"
url: "/about/"
---
LoveIt 默认把 about 当成 Section,不加 type = “page” 就会 404。
7. 修复微博分享地址总是 localhost:1313 使用正确的 baseURL:
bash 复制代码
/opt/hugo/hugo server -b "http://www.edu365.site/" --bind=0.0.0.0 --port=80
并确保配置文件中:
baseURL = “http://www.edu365.site/"
8. 修复移动端首页文章内容过长导致排版混乱 创建或编辑:
assets/css/_custom.scss
写入:
@media screen and (max-width: 768px) {
article.single.summary .content {
display: -webkit-box !important;
-webkit-box-orient: vertical !important;
-webkit-line-clamp: 5 !important;
overflow: hidden !important;
max-height: 200px;
}
}
9. systemd 启动 Hugo 创建:
/etc/systemd/system/hugo.service 内容:
[Unit]
Description=Hugo Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/blog
ExecStart=/opt/hugo/hugo server --disableFastRender --ignoreCache -b "http://www.edu365.site/" --bind=0.0.0.0 --port=80
Restart=on-failure
Environment=HUGO_ENV=development
[Install]
WantedBy=multi-user.target
启动:
bash 复制代码
systemctl daemon-reload
systemctl restart hugo
systemctl enable hugo
10. 部分常见问题与解决
| 问题 | 原因 | 解决方案 |
|---|---|---|
| About 页面 404 | LoveIt 主题将 about 视为特殊页面,未按常规生成 |
在 content/about/index.zh-cn.md 中加入 type = "page" 和 url = "/about/" |
| 首页文章摘要在手机端过长 | LoveIt 默认不做内容截断 | 在 assets/css/_custom.scss 中加入 -webkit-line-clamp 自定义截断规则 |
微信/微博分享时仍出现 localhost:1313 |
baseURL 未生效 或 启动参数覆盖 |
在 systemd 中使用 ExecStart=/opt/hugo/hugo server -b "http://你的域名" 重新启动服务 |
| 修改内容后页面不更新 | Hugo 使用缓存 | 启动时添加 --disableFastRender --ignoreCache 或执行 rm -rf public resources/_gen 再 hugo --gc --minify |
| 文章放在坚果云挂载目录后不显示 | Hugo 默认不会跟踪软链接或外部挂载 | 在 hugo.toml 中使用 module.mounts 显式挂载文章目录 |
public 目录内容与实际内容不一致 |
正在使用 hugo server 而不是 hugo build |
本地预览只看内存构建,发布需使用 hugo --gc --minify 重建 |
| 移动端文章标题换行不自然 | 默认 CSS 行高偏紧 | 在 _custom.scss 中重写 .single-title 字体大小与 word-break |
如果你也在搭建网盘博客,希望这份笔记能帮助你少走弯路。
搭建过程曲折,问题很多,但每个问题都不难,搭建完成后就可以直接复制blog目录进行备份和迁移,后续只需更新坚果云目录即可更新博客,其他配置已上传网盘共享目录)