一.使用git提交文件
参考: 从零开始搭建个人博客(超详细) - 知乎 致谢!
第一种:本地没有 git 仓库
- 直接将远程仓库 clone 到本地;
- 将文件添加并 commit 到本地仓库;
- 将本地仓库的内容push到远程仓库。
$ ssh -T git@github.comHi xidianswq! You've successfully authenticated, but GitHub does not provide shell access.
$ git clone git@github.com:xidianswq/switch_homepage.gitCloning into 'switch_homepage'...remote: Enumerating objects: 3, done.remote: Counting objects: 100% (3/3), done.remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)Receiving objects: 100% (3/3), done.
$ cd ./switch_homepage
$ git statusOn branch mainYour branch is up to date with 'origin/main'.Untracked files:(use "git add <file>..." to include in what will be committed)test.txtnothing added to commit but untracked files present (use "git add" to track)
$ git add test.txt
$ git commit -m test.txt "test.txt"[main 4463650] test.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 test.txt
$ git logcommit 4463650540e1bc66dc16aedc8b132e11b5e469ed (HEAD -> main)Author: xidianswq <3209507800@qq.com>Date: Thu Feb 6 22:31:41 2025 +0800test.txtcommit 8f09f668066393a7b16b2c8c5df31e0d6a64eaa1 (origin/main, origin/HEAD)Author: xidianswq <94434249+xidianswq@users.noreply.github.com>Date: Thu Feb 6 21:32:08 2025 +0800Initial commit
$ git push origin mainEnumerating objects: 4, done.Counting objects: 100% (4/4), done.Delta compression using up to 16 threadsCompressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 269 bytes | 269.00 KiB/s, done.Total 3 (delta 0), reused 0 (delta 0), pack-reused 0To github.com:xidianswq/switch_homepage.git8f09f66..4463650 main -> main
第二种:本地有 Git 仓库,并且我们已经进行了多次 commit 操作
- 建立一个本地仓库进入,init 初始化;
- 关联远程仓库;
- 同步远程仓库和本地仓库;
- 将文件添加提交到本地仓库;
- 将本地仓库的内容 push 到远程仓库。
$ ssh -T git@github.comHi xidianswq! You've successfully authenticated, but GitHub does not provide shell access.
$ cd switch_homepage/public/switch_homepage/
$ git remote add origin git@github.com:xidianswq/switch_homepage.git
$ git add test2.txt
$ git commit -m "test2.txt"
$ git push origin masterEnumerating objects: 3, done.Counting objects: 100% (3/3), done.Writing objects: 100% (3/3), 207 bytes | 207.00 KiB/s, done.Total 3 (delta 0), reused 0 (delta 0), pack-reused 0remote:remote: Create a pull request for 'master' on GitHub by visiting:remote: https://github.com/xidianswq/switch_homepage/pull/new/masterremote:To github.com:xidianswq/switch_homepage.git* [new branch] master -> master/
两种由于创建的主体不同,如果关联同一仓库即会产生分支Branches,例如main和master两个版本
二.Hexo部署个人博客
参考: 个人博客第5篇——安装node.js和Hexo - 知乎 致谢!
1.本地静态部署
- 完成git通过ssh连接github步骤
- node官网下载安装
- 用 node -v 和 npm -v 命令检查版本
- 设置npm在安装全局模块时的路径和环境变量(npm install X -g时的安装目录):
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"
- 设置环境变量
npm install webpack -g
github创建XXX.github.io仓库
npm install -g hexo-cli
hexo init
hexo g
hexo s #static deploy
解决 bash: hexo: command not found:
参考: 完美解决 bash: hexo: command not found-CSDN博客
2.动态部署及后续更新
- 修改hexo根目录_config.yml文件
deploy:type: gitrepository: XXX.github.io.git #你的仓库地址branch: master
npm install hexo-deployer-git --save
重新部署网页三条指令:
- hexo clean #清除缓存文件 db.json 和已生成的静态文件 public(同时检查语法)
- hexo g #生成网站静态文件到默认设置的 public 文件夹(hexo generate 的缩写)
- hexo d #自动生成网站静态文件,并部署到设定的仓库(hexo deploy 的缩写)
注:打开XXX.github.io网页时使用默认分支branch,可在设置内设置默认分支
(参考: github:master提交项目到远程仓库出现“There isn’t anything to compare.”_there isn鈥檛 anything to compare.-CSDN博客 )。
三.安装及优化NexT主题
1.安装NexT主题
参考目录:
个人博客第7篇——设置next主题 - 知乎 ;
个人博客第8篇——优化主题(持续更新) - 知乎
致谢!
- 在网页根目录:
git clone https://github.com/theme-next/hexo-theme-next themes/next
下载主题 - 打开根目录下的
\_config.yml
(称为站点配置文件),修改主题(注意冒号后都要有空格):
# Site
title: XXX #标题
subtitle: ''
description: 选择有时候比努力更重要 #简介或者格言
keywords:
author: XX #作者
language: zh-CN #主题语言
timezone: Asia/Shanghai #中国的时区# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next #主题改为next
- 打开目录Blog/themes/next/下的_config.yml(称为主题配置文件),选择需要使用的主题,注释其他的
# Schemes
#scheme: Muse
#scheme: Mist
#scheme: Pisces
scheme: Gemini #这是我选的主题
- 回到根目录打开Git Bash,输入如下三条命令:
hexo clean & hexo g & hexo d
2.优化主题
参考:
[1] 个人博客第8篇——优化主题(持续更新) - 知乎
[2] 在hexo博客中插入图片的方法_hexo插入图片-CSDN博客致谢!
- 下载主题next:
git clone https://github.com/theme-next/hexo-theme-next themes/next
- 参考博客中错误:
- 第6个,设置背景图片,添加内容的时候,url(/images/…),斜杠一定不要漏加
其他:
-
新建文章时,在相同目录下创建同名文件夹(便于图片管理)
- 打开站点配置文件_config.yml,搜索post_asset_folder字段,设置其值为true
- 安装hexo-asset-image:
npm install hexo-asset-image --save
- 此时hexo new "fileName"会在/source/_posts 目录下创建同名的文件夹
- 只需在 md 文件里使用 ![title](图片名.jpg) ,无需路径名就可以插入图片。
原文链接: Hexo框架下用NexT(v7.0+)主题美化博客_next主题魔改教程-CSDN博客
-
其他参考:
hexo+next添加鼠标点击和打字特效-CSDN博客
hexo博客工具屏蔽上传一些私人文章_hexo markdown设定文章不发布-CSDN博客
Hexo本地预览与部署样式不统一的几种可能的解决思路 | 云上时记
Hexo 博客上手入门指南、性能优化、界面美化、扩展功能、各种疑难杂症等解决方案全系列合辑 | 竹山一叶
3.NexT主体颜色更改
- 在网页上右键想要更改的样式,点击检查(或F12,在网页元素 “flex” 中寻找对应 html 代码)
- 在样式中找到对应规则,复制关键字,在vscode中寻找对应段代码,进行相应修改
- 一些常用的样式配置文件:
~\themes\next\source\css\\variables\base.styl
~\themes\next\source\css\\variables\Pisces.styl
~\themes\next\layout\macro\post.swig
~\themes\next\layout\\partials\footer.swig
themes\next\source\css\_common\outline\header\site-meta.styl
4.侧边栏“当前位置”显示样式更改
- vscode搜索
.sidebar-nav-active
,此为点击后的显示效果,可更改颜色与字体
.sidebar-nav-active {border-bottom-color: $sidebar-highlight;color: $sidebar-highlight;font-weight: bold;font-size: 1.05em;font-style: italic;&:hover {color: $sidebar-highlight;}
}
- 同理,更改
.active-current > a
,如下:
.active-current > a {color: $sidebar-highlight;font-weight: bold;font-size: 1.25em;font-style: italic;&:hover {color: $sidebar-highlight;}}
5.更改字体
(参考: 字体设置 - Hexo-NexT )
-
在 Browse Fonts - Google Fonts 网站点击想使用的字体
- 点击
Get font
、Get embed code
- 复制
Embed code in the <head> of your html
内的内容 - 复制
字体: CSS class
内的内容
- 点击
-
修改
~\themes\next\layout\_partials\head\head.swig
,在{{ next_font() }}
下添加之前复制的内容<link href="https://fonts.googleapis.com/css?family=Noto+Serif+SC|Roboto&display=swap" rel="stylesheet">
-
在需要修改字体的地方添加或修改
font-style
,如何搜索修改位置见上NexT主体颜色更改
最后,欢迎参观我的主页!