自己建個網(wǎng)站,從此沒有鎖文

行者說幣網(wǎng)站

為什么要自建博客?

現(xiàn)有的博客平臺,常見的有CSDN、博客園、掘金等,已經(jīng)給我們提供了便利的書寫平臺和學習社區(qū),然而,畢竟不是自己親生的,域名好大一串,也不方便定制化,文章審核不過等等問題。

因此,自己親建一個博客,更加自由,WordPress和Django也可以簡單的完成建站,然而,需要一個服務器,而GItGub Page提供了一個免費的服務器,極大減少開銷,無需維護,以便我們將精力更多集中在內容上。

配置GitHub

注冊GitHub賬號

注冊成功顯示如下界面

安裝Git版本管理工具

配置git

git config --global user.name "shijitech"
git config --global user.email xypip@qq.com

創(chuàng)建ssh key

ssh-keygen -t rsa -C xypip@qq.com

復制id_rsa.pb

pbcopy < ~/.ssh/id_rsa.pub

進入GitHub的SSH keys

檢測是否許可成功

ssh -T git@github.com

創(chuàng)建倉庫

倉庫名格式:github名.github.io,這就是我們的網(wǎng)址,之后也可以綁定自己的域名。

配置Hexo

Hexo的作用就是生成我們的靜態(tài)網(wǎng)站源碼,將Hexo源碼上傳到GitHub服務器就可以完成網(wǎng)站的搭建。需要預先安裝好Node.js。

hexo init shijitech
npm install

安裝主題

git clone git@github.com:shijitech/hexo-theme-cafe.git cafe

安裝插件

npm install hexo-server --save
npm install hexo-admin --save
npm install hexo-generator-archive --save
npm install hexo-generator-feed --save
npm install hexo-generator-search --save
npm install hexo-generator-tag --save
npm install hexo-deployer-git --save
npm install hexo-generator-sitemap --save

設置域名

綁定自己的域名,逼光閃閃!

在source目錄下創(chuàng)建CNAME文件

遠程倉庫配置

編輯根目錄下配置文件_config.yml

deploy:
    type: git
    repo: git@github.com:shijitech/shijitech.github.io.git
    branch: master

常用命令

hexo clean
hexo g
hexo d
hexo s
hexo g -d
hexo new "新建文章名稱"
hexo new page about

文章排序

進入文件夾:node_modules/hexo-generator-index/lib
編輯文件:generator.js

添加代碼:

'use strict';

var pagination = require('hexo-pagination');

module.exports = function(locals) {
  var config = this.config;
  var posts = locals.posts.sort(config.index_generator.order_by);

  posts.data = posts.data.sort(function(a, b) {
      if(a.top && b.top) {
          if(a.top == b.top) return b.date - a.date;
          else return b.top - a.top;
      }
      else if(a.top && !b.top) {
          return -1;
      }
      else if(!a.top && b.top) {
          return 1;
      }
      else return b.date - a.date;
  });

  var paginationDir = config.pagination_dir || 'page';

  return pagination('', posts, {
    perPage: config.index_generator.per_page,
    layout: ['index', 'archive'],
    format: paginationDir + '/%d/',
    data: {
      __index: true
    }
  });
};



部署網(wǎng)站到GitHub

hexo g –d

成果一覽

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容