0%

从0开始的ithub+hexo搭建个人博客

从0开始的github+hexo搭建个人博客

1 工具准备

使用<!-- more -->为阅读全文

2 安装hexo

  • 先安装cnpm,使得npm可替换为在国内可用的cnpm
  • npm install -g cnpm –registry=https://registry.npm.taobao.org
  • 然后按照hexo
  • cnpm install -g hexo
  • npm install hexo-deployer-git –save -g
  • 创建博客的本地目录
  • C:\Users\ZHANGCAIBIN>md blog
  • C:\Users\ZHANGCAIBIN>dir
  • cd blog
  • 初始化hexo模板
  • hexo init
  • 网页预览博客
  • hexo s
  • hexo s –debug
  • 创建第一篇文章
  • hexo n “My first essay”
  • 下载next主题https://www.cnblogs.com/yinxiang/p/9237752.html

3 写文章

  • 在soure里找到md并编辑

4 配置ssH

  • cd D:\blog

  • 安装hexo必要插件

  • npm install hexo-abbrlink –save

  • Git bash 内输入,设置ssh钥匙

  • ssh-keygen -t rsa -C “zhangcb21@lzu.edu.cn

  • 用txt打开pub,复制ssh-开头的全文内容,在github里总的settings中的ssh里创建新的中输入

  • 检测是否ssh设置成功

  • ssh -T git@github.com

  • 输入yes

    1
    2
    3
    4
    5
    6
    7
    8
    $ ssh -T git@github.com
    The authenticity of host 'github.com (20.205.243.166)' can't be established.
    ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
    This key is not known by any other names.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? ED25519
    Please type 'yes', 'no' or the fingerprint: yes
    Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
    Hi cz6900! You've successfully authenticated, but GitHub does not provide shell access.
    • 在github里创建respority

    • 打开blog下面_config.yml,添加

    • type: git

    • repo: 地址

    • branch: master

    •  git config --global user.email "zhangcb21@lzu.edu.cn"
       git config --global user.name "cz6900"
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30

      - 先按esc再按:wq

      - :wq!就是强制保存

      - type和repo的冒号后面要加空格,不然会卡死

      - 在git bash命令窗口中输入git config --global user.name "xxx"

      - windows这里报错的同学看下提示,输入两行代码配置,然后再hexo d就可以了

      ## 5 插入图片、音乐、视频 ##

      - 视频、音乐在网站上找镶入链接

      ` 图片用“![]()”格式 `

      ## 6 文本编辑类型 ##

      ``` library(ggplot2)
      library(ggsci)
      library(cowplot)

      data("iris")
      View(iris)

      ggplot (data = iris, mapping = aes (x = Species, y = Sepal.Length)) +
      geom_point (position = 'jitter', aes (color = Species),
      size = 3, alpha= 0.5, shape = 21) +
      theme_cowplot()

7 PDF

cnpm install –save hexo-pdf

8 阅读全文

1、开启阅读全文按钮,打开主题配置文件themes\next_config.yml,找到auto_excerpt

auto_excerpt:
enable: true
length: 150 #默认截取全文开篇前150字,可自行修改
————————————————

使用<!-- more -->为阅读全文

9 置顶

cnpm install hexo-generator-topindex –save

cnpm i object-assign

每篇文章加入top: 10

文章内加入的文件(图片等)名称内不得包含空格

默认情况下, Hexo文章图片左对齐

如何实现居中对齐呢

方法一

直接添加html元素,当然这种稍显麻烦,比较每次都要加html元素,还好一般图片不多适合

1
2
3
<div align=center>
![微信小程序 导航菜单](/images/miniapp-navigatortitle.png)
</div>

方法二

直接修改Hexo主题的css样式表

1
2
3
.posts-expand .post-body img {
margin: auto;
}

文章可以拥有如下属性:

Setting Description Default
layout Layout post或page
title 文章的标题
date 创建日期 文件的创建日期
updated 修改日期 文件的修改日期
comments 是否开启评论 true
tags 标签
categories 分类
permalink url中的名字 文件名

文字居中

这是需要居中的文字

这是需要居中的文字

这是字体 这是字体 这是字体 这是字体

10 部署

1
2
3
4
1. 在blog文件夹中右键git bash
2. hexo clean
3. hexo g
4. hexo d

11 可能出现的错误

1
2
3
4
5
6
7
8
9
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (C:\Users\myosotis\Desktop\Hexo_blog\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (events.js:315:20)
at ChildProcess.cp.emit (C:\Users\myosotis\Desktop\Hexo_blog\node_modules\cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
code: 128
}
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

方法一

1
2
3
4
5
6
7
8
9
10
##进入站点根目录

##删除git提交内容文件夹,
rm -rf .deploy_git/

##执行
git config --global core.autocrlf false

##最后
hexo clean && hexo g && hexo d

还需要手动删除这个文件夹 deploy_git/

方法二

修改 _config.yml 文件,将配置地址http方式切换成ssh方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
##进入站点根目录

##删除git提交内容文件夹
vim _config.yml

##修改
deploy:

type: git

repository: https://github.com/Uninfo/blog.github.io.git
-> git@github.com:Uninfo/blog.github.io.git

branch: master

##最后
hexo clean && hexo g && hexo d

方法三

强制上传,不建议

1
2
3
4
5
6
7
##进入站点根目录

##进入depoly文件夹
cd .deploy_git/

##强制推送
git push -f
1
2
3
解决The authenticity of host ‘github.com (20.205.243.166)‘ can‘t be established.

beichyes

已于 2023-03-29 15:27:28 修改

在使用git推送到github仓库的时候提示这个

需要将

202401022339391

将框内的key输入到下面的输入栏里面,然后的点ok

之后会弹出一个弹窗输入yes就行了202401022339305

img

————————————————
版权声明:本文为CSDN博主「beichyes」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/beichyes/article/details/

12 模块安装

第一步先根据提示在node_modules中删除对应模块
第二步 安装下列模块

1
2
3
4
5
6
7
8
9
cnpm install -g hexo
npm install hexo-deployer-git --save -g
npm install --save hexo-pdf
npm install --save hexo-generator-topindex
cnpm install hexo-generator-topindex --save
npm i object-assign
npm install --save hexo-deployer-git
cnpm install --save hexo-pdf
npm install hexo-abbrlink --save

13 文章内图片自动上传至github图床

在GitHub内settings里developer settings里面的personal access tokens里面的tokens(classic)里generate new token,设置名称,自动产生token

1
2
3
目前的token:img: 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
(至2025年1月1日,有效期:365 days,每次使用前请检查邮箱)
https://cdn.jsdelivr.net/gh/cz6900/img
谢谢你们对我的支持!

欢迎关注我的其它发布渠道