这里基于ubuntu18,win10其实一样的,把sudo去掉就行了
安装
安装git
配置github的ssh
安装Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本
建议换个源
npm install express --registry=https://registry.npm.taobao.org
在github创建一个仓库
xxx.github.io

然后确认完后是这样的

把username.github.io改成在github创建的仓库名
mkdir username.github.io
cd username.github.io
sudo npm install -g hexo-cli
hexo init
npm install
npm install hexo-deployer-git --save
接着
hexo g
hexo s


用这个来生成新的页面
xxx换成文章标题
hexo new 'xxx'
显示主题
以next主题为例
把主题下到themes文件夹里
git clone https://github.com/theme-next/hexo-theme-next themes/next
在_config.yml里
theme:next


显示数学公式
next主题
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save
修改node_modules/kramed/lib/rules/inline.js

修改11行的escape
// escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,escape: /^\\([`*\[\]()#$+\-.!_>])/,
修改20行的em
// em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

修改themes/next/_config.yml
# Math Formulas Render Support
math:# Default (true) will load mathjax / katex script on demand.# That is it only render those page which has `mathjax: true` in Front-matter.# If you set it to false, it will load mathjax / katex srcipt EVERY PAGE.per_page: true# hexo-renderer-pandoc (or hexo-renderer-kramed) required for full MathJax support.mathjax:enable: true# See: https://mhchem.github.io/MathJax-mhchem/mhchem: true

在文章的开头加上
mathjax: true

hexo clean
hexo g
hexo s
注意点:
大括号不要用\left{ \right},要用\lbrace \rbrace
有时候公式没出来,可以多刷新一下
发布github
把这个ssh复制了

在最外面的_config.yml里
修改
deploy:type: gitrepository: git@github.com:username/username.github.io.gitbranch: master

每次要发布到github的时候
hexo g
hexo d
显示图片
npm install hexo-asset-image --save
修改node_modules/hexo-asset-image/index.js为
'use strict';
var cheerio = require('cheerio');// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string
function getPosition(str, m, i) {return str.split(m, i).join(m).length;
}var version = String(hexo.version).split('.');
hexo.extend.filter.register('after_post_render', function(data){var config = hexo.config;if(config.post_asset_folder){var link = data.permalink;if(version.length > 0 && Number(version[0]) == 3)var beginPos = getPosition(link, '/', 1) + 1;elsevar beginPos = getPosition(link, '/', 3) + 1;// In hexo 3.1.1, the permalink of "about" page is like ".../about/index.html".var endPos = link.lastIndexOf('/') + 1;link = link.substring(beginPos, endPos);var toprocess = ['excerpt', 'more', 'content'];for(var i = 0; i < toprocess.length; i++){var key = toprocess[i];var $ = cheerio.load(data[key], {ignoreWhitespace: false,xmlMode: false,lowerCaseTags: false,decodeEntities: false});$('img').each(function(){if ($(this).attr('src')){// For windows style path, we replace '\' to '/'.var src = $(this).attr('src').replace('\\', '/');if(!/http[s]*.*|\/\/.*/.test(src) &&!/^\s*\//.test(src)) {// For "about" page, the first part of "src" can't be removed.// In addition, to support multi-level local directory.var linkArray = link.split('/').filter(function(elem){return elem != '';});var srcArray = src.split('/').filter(function(elem){return elem != '' && elem != '.';});if(srcArray.length > 1)srcArray.shift();src = srcArray.join('/');$(this).attr('src', config.root + link + src);console.info&&console.info("update link as:-->"+config.root + link + src);}}else{console.info&&console.info("no src attr, skipped...");console.info&&console.info($(this));}});data[key] = $.html();}}
});

修改_config.yml
把post_asset_folder改为true

然后比如你要引用图片
博客名字叫test.md,就创建一个目录test,图片放进去
用相对路径引用
千万不要在前面加./,不然github上可能看不到

参考
https://zhuanlan.zhihu.com/p/32957389
https://www.jianshu.com/p/7ab21c7f0674
https://blog.csdn.net/dianling3902/article/details/101267806
https://www.cnblogs.com/iHeling/p/14095986.html
https://blog.eson.org/pub/6aa77778/
https://lanlan2017.github.io/blog/14ee6880/
https://www.jianshu.com/p/f72aaad7b852
















