本地博客
安装Hugo
brew install hugo
建立新站点
hugo new site blog
添加主题
cd blog
git init
git submodule add https://github.com/budparr/gohugo-theme-<YOURTHEME>.git themes/<YOURTHEME>
新建文章
hugo new posts/article.md
开启本地服务
hugo server
GitHub部署Hugo
创建GitHub项目
项目名称为xxx.github.io
(xxx为你想要的项目名)
关联Github
hugo --theme=主题名称 --baseUrl="https://xxx.github.io"(xxx表示你的github..) --buildDrafts
cd public
git init .
git add .
git commit -m "xxx"
- `git remote add origin 仓库地址
git push -u origin 分支名
- github为该项目配置page及域名,输入域名即可访问
博客修改更新
-
博客根目录创建deploy.sh并输入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/bin/sh # If a command fails then the deploy stops set -e # Print out commands before executing them set -x printf "\033[0;32mDeploying updates to GitHub...\033[0m\n" # Build the project. hugo -t 主题文件夹名称 --buildDrafts # Go To Public folder cd public # Add changes to git. git add . # Commit changes. msg="rebuilding site $(date)" if [ -n "$*" ]; then msg="$*" fi git commit -m "$msg" git pull origin main # Push source and build repos. git push origin main # Back to the origin folder # cd .. # rm -rf public
-
博客根目录命令行执行
./deploy.sh "网站更改的内容"