Github搭建个人博客

2020-04-27  本文已影响0人  熙航君

博客成品地址:https://guxiaofeng-dev.github.io/

效果图

初版的博客可能界面有点low,后期还要完善一下内容和样式。

个人github:https://github.com/guxiaofeng-dev

创建github仓库

github仓库

安装Hexo:pm install hexo-cli -g
创建博客文件夹:hexo init guxiaofeng-dev.github.io
在上面文件夹目录下克隆主题:git clone https://github.com/iissnan/hexo-theme-next themes/next
修改username.github.io/_config.yml配置:

 title: dimsky 的 9 维空间    //你博客的名字
 author: dimsky  //你的名字
 language: zh-Hans    //语言 中文
 theme: next   //刚刚安装的主题名称
 deploy:
   type: git    //使用Git 发布
   repo: https://github.com/username/username.github.io.git    // 刚创建的Github仓库

在username.github.io/source/_posts下创建博客文件,添加内容
输入hexo s启动项目,访问https://localhost:4000
安装hexo-deployer-git自动部署发布工具:npm install hexo-deployer-git --save
发布到远程github上:hexo clean && hexo g && hexo d
最后直接访问地址即可:https://guxiaofeng-dev.github.io/

附录:

插入图片

1.首先安装一个图片路径转换的插件
npm install https://github.com/CodeFalling/hexo-asset-image --save

2.修改/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;
    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();
    }
  }
});

3.设置_config.yml文件中的post_asset_folder: true
4.通过{% asset_img example.jpg This is an example image %}引用

插入音乐

npm install hexo-tag-aplayer

{% aplayer "她的睫毛" "周杰伦" "http://home.ustc.edu.cn/~mmmwhy/%d6%dc%bd%dc%c2%d7%20-%20%cb%fd%b5%c4%bd%de%c3%ab.mp3"  "http://home.ustc.edu.cn/~mmmwhy/jay.jpg" "autoplay=false" %}

插入视频

npm install hexo-tag-dplayer

{% dplayer "url=http://home.ustc.edu.cn/~mmmwhy/GEM.mp4"  "pic=http://home.ustc.edu.cn/~mmmwhy/GEM.jpg" "loop=yes" "theme=#FADFA3" "autoplay=false" "token=tokendemo" %}
上一篇下一篇

猜你喜欢

热点阅读