个人博客部署 github pages+hugo extened

### github 创建
创建仓库 https://github.com/username/username.github.io.git
打开 https://username.github.io/

### 本机( Windows11)安装 Hugo extened
打开 https://github.com/gohugoio/hugo/releases
找到并下载 hugo_extended_0.125.3_windows-amd64.zip
解压后,将其中的 hugo.exe 放到 C:\Program Files\Hugo\bin
然后将该目录添加到系统环境变量(win+R → sysdm.cpl → 高级 → 环境变量 → 系统变量 Path)的 Path 下
打开命令行,输入 hugo version,显示版本号即为安装成功

# 使用 Hugo 创建博客站点
hugo new site blog

打开选择 Hugo 主题站中,找到需要的主题模板
https://themes.gohugo.io

# 进入网站目录 下载主题
cd blog/themes
git clone https://github.com/wlh320/hugo-theme-hulga.git

将 themes/hugo-theme-hulga/exampleSite/hugo.toml 复制到根目
将 themes/hugo-theme-hulga/exampleSite/content 复制到根目

复制 package.json , postcss.config.js 到根目录
npm install

修改hugo.toml
找到 languageCode = 'en-us' 修改为 languageCode = 'zh-CN'
找到 theme = "../../" 修改为 theme = "hugo-theme-hulga"

# 新建文章,编辑后保存
hugo new post/first-post.md

# 启动 Hogo server
hugo server -D
打开 http://localhost:1313/

### 设置发布目录的分支
cd blog
mkdir public && cd pubic
git init
git remote add origin https://github.com/username/username.github.io.git
git pull origin main
git branch -a
git branch -m "main"

#发布站点
cd blog
hugo -t=hugo-theme-hulga -b=http://username.github.io/

# 推送到github (命令行上传,需要到github上申请 access tokens)

# Settings-Developer Settings-Personal access tokens(classic)
# 申请后复制下来,push时提未账号密码时,作为密码授权

cd public
git commit -am "first commit"
git push -u origin main
打开 https://username.github.io/
--------------------------------------------------------------------------------------------

 ### 参考脚本

#!/bin/sh
# If a command fails then the deploy stops
set -e
printf "\033[0;32mDeploying updates to GitHub...\033[0m\n"
hugo -d docs 
git add docs
msg="rebuilding site $(date)"
if [ -n "$*" ]; then
msg="$*"
fi
git commit -m "$msg"
git push origin main

========================================================
1)查看分支
git branch //查看本地分支
git branch -r //查看远程分支
git branch -a //查看所有分支,包括本地和远程的分支

2)切换分支
git checkout dev //切换到dev分支上

3)创建分支
git checkout dev //在当前分支上创建dev分支
git checkout -b dev //在当前的分支上新创建的dev分支并切换到新的创建的dev分支上
git push origin dev // 创建远程dev分支,本地dev分支必须存在

4)查看分支是从哪个分支上创建的
git reflog --date=local --all | grep dev //查看在dev分支上的操作
git reflog show --date=iso dev

5)删除分支
git branch -d dev //删除本地dev分支
git push origin --delete dev //删除远程dev分支

6)分支的合并merge
git merge dev //将dev分支合并到当前分支(一般是master主分支)
git push //将当前分支代码push到远程分支上

7)查看commit记录
git log --graph //#查看历史提交记录

posted @ 2024-04-23 14:45  vicowong  阅读(4)  评论(0编辑  收藏  举报