How_to_hugo日常使用篇
How to hugo 日常使用篇
本篇介绍如何发布一篇文章并编写shell脚本快捷发布/
本篇文章介绍如何发布一篇文章并上传到网页端. 一共只有两个步骤
本地撰写博文
cd ./mytopia
hugo server -D // 此时开启的是fast render 模式, 会热更新你的博文编辑.
hugo new /posts/new_intro.md // 创建一篇新的博文发布
cd ./mytopia
hugo -D // 默认hugo new出来的文章都有个标签是草稿, -D 指的是build 所有草稿
cd build
git add .
git commit -m "xxx"
git push original master注意, 以上这部分推送之后, 页面就更新了, 但是其实本体文件并没有上传到github保存, 建议先如下操作:
cd ./mytopia
hugo -D
git add .
git commit -m "xxx"
git push original master由于每次想写文章都要敲以上那么多条命令, 当然我们还是写一个shell脚本更加方便.
shell 脚本自动发布
deploy.sh 使用方法:
- 复制如下脚本并
chomd + x deploy.sh - 自动commit
./deploy.sh自动push 到github并更新page, 或者./deploy.sh + xxx
#!/bin/sh
# If a command fails then the deploy stops
set -e
printf "\033[0;32mDeploying updates to tangzhongham...\033[0m\n"
# Build the project.
hugo -D # if using a theme, replace with `hugo -t <YOURTHEME>`
# push your files to github
msg="saving file and rebuilding site $(date)"
if [ -n "$*" ]; then
msg="$*"
fi
git add .
git commit -m "$msg"
# Push source and build repos.
git push origin master
# Go To Public folder
cd public
# Add changes to git.
git add .
# Commit changes.
git commit -m "$msg"
# Push source and build repos.
git push origin master
printf "upload success, enjoy your journey! "TODO
创建了一个改版的sh文件,不知道咋样,试试.
一个很坑的事情, 按照文档添加 search 则会把homepage的介绍挤掉. 放到sidebar 则无法使用… 暂时去掉搜索吧.