zoukankan      html  css  js  c++  java
  • Hexo+Next搭建Github个人静态博客

    经过我几天的努力,用hexo搭建的博客终于好了。欢迎莅临

    废话不多说。

    环境配置

    • Node.js(必须) 一路默认安装即可。
    • 安装Git(必须) 一路默认安装即可。
    • Github账号(必须)

    安装Hexo

    nodejs和git安装完成后,打开’git bash’安装hexo

    npm install -g hexo-cli

    Start

    新建一个文件夹(如E:Hexo),在此文件夹中执行命令

    1 hexo init
    2 npm install

    本地查看

    1 hexo server //hexo s

    后在浏览器中输入 http://localhost:4000/

    此时,会有一篇文章hello world,对应的文件为 E:Hexosource_postshello-world.md
    文章用markdown语法写.

    新建文章

    1 hexo new "New article"

    会新建一个名为’New article’的文章,执行以下命令之后查看。

    hexo generate   //生成静态网页以及css js文件 存放于public文件夹中
    hexo server

    至此,本地博客搭建完毕。下一步移植到Github

    Github

    新建repository,项目名必须是:name.github.io(name是你的账号名)。
    我的账号名是cnfanhua,新建的项目名也就是cnfanhua.github.io

    部署

    在你的hexo文件夹中有个重要的文件_config.yml,打开编辑,把’cnfanhua’换成你的账号名

    1 deploy:
    2   type: git
    3   repository: https://github.com/cnfanhua/cnfanhua.github.io.git
    4   branch: master

    执行下列命令后部署(部署前,需要配置SSh,否则失败)。

    1 hexo generate
    2 hexo deploy  //上传至github 代替 git push...

    至此,个人博客搭建完成。
    注意:每次修改后 需要 hexo g 命令保存 然后hexo d 命令上传

    外配置SSh

    打开git bash

    • 设置username和email
    • 1 git config --global user.name "test"
      2 git config --global user.email "test@gmail.com"
    • 生成秘钥
    • ssh-keygen -t rsa -C "test@gmail.com"
    • 最后得到id_rsa和id_rsa.pub两个文件,把id_rsa.pub的内容粘贴到github中即可

    NexT主题

    下载

    gitHub,clone到你的博客目录 hemes目录下(E:Hexo hemes下)

    git clone git@github.com:iissnan/hexo-theme-next.git

    使用

    打开站点总配置_config.yml(即E:Hexo下的_config.yml),找到theme换成next即可(theme: next),记得每一个冒号后面要有一个空格

    NexT-配置

    插件安装

    npm install <插件名>

    卸载插件

    npm uninstall <插件名>

    多说评论

    使用多说前需要先在 多说 创建一个站点。具体步骤如下:

      • 登录后在首页选择 “我要安装”。
      • 创建站点,填写表单。多说域名 这一栏填写的即是你的 duoshuo_shortname
        主题配置文件 中设置:

          # 多说热评文章 true 或者 false
          duoshuo_shortname: '多说域名'

    Google 分析

    登陆google分析网站获取ID
    编辑 站点配置文件,新增字段 google_analytics,值设置成你的 Google 跟踪 ID。

    google_analytics: UA-XXX...

    社交链接,将在侧栏中显示

    将以下代码放到站点配置文件

    1 social:
    2   GitHub: your-github-url
    3   Twitter: your-twitter-url
    4   Weibo: your-weibo-url
    5   DouBan: your-douban-url
    6   ZhiHu: your-zhihu-url
    7   # 等等

    文章目录

    主题配置文件 中设置:

    1 sidebar: post   #自动展示有目录的文章的目录
    2 #sidebar: always    #总是展示
    3 #sidebar: hide      #隐藏

    添加云标签

    hexo new page "tags"        //新增tags页面

      编辑刚才的页面(pathsource agsindex.md)

    1 ---
    2 title: TagCloud
    3 date: 2016-01-21 16:12:58
    4 type: "tags"
    5 comments: false     //关闭评论
    6 ---

      编辑主题配置文件,添加 tags 到 menu 中

    1 menu:
    2   home: /
    3   archives: /archives
    4   tags: /tags

    添加high一下

    在 Hexo hemes extlayout_partialsheader.swig 中的 ul 标签加入如下 li 代码:

      1 <li> <a title="把这个链接拖到你的Chrome收藏夹工具栏中" href='javascript:(function() {
      2     function c() {
      3         var e = document.createElement("link");
      4         e.setAttribute("type", "text/css");
      5         e.setAttribute("rel", "stylesheet");
      6         e.setAttribute("href", f);
      7         e.setAttribute("class", l);
      8         document.body.appendChild(e)
      9     }
     10  
     11     function h() {
     12         var e = document.getElementsByClassName(l);
     13         for (var t = 0; t < e.length; t++) {
     14             document.body.removeChild(e[t])
     15         }
     16     }
     17  
     18     function p() {
     19         var e = document.createElement("div");
     20         e.setAttribute("class", a);
     21         document.body.appendChild(e);
     22         setTimeout(function() {
     23             document.body.removeChild(e)
     24         }, 100)
     25     }
     26  
     27     function d(e) {
     28         return {
     29             height : e.offsetHeight,
     30             width : e.offsetWidth
     31         }
     32     }
     33  
     34     function v(i) {
     35         var s = d(i);
     36         return s.height > e && s.height < n && s.width > t && s.width < r
     37     }
     38  
     39     function m(e) {
     40         var t = e;
     41         var n = 0;
     42         while (!!t) {
     43             n += t.offsetTop;
     44             t = t.offsetParent
     45         }
     46         return n
     47     }
     48  
     49     function g() {
     50         var e = document.documentElement;
     51         if (!!window.innerWidth) {
     52             return window.innerHeight
     53         } else if (e && !isNaN(e.clientHeight)) {
     54             return e.clientHeight
     55         }
     56         return 0
     57     }
     58  
     59     function y() {
     60         if (window.pageYOffset) {
     61             return window.pageYOffset
     62         }
     63         return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
     64     }
     65  
     66     function E(e) {
     67         var t = m(e);
     68         return t >= w && t <= b + w
     69     }
     70  
     71     function S() {
     72         var e = document.createElement("audio");
     73         e.setAttribute("class", l);
     74         e.src = i;
     75         e.loop = false;
     76         e.addEventListener("canplay", function() {
     77             setTimeout(function() {
     78                 x(k)
     79             }, 500);
     80             setTimeout(function() {
     81                 N();
     82                 p();
     83                 for (var e = 0; e < O.length; e++) {
     84                     T(O[e])
     85                 }
     86             }, 15500)
     87         }, true);
     88         e.addEventListener("ended", function() {
     89             N();
     90             h()
     91         }, true);
     92         e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
     93         document.body.appendChild(e);
     94         e.play()
     95     }
     96  
     97     function x(e) {
     98         e.className += " " + s + " " + o
     99     }
    100  
    101     function T(e) {
    102         e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
    103     }
    104  
    105     function N() {
    106         var e = document.getElementsByClassName(s);
    107         var t = new RegExp("\b" + s + "\b");
    108         for (var n = 0; n < e.length; ) {
    109             e[n].className = e[n].className.replace(t, "")
    110         }
    111     }
    112  
    113     var e = 30;
    114     var t = 30;
    115     var n = 350;
    116     var r = 350;
    117     var i = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3";
    118     var s = "mw-harlem_shake_me";
    119     var o = "im_first";
    120     var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
    121     var a = "mw-strobe_light";
    122     var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
    123     var l = "mw_added_css";
    124     var b = g();
    125     var w = y();
    126     var C = document.getElementsByTagName("*");
    127     var k = null;
    128     for (var L = 0; L < C.length; L++) {
    129         var A = C[L];
    130         if (v(A)) {
    131             if (E(A)) {
    132                 k = A;
    133                 break
    134             }
    135         }
    136     }
    137     if (A === null) {
    138         console.warn("Could not find a node of the right size. Please try a different page.");
    139         return
    140     }
    141     c();
    142     S();
    143     var O = [];
    144     for (var L = 0; L < C.length; L++) {
    145         var A = C[L];
    146         if (v(A)) {
    147             O.push(A)
    148         }
    149     }
    150 })()    '>High一下</a> </li>
    View Code

    开启RSS功能

    安装插件

    npm install hexo-generator-feed --save

    后编辑主题配置文件_config.yml,添加如下代码

    rss: /atom.xml #rss地址  默认即可

    报错

    找不到git部署 ERROR Deployer not found: git

    解决办法

    npm install hexo-deployer-git --save

    部署类型设置git

    hexo 3.0 部署类型不再是github,而是git,修改主题配置文件_config.yml中deploy中的type为git

    1 deploy:
    2   type: git
    3   repository: git@cnfanhua.github.com:cnfanhua/cnfanhua.github.io.git
    4   branch: master

    参考

    1.hexo
    2.创建GitHub技术博客全攻略
    3.搭建一个免费的,无限流量的Blog—-github Pages和Jekyll入门
    4.HEXO+Github,搭建属于自己的博客
    5.Hexo搭建Github静态博客
    6.hexo系列教程:(三)hexo博客的配置、使用
    7.hexo系列教程:(二)搭建hexo博客
    8.NexT
    9.廖雪峰Git教程

  • 相关阅读:
    echarts官网上的动态加载数据bug被我解决。咳咳/。
    jquery中的jsonp和js中的jsonp还有配合php实现的jsonp。
    jquery中的done和always解决ajax问题
    vue2.0使用watch监听对象属性
    gulp配合vue压缩代码格式化
    支持flv的播放神器
    前端组件化-Web Components【转】
    自定义异步加载资源插件
    【leetcode刷题笔记】Two Sum
    【leetcode刷题笔记】Longest Common Prefix
  • 原文地址:https://www.cnblogs.com/cnfanhua/p/5167191.html
Copyright © 2011-2022 走看看