搭建个人博客
Windows:
choco install hugo -y
MacOS:
brew install hugo
Linux:
sudo apt-get install hugo
创建博客项目
创建一个新的Hugo项目:
hugo new site my-blog
cd my-blog
添加主题
Hugo提供了丰富的主题,你可以从Hugo Themes网站选择一个喜欢的主题。以下以ananke主题为例:
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo ‘theme = “ananke”’ >> config.toml
创建内容
创建一个新文章:
hugo new posts/my-first-post.md
编辑生成的Markdown文件,添加内容:
title: “My First Post”
date: 2024-10-01T15:00:00+08:00
draft: false
This is my first post on my new blog.
启动本地服务器
启动Hugo本地服务器,预览博客:
hugo server
访问http://localhost:1313,你将看到你的个人博客。
部署个人博客
搭建好本地博客后,下一步是将其部署到互联网上,让全世界都能访问。
使用GitHub Pages部署
GitHub Pages是一个免费的静态网站托管服务,非常适合部署Hugo博客。
创建GitHub仓库:在GitHub上创建一个新的仓库,例如yourusername.github.io。
配置Hugo:在config.toml中添加以下配置:
baseURL = “https://yourusername.github.io/”
生成静态文件:
hugo
部署到GitHub Pages:将生成的public目录内容推送到GitHub仓库:
cd public
git init
git remote add origin https://github.com/yourusername/yourusername.github.io.git
git add .
git commit -m “Initial commit”
git push -u origin master
访问博客:访问https://yourusername.github.io/,你的博客已经上线了!
优化与维护
添加元标签:在layouts/partials/head.html中添加SEO相关的元标签,如。
使用友好URL:确保文章的URL简洁易读,如/posts/my-first-post/。