使用Hexo部署NexT主体网站

一.使用git提交文件

参考: 从零开始搭建个人博客(超详细) - 知乎 致谢!

第一种:本地没有 git 仓库

  • 直接将远程仓库 clone 到本地;

  • 将文件添加并 commit 到本地仓库;

  • 将本地仓库的内容push到远程仓库。

    ssh -T [email protected] Hi xidianswq! You've successfully authenticated, but GitHub does not provide shell access. git clone [email protected]:xidianswq/switch_homepage.git
    Cloning 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 status
    On branch main
    Your branch is up to date with 'origin/main'.
    Untracked files:
    (use "git add <file>..." to include in what will be committed)
    test.txt

    复制代码
      nothing 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.txt
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 test.txt
    $ git log
    commit 4463650540e1bc66dc16aedc8b132e11b5e469ed (HEAD -> main)
    Author: xidianswq [email protected]
    Date: Thu Feb 6 22:31:41 2025 +0800

    复制代码
          test.txt
      
      commit 8f09f668066393a7b16b2c8c5df31e0d6a64eaa1 (origin/main, origin/HEAD)
      Author: xidianswq <[email protected]>
      Date:   Thu Feb 6 21:32:08 2025 +0800
      
          Initial commit

    $ git push origin main
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 16 threads
    Compressing 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 0
    To github.com:xidianswq/switch_homepage.git
    8f09f66..4463650 main -> main


第二种:本地有 Git 仓库,并且我们已经进行了多次 commit 操作

  • 建立一个本地仓库进入,init 初始化;

  • 关联远程仓库;

  • 同步远程仓库和本地仓库;

  • 将文件添加提交到本地仓库;

  • 将本地仓库的内容 push 到远程仓库。

    ssh -T [email protected] Hi xidianswq! You've successfully authenticated, but GitHub does not provide shell access. cd switch_homepage/public/switch_homepage/
    git remote add origin [email protected]:xidianswq/switch_homepage.git git add test2.txt
    git commit -m "test2.txt" git push origin master
    Enumerating 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 0
    remote:
    remote: Create a pull request for 'master' on GitHub by visiting:
    remote: https://github.com/xidianswq/switch_homepage/pull/new/master
    remote:
    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: git
    		repository: 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篇------优化主题(持续更新) - 知乎](https://zhuanlan.zhihu.com/p/106060640) \[2\] [在hexo博客中插入图片的方法_hexo插入图片-CSDN博客](https://blog.csdn.net/2301_77285173/article/details/130189857) ***致谢!***

  • 下载主题next:
text 复制代码
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博客

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主体颜色更改

最后,欢迎参观我的主页!

相关推荐
RadNIkMan21 分钟前
Python学习(二)操作列表
网络·python·学习
笑鸿的学习笔记23 分钟前
ROS2笔记之服务通信和基于参数的服务通信区别
android·笔记·microsoft
yanxy5121 小时前
【TS学习】(15)分布式条件特性
前端·学习·typescript
lalapanda1 小时前
UE5学习记录 part13
学习·ue5
高林雨露1 小时前
Java对比学习Kotlin的详细指南(一)
java·学习·kotlin
安建资小栗子2 小时前
2025年汽车加气站操作工备考题库
笔记
齐尹秦2 小时前
HTML5 Web Workers 学习笔记
笔记·学习
DarkBule_2 小时前
零基础驯服GitHub Pages
css·学习·html·github·html5·web
Li_na_na012 小时前
解决安卓手机WebView无法直接预览PDF的问题(使用PDF.js方案)
android·pdf·uni-app·html5
疾风铸境3 小时前
Qt5.14.2+mingw64编译OpenCV3.4.14一次成功记录
前端·webpack·node.js