开发者联盟程序员

mac 搭建基于Hexo-Github的Blog

2019-08-14  本文已影响2人  72行代码

博客搭建

  1. 创建 GitHub 仓库
  1. 安装博客需要的框架
  1. 安装博客相关插件
# Extensions
## Plugins: http://hexo.io/plugins/
#RSS订阅
plugin: -hexo-generator-feed
#Feed Atom
feed:
     type: atom
     path: atom.xml
     limit: 20

在主题目录下的_config.yml目录下,添加如下配置
rss: /atom.xml

  1. 创建博客、调试、发布
# Site
title: 博客的名字
subtitle: 博客副标题
description: 博客描述
author: 博客作者
language: zh-Hans
theme: next //安装的主题名称
deploy:
  type: git  //使用Git 发布
  repo: https://github.com/yourusername/yourusername.github.com.git  //自己的Github仓库地址
  branch: master
$ sudo hexo g
$ sudo hexo d
  1. 配置博客分类内容
hexo new page about
INFO  Created: ~/blog/source/about/index.md
// 打开修改为如下
---
title: about
date: 2016-09-17 13:21:20
tags: 代码库        // 标签
comment: false   // 添加这行关闭评论
---
here is something about me
  1. 自定义博客
$ hexo g
$ hexo d

执行完毕以后,就可以在本地或者git上看到博客的新主题了,更多的主题可以参考知乎

# 脚本
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

# 标签
# pv的方式,单个用户连续点击n篇文章,记录n次访问量
<span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
# uv的方式,单个用户连续点击n篇文章,只记录1次访客数
<span id="busuanzi_container_site_uv">
    总访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<section class="livere" id="comments">
    <!-- 来必力City版安装代码 -->
    <div id="lv-container" data-id="city" data-uid="MTAyM***注册成功官方返回的uid****xNzkwMw==">
      <script type="text/javascript">
       (function(d, s) {
           var j, e = d.getElementsByTagName(s)[0];

           if (typeof LivereTower === 'function') { return; }

           j = d.createElement(s);
           j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
           j.async = true;

           e.parentNode.insertBefore(j, e);
       })(document, 'script');
      </script>
    <noscript> 为正常使用来必力评论功能请激活JavaScript</noscript>
    </div>
    <!-- City版安装代码已完成 -->
</section>

\themes\random\layout\post.ejs文件中添加或修改如下代码
<% if (page.comment || theme.page_comment) { %>
  <%- partial('_partial/livere',{}) %>
<% } %>
<script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
<link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
  <style>
      .pace .pace-progress {
          background: #1E92FB; /*进度条颜色*/
          height: 3px;
      }
      .pace .pace-progress-inner {
           box-shadow: 0 0 10px #1E92FB, 0 0 5px     #1E92FB; /*阴影颜色*/
      }
      .pace .pace-activity {
          border-top-color: #1E92FB;    /*上边框颜色*/
          border-left-color: #1E92FB;    /*左边框颜色*/
      }
  </style>
添加在head里面
# 标签
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
# 脚本
<script>
    var now = new Date(); 
    function createtime() { 
        var grt= new Date("07/08/2018 12:00:00");//此处修改你的建站时间或者网站上线时间 
        now.setTime(now.getTime()+250); 
        days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days); 
        hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours); 
        if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum); 
        mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;} 
        seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum); 
        snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;} 
        document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 "; 
        document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒"; 
    } 
    setInterval("createtime()",250);
</script>
<div>
    <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
</div>  
live2d:
  enable: true
  scriptFrom: local
  pluginRootPath: live2dw/
  pluginJsPath: lib/
  pluginModelPath: assets/
  tagMode: false
  debug: false
  model:
    use: live2d-widget-model-shizuku
  display:
    position: right
    width: 150
    height: 300
  mobile:
    show: true

然后下载模型,模型名称可以到这里参考,一些模型的预览可以在这里
$ npm install live2d-widget-model-shizuku
下载完之后,在Blog根目录中新建文件夹live2d_models,然后在node_modules文件夹中找到刚刚下载的live2d模型,将其复制到live2d_models中,然后编辑配置文件中的model.use项,将其修改为live2d_models文件夹中的模型文件夹名称
一切就绪之后,用hexo server命令启动服务器,稍等一下就可以看到右下角出现了一个可爱的萌萌哒的妹纸!不过因为所有东西都在Github上托管的原因,可能Live2D不能马上加载出来

$ hexo clean      #清理缓存
$ hexo generate   #生成静态文件
$ hexo server     #启动本地服务器
$ hexo deploy    #部署
或者
$ hexo clean      #清理缓存
$ hexo g          #生成静态文件
$ hexo s          #启动本地服务器
$ hexo d         #部署
// 安装 homebrew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
// 卸载 homebrew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
// 查看版本
$ brew -v
// 下载软件:brew install 软件名
如:$ brew install htop, 安装htop
// 如需要图形安装的软件 要加cask
如:$ brew cask install google-chrome
// 卸载软件:brew uninstall 软件名
如: $ brew cask uninstall google-chrome
// 软件搜索:brew search 软件名
如: $ brew search google
// 列出已安装的包
$ brew list
// 查看软件相关信息:brew info 软件名
如:$ brew info google-chrome
// 删除 Homebrew下载的包
$ brew cleanup
// 更新 Homebrew
$ brew update
  1. 验证站点
    搜索引擎验证的方法有好几种,下面选择 HTML标签验证 验证方法,其他的方法有兴趣可以自己去试一下
  1. 生成站点地图
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
url: http://jonzzs.cn # 修改成你博客的首页地址
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
# 自动生成sitemap
sitemap: 
  path: sitemap.xml
baidusitemap: 
  path: baidusitemap.xml
  1. 将站点地图提交谷歌
baidu_url_submit:
  count: 3 ## 提交最新的3个链接
  host: www.hui-wang.info ## 在百度站长平台中注册的域名
  token: your_token ## 请注意这是您的秘钥, 所以请不要把博客源代码发布在公众仓库里!
  path: baidu_urls.txt ## 文本文档的地址, 新链接会保存在此文本文档里

其次,记得查看_config.ym文件中url的值, 必须包含是百度站长平台注册的域名,比如:

# URL
url: http://www.hui-wang.info
root: /
permalink: :year/:month/:day/:title/

最后,加入新的deployer:

deploy:
- type: git ## 这是原来的deployer
  repo: https://github.com/yourusername/yourusername.github.com.git  //自己的Github仓库地址
  branch: master
- type: baidu_url_submitter ## 这是新加的

执行hexo deploy的时候,新的连接就会被推送了

<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
  1. site:域名测试是否成功

附:我的博客地址

上一篇 下一篇

猜你喜欢

热点阅读