0%

LF和CRLF其实都是换行符。

LF是linux和Unix系统的换行符,CRLF是window系统的换行符。

Git提供了换行符自动转换的功能,默认开启,自动把代码里换行的方式转换成当前系统的换行方式。提交代码时,Git就会提示 LF will be replaced by CRLF in。

1
2
git config core.autocrlf false
git config --global core.autocrlf false

查看全局配置

1
2
3
git config --global --list
git config --global user.name "yourname"
git config --global user.email "email@email.com"

生成密钥

1
2
3
ssh-keygen -t rsa -C "email@email.com"

>> cat /c/Users/Alan/.ssh/id_rsa.pub

配置github授权

GitHub—>setting—>SSH and GPG keys—>SSH keys

测试是否生效

1
ssh -T git@github.com

设置代理

1
2
3
git config --global http.proxy socks://127.0.0.1:10808
git config --global http.proxy http://127.0.0.1:10809
git config --global http.proxy https://127.0.0.1:10808

取消代理

1
git config --global --unset http.proxy

安装git

1
2
sudo apt-get install git
git --version

修改更新url的代码

node_modules/hexo-asset-image/index.js

1
2
3
4
5
6
if(srcArray.length > 1)
srcArray.shift();
src = srcArray.join('/');

$(this).attr('src', "/img/" + src);
console.info&&console.info("update link as:-->"+"/img/" + src);

nodejs 版本

需要考虑主题支持的版本范围,最好应大于10 小于 15,推荐使用12

参考官方文档 安装前提

安装hexo

1
2
3
npm install -g hexo-cli
npm install -g hexo
环境变量配置 全局安装的目录

启动一个blog项目

1
2
3
4
5
6
7
8
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo new "postName"
hexo new page "pageName"
hexo generate
hexo server

主题配置

菜单项配置

新增页面

source 目录下新建 tags、categories、about文件夹

1
2
3
hexo new page "tags"
hexo new page "categories"
hexo new page "about"

博文的头部

1
2
3
4
5
6
7
8
9
10
11
12
---
title: Hello World
date: 2022/3/26 00:00:00
categories:
- Java
tags: # 标签
- Web
- Server
---

摘要
正文

修改主题配置文件

theme/next/_config.yml

1
2
3
4
5
6
7
8
9
menu:
home: / || fa fa-home
tags: /tags/ || fa fa-tags
categories: /categories/ || fa fa-th
archives: /archives/ || fa fa-archive
about: /about/ || fa fa-user
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat

定制页面

Hexo的scripts目录下新增customcategory.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var pagination = require('hexo-pagination');

const filteredCategory = '分析';

hexo.extend.generator.register('customcategory', function(locals){
var analysisPosts = locals.posts.filter(function(x) {
return x.categories.data[0].name == filteredCategory;
});

return pagination('analysis', analysisPosts, {
perPage: 10,
layout: ['customcategory']
});
});

参考 hexo-pagination 的使用方式

定制模板

theme/next/layout 下新增 customcategory.swig

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
31
32
33
34
35
36
{% extends '_layout.swig' %}
{% import '_macro/post-collapse.swig' as post_template with context %}
{% import '_macro/sidebar.swig' as sidebar_template with context %}

{% block title %}{{ __('title.category') }}: {{ page.category }} | {{ title }}{% endblock %}

{% block class %}category{% endblock %}

{% block content %}

{######################}
{### CATEGORY BLOCK ###}
{######################}
<div class="post-block">
<div class="posts-collapse">
<div class="collection-title">
<h2 class="collection-header">
{{- page.category }}
<small>{{ __('title.category') }}</small>
</h2>
</div>

{{ post_template.render(page.posts) }}
</div>
</div>
{##########################}
{### END CATEGORY BLOCK ###}
{##########################}

{% include '_partials/pagination.swig' %}

{% endblock %}

{% block sidebar %}
{{ sidebar_template.render(false) }}
{% endblock %}

hexo常用命令

1
2
3
4
5
6
hexo init
hexo clean
hexo generate
hexo server
hexo deploy
(新版本支持首字母缩写命令,如 hexo g -> hexo generate)

hexo常用插件

插件地址: https://hexo.io/plugins/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"hexo": "^5.4.2",
"hexo-cake-moon-menu": "^2.5.0",
"hexo-abbrlink": "^2.2.1",
"hexo-asset-image": "^1.0.0",
"hexo-auto-category": "^0.2.1",
"hexo-calendar": "^1.0.6",
"hexo-cli": "^4.3.0",
"hexo-deployer-git": "^0.3.1",
"hexo-generator-archive": "^0.1.5",
"hexo-generator-baidu-sitemap": "^0.1.9",
"hexo-generator-category": "^0.1.3",
"hexo-generator-index": "^0.2.1",
"hexo-generator-search": "^2.4.3",
"hexo-generator-searchdb": "^1.4.1",
"hexo-generator-sitemap": "^3.0.1",
"hexo-generator-tag": "^0.2.0",
"hexo-renderer-ejs": "^0.3.1",
"hexo-renderer-marked": "^0.3.2",
"hexo-renderer-stylus": "^0.3.3",
"hexo-renderer-swig": "^2.0.0",
"hexo-server": "^0.3.3",
"hexo-theme-next": "^8.14.0",
"hexo-word-counter": "^0.1.0"

hexo note用法

https://hexo.io/zh-cn/docs/tag-plugins

配置部分

theme/next/_config.yml

1
2
3
4
5
6
7
8
9
10
11
12
note:
# Note tag style values:
# - simple bs-callout old alert style. Default.
# - modern bs-callout new (v2-v3) alert style.
# - flat flat callout style with background, like on Mozilla or StackOverflow.
# - disabled disable all CSS styles import of note tag.
style: simple
icons: true #false时PC端不显示图标,但移动端仍会显示,故需要在标签语句中手动no-icon进行标注
border_radius: 3
# Offset lighter of background in % for modern and flat styles (modern: -12 | 12; flat: -18 | 6).
# Offset also applied to label tag variables. This option can work with disabled note tag.
light_bg_offset: 0

执行模板

1
2
3
4
5
6
7
note.js
{% note [class] [no-icon] %}
Any content (support inline tags too.io).
{% endnote %}
[class] : default | primary | success | info | warning | danger.
[no-icon] : Disable icon in note.
All parameters are optional.

example

1
2
3
4
{% note default %}
#### Default Header
Welcome to [Hexo!](https://hexo.io)
{% endnote %}

hexo tabs用法

配置部分

theme/next/_config.yml

1
2
3
4
5
6
7
next/_config.yml
tabs:
enable: true
transition:
tabs: false
labels: true
border_radius: 0

执行模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{% tabs Unique name, [index] %}
<!-- tab [Tab caption] [@icon] -->
Any content (support inline tags too).
<!-- endtab -->
{% endtabs %}

Unique name : Unique name of tabs block tag without comma.
Will be used in #id's as prefix for each tab with their index numbers.
If there are whitespaces in name, for generate #id all whitespaces will replaced by dashes.
Only for current url of post/page must be unique!
[index] : Index number of active tab.
If not specified, first tab (1) will be selected.
If index is -1, no tab will be selected. It's will be something like spoiler.
Optional parameter.
[Tab caption] : Caption of current tab.
If not caption specified, unique name with tab index suffix will be used as caption of tab.
If not caption specified, but specified icon, caption will empty.
Optional parameter.
[@icon] : FontAwesome icon name (without 'fa-' at the begining).
Can be specified with or without space; e.g. 'Tab caption @icon' similar to 'Tab caption@icon'.
Optional parameter.

example

1
2
3
4
5
6
7
8
9
10
11
{% tabs First unique name %}
<!-- tab -->
**This is Tab 1.**
<!-- endtab -->
<!-- tab -->
**This is Tab 2.**
<!-- endtab -->
<!-- tab -->
**This is Tab 3.**
<!-- endtab -->
{% endtabs %}

hexo pdf用法

配置部分

theme/next/_config.yml

1
2
3
4
5
next/_config.yml
pdf:
enable: true
# Default height
height: 500px

执行模板

1
2
3
4
pdf.js
{% pdf url [height] %}
[url] : Relative path to PDF file.
[height] : Optional. Height of the PDF display element, e.g. 800px.

example

1
{% pdf https://example.com/sample.pdf %}

hexo video用法

执行模板

1
2
video.js
{% video url %}

example

1
2
{% video /path/to/your/video.mp4 %}
{% video https://example.com/sample.mp4 %}

hexo Group-pictures用法

执行模板

1
2
3
4
5
group-pictures.js
{% grouppicture [group]-[layout] %}{% endgrouppicture %}
{% gp [group]-[layout] %}{% endgp %}
[group] : Total number of pictures to add in the group.
[layout] : Default picture under the group to show.

example

1
2
3
4
{% grouppicture 7-5%}
![](https://suncos-01-1254144885.cos.ap-shanghai.myqcloud.com/%E6%89%8B%E6%9C%BA/IMG_20160720_192243_AO_HDR.jpg)
![](https://suncos-01-1254144885.cos.ap-shanghai.myqcloud.com/%E6%89%8B%E6%9C%BA/IMG_20160817_185254_AO_HDR.jpg)
{% endgrouppicture %}

hexo 写作模板

https://www.bas369.com/more/learning_notes/2020/03/14/Markdown%E5%86%99%E4%BD%9C%E6%A8%A1%E6%9D%BF/

hexo 资源文件夹

https://hexo.io/zh-cn/docs/asset-folders.html

github svg corner

https://tholman.com/github-corners/

githubPage访问地址问题

repository名称需要与githubPage名称保持一致
域名在github repository setting中配置,每次上传被覆盖
需要配置cname文件

GithubPage

cname 重定向

hexo 站点配置文件 _config.yml中设置url为域名
githubPage 重定向机制 source目录新建CNAME文件,添加域名地址
如果你的 CNAME 文件为 example.com,那么 www.example.com 会定向到 example.com。
如果你的 CNAME 文件为 www.example.com,那么 example.com 会定向到 www.example.com

阿里DNS配置

hexo配置文件说明

https://hexo.io/zh-cn/docs/configuration

hexo 语言

站点配置文件 language: zh-Hans // 这里设置语言 简体中文
对应主题语言目录中的 文件名 需要保持一致

hexo 问题处理

https://hexo.io/docs/troubleshooting.html

访问页面直接显示未经过渲染的模板

hexo在5.0版本以上移除了swig

1
npm i hexo-renderer-swig --save

参考

https://blog.eson.org/categories/

1
2
3
4
5
6
git clone https://github.com/theme-next/hexo-theme-next themes/next

git clone --branch v6.0.0 https://github.com/theme-next/hexo-theme-next themes/next

curl -s https://api.github.com/repos/theme-next/hexo-theme-next/releases/latest | grep tarball_url | cut -d '"' -f 4 | wget -i - -O- | tar -zx -C themes/next --strip-components=1

配置主题

hexo _config.yml

1
theme: next

npm ERR! Refusing to delete

删除node_modules,重新执行npm install

SyntaxError: Unexpected token

版本问题,找到匹配的版本

node 与 npm 版本不匹配

https://nodejs.org/zh-cn/download/releases/

下载包超时问题

1
npm config set registry https://registry.npm.taobao.org

npm ERR! notsup Unsupported platform for fsevents@1.0.14: wanted {“os”:“darwin”,“arch”:“any”}

1
2
方法一 npm install-g npm@3.10.7 (更高版本会强制在window下安装fsevent,而fsevent只会在mac系统上可用)
方法二 删除pafsevent依赖

安装命令

1
npm install -g hexo@版本号

更新版本

1
2
3
npm cache clean -f
npm install-g n
n stable

npm-check-updates安装

1
npm install -g npm-check-updates

检查包

1
2
npm install -g npm-check
npm-check

更新包

npm update

检查 package.json 的最新依赖项

1
2
3
4
npm install -g npm-upgrade
npm-upgrade

ncu

更新 package.json 的最新依赖项

1
ncu -u

检查包是否最新

1
ncu <package>

更新包到最新

1
2
3
npm update <name> -g

ncu -u <package>

查看全局安装包最新版本

1
ncu -g

nvm配置修改

修改nvm的安装目录settings

1
2
node_mirror: npm.taobao.org/mirrors/node/
npm_mirror: npm.taobao.org/mirrors/npm/

常用命令

1
2
3
4
5
6
7
8
9
nvm                  // 提示相关命令
nvm ls // 查看已安装node版本
nvm install XX // 安装XX版本的node
nvm uninstall XX // 卸载XX版本的node
nvm use XX // 切换到XX版本
nvm current // 显示当前版本
nvm ls available // 查看运程线上所有版本
nvm root // 查看nvm安装路径
nvm proxy // 查看设置与代理

常见问题

nvm use 切换环境无效

  • 切换到管理员权限
  • node 在nvm之前安装,切换无效,需要卸载后使用nvm安装(npm ls -g –depth=0)