Hello World!
博客搭建过程
博客基于 cotes2020/jekyll-theme-chirpy 项目,该项目基于Jekyll(一个用Ruby写的将原始文本转化成静态网站的工具)
一、安装依赖
(一)Ruby环境
1、安装Ruby
如在Windows上安装rubyinstaller-devkit-3.2.2-1-x64.exe,安装最后一步,勾选该项:Run ‘ridk install’ to set up MSYS2 and the development toolchain. MSYS2 is required to install gems with C extensions.
2、安装RubyGems
在弹出的cmd命令行中输入3并回车(This is needed for installing gems with native extensions.),等待cmd命令运行完成,回车退出命令行
(二)Jekyll
3、用 RubyGems 安装 Jekyll和 bundler
在新的cmd命令行中运行
gem install jekyll bundler
(三)Node.js
chirpy主题初始化项目时需要
(四)可选工具
二、初始化项目
(一)fork 项目
cotes2020/jekyll-theme-chirpy项目并clone到本地
这里使用Github Desktop将fork的代码clone下来(注意网络环境)
(二)初始化项目
打开Git Bash,在项目根目录下运行该命令,执行tools目录下的init脚本进行初始化(pwd可查看当前路径)
1
bash tools/init
(三)安装依赖项
打开cmd,在项目根目录下运行该命令安装依赖
1
bundle
(四)进行本地预览
在cmd or Git Bash中运行该命令进行本地预览
1
bundle exec jekyll s
三、Github Pages
本地将修改commit之后,push至Github,push会自动触发Github Action,进行build和deploy。也可以在Github项目的repo下,Action –> Build and Deploy中Run workflow手动进行。
四、Git使用相关
(一)合并不同repo中存在conflict的代码
fork的upstream(master)进行了更新,自己fork的origin(main)也进行了更新,现在需要将upstream repo的master中的commit同步到origin repo的main branch,Github提示有conflict,Can’t automatically merge.
理论流程:将upstream repo的master branch fetch到origin main上,解决conflict后,进行commit和push。
解决:在Github Desktop中切换到origin repo的main branch,菜单栏选择branch –> Merge into current branch… 或者是 Rebase current branch…进行同步操作,当存在conflict时,会提示进行修改,确定一个最终状态修改好之后进行commit和push。
参考:git分支与冲突,git rebase和 git merge
(二)撤回push的commit
commit了两次,push到了Github,然后发现commit有问题,该如何撤回commit和push
在本地打开Git Bash
使用git reflog
确定自己想要回到的节点的commit及版本号
假设想要回到的commit版本号位123456b
,通过下面的命令直接将本地代码回到那个版本(直接改变源码,后面的修改在本地直接丢失)
1
git reset --hard 123456b
然后push本地的代码,这样就回到了123456b
版本号对应的commit位置。
1
git push repo_name branch_name --force
本地branch提交云端(本地退回之后强制覆盖云端)
1
git push origin --force
(三)dev部署成功后同步至master分支
查看分支
1
git branch
切换至master分支
1
git checkout master
将dev分支合并到master分支
1
git merge dev
将本地的master分支push至云端
1
git push origin --force
(四)参考
五、注意
(一)文章头部格式说明
1
2
3
4
5
6
7
8
9
10
11
---
layout: post
title: Hello World!
date: 2023-10-1 20:52:34 +0800
Author: Sokranotes
tags: [blog building, ]
comments: true
categories: technology blog_building
toc: true
typora-root-url: ..
---
说明:
- title:文章标题
- data:文章显示的日期,日期 时间 时区(默认为0时区)
- toc:文章侧边目录是否开启(need confirm)
- categories: 设置categories,子目录直接在后面添加,以空格隔开,最多支持二级目录(need confirm)
- 图片位置说明:上传图片不能置于/_post路径下,需放在/assets目录下(need confirm)
- typora-root-url:设置在typora中的根目录,方便typora中图片显示
(二)注意事项
1、图片必须要有alt属性,哪怕为空。
2、http禁用,必须使用https。
3、提交commit必须遵循commitlint规范。
否则会报husky - commit-msg script failed (code 1)错误。
type: fix, docs, feat, style等
subject:描述,必须小写
示例如下:type的冒号后面必须要有空格
1
fix: fix a bug of stack over flow
六、长时间未跟进chirpy项目的更新
1、保存好_config.yml,README.md,_posts,assets目录的img及music资源, _data目录的authors.yml,contact.yml,share.yml, _includes目录的sidebar.html,以及 _tabs目录的about.md;
2、用chirpy项目最新覆盖dev分支并执行项目初始化操作;
3、将保存好的内容更新至dev分支;
4、push至云端并同步至master分支。
七、个性化修改(todo)
todo