新建博客-hexo搭建简单博客

hexo是一款快速生成index.html页面的框架

  1. hexo生成博客快捷方便容易上手
  2. 需要依赖node.js npm hexo
  3. 可以选择自己喜欢的主题和样式,主题也可以自己写,but我就比较懒,我的想法是我自己写个自己的网站里面写点博客,因为自己网站写的比较慢所以先用hexo在GitHub和coding上写博客,可能我有点
    除了hexo还有typecho

工具的下载

  1. node.js的下载
    node.js一般我就会官网下载安装-不细说

    node -v

    查看node版本
  2. npm 一般下载安装nodejs就有

    npm -v

    查看下npm是否拥有,如果没有检查环境变量或者重新安装
  3. 安装hexo-cli这是必要的安装在环境中的

    npm install -g hexo-cli 或者 cnpm install -g hexo-cli

  4. 创建本地hexo项目

    hexo init <folder> //这步可能安装失败,或者过长如果看见文件里的package.json出现了可以停止安装
    cd <folder>
    npm install 或者 cnpm install

  5. 如果需要保存本地图片
    先下载

    npm install hexo-asset-image –save

    修改配置

    打开hexo的配置文件_config.yml找到post_asset_folder改为true

    修改node包保证本地能看到/node_modules/hexo-asset-image/index.js
    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    '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();
    }
    }
    });
    会在新建md的时候出现同名文件夹然后可以存放图片
  6. 安装deploy-git能部署到GitHub和coding

    npm install hexo-deployer-git –save

    打开配置文件 _config.yml是更目录下的那个不要弄错了找到deploy
    1
    2
    3
    4
    5
    6
    deploy:
    type: 'git'
    repo:
    coding: git@e.coding.net:<你的coding名字>/<你的coding项目>/<库>.git
    github: https://github.com/<你的GitHub名字>/<你的项目名字>.github.io.git

    因为我是git和coding一起建造博客的所以我的配置设置是这样的如果单独为git或者coding
    1
    2
    3
    4
    deploy:
    type: 'git'
    repo: git@e.coding.net:<你的coding名字>/<你的coding项目>/<库>.git
    <!--https://github.com/<你的GitHub名字>/<你的项目名字>.github.io.git -->
  7. 主题自己去选然后放在themes里面然后修改配置文件 _config.yml的theme为文件名主题下载地址

hexo指示命令

运行hexo于本地http://localhost:4000查看

hexo s 运行全写(hexo server)

新建页面后面为页面名字

hexo new “My New Post”

打包文件(因为hexo是个静态页面生成框架所以都是生成好静态页面进行上传)

hexo g 打包全写(hexo generate)

文件上传同步于的GitHub和coding请参照新建博客-平台进行配置

hexo d 上传全写(hexo deploy)

切记一件事.md的文件是不上传的建议把整个项目git到另外一个库里进行多处电脑备份嗯

×

写着玩做笔记

扫码支持
小编不易来个几毛也是钱

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. hexo是一款快速生成index.html页面的框架
  2. 2. 工具的下载
  3. 3. hexo指示命令
  • 切记一件事.md的文件是不上传的建议把整个项目git到另外一个库里进行多处电脑备份嗯
  • ,