Hexo 博客搭建与写作完全指南:从零开始的实战教程
📝 Hexo 博客搭建与写作完全指南:从零开始的实战教程
💡 想拥有自己的技术博客吗?
- 如何从零搭建一个免费的技术博客?
- 如何高效地编写和管理 Markdown 文章?
- 如何实现一键部署到 GitHub Pages?
- 如何在博客中插入图片?
完全教程!手把手教你搭建 Hexo 博客,开始你的技术写作之旅!
- 1:使用 vscode 打开 xinzhuzi.github.io
- 2:终端打开, ```
cd xinzhuzi.github.io1
2- 3:开始写文章,```
hexo new 文章名字 - 4:写完之后输入```
hexo clean
hexo gnpm install hexo-asset-image –save1
2
3
4
5
6
7
8
9
10
11
12
13
14- 5:使用 Github Desktop 上传到 GitHub 网站
仓库地址
- [https://github.com/xinzhuzi/xinzhuzi.github.io](https://github.com/xinzhuzi/xinzhuzi.github.io)
[https://github.com/xinzhuzi/Record](https://github.com/xinzhuzi/Record) hexo 项目地址搭建博客
- [https://www.jianshu.com/p/83b3b7d4e649](https://www.jianshu.com/p/83b3b7d4e649)
主题
- [https://github.com/xinzhuzi/hexo-theme-3-hexo](https://github.com/xinzhuzi/hexo-theme-3-hexo)
HEXO插入图片(详细版)[https://www.jianshu.com/p/f72aaad7b852](https://www.jianshu.com/p/f72aaad7b852)
- 第一步:安装插件,在hexo根目录打开Git Bash,执行1
2
3
4
5
6
7第二步:打开hexo的配置文件_config.yml
找到 post_asset_folder,把这个选项从false改成true
第三步:打开
/node_modules/hexo-asset-image/index.js
将内容更换为下面的代码
(在此感谢Ericam_ 大神:[https://blog.csdn.net/xjm850552586)](https://blog.csdn.net/xjm850552586))'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; else var 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(); } } });
1 | 第四步:现在就可以插入图片了,比如hexo new post photo之后 |

参考链接:
[https://blog.csdn.net/xjm850552586/article/details/84101345](https://blog.csdn.net/xjm850552586/article/details/84101345)
[https://blog.csdn.net/qq_38148394/article/details/79997971](https://blog.csdn.net/qq_38148394/article/details/79997971)
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 1487842110@qq.com
本文是原创文章,采用CC BY-NC-SA 4.0协议,完整转载请注明来自新诸子
