2018-02-06

搭建hexo和github遇到问题

学习一样新事物,总是要经历磕磕碰碰,才能有所成长!脚踏实地,一步一个脚印,走好每一步,不要给自己留遗憾!


安装hexo问题

安装hexo我是在网上找教程安装的:
1.安装node.js(去官网下载windows版的安装包) node.js官网
2.安装git git下载地址
3.申请github账号 github 这里自己注册
设置user.name user.email

$ git config --global user.name "你的GitHub用户名"
$ git config --global user.email "你的GitHub注册邮箱"

4.生成ssh密匙
输入

$ ssh-keygen -t rsa -C "你的GitHub注册邮箱"

一路回车就OK了!
此时,在用户文件夹下就会有一个新的文件夹.ssh,里面有刚刚创建的ssh密钥文件id_rsa和id_rsa.pub。
上传公匙添加到github上
记住是id_rsa.pub内容复制到github上

5.安装hexo

$ npm install hexo-cli g
# 建立一个文件夹hexo
$ mkdir hexo 
# 初始化hexo文件夹
$ hexo init hexo
# 安装hexo插件(都安装吧!)
$ 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
$ npm install hexo-generator-category --save

6.本地使用hexo

# 生成静态页面
$ hexo generate
# 开启本地服务器(可以使用全名 hexo server)
$ hexo s 

在浏览器输入 http://localhost:4000/ 就可以在本地访问blog
7.hexo部署到github上

先在github上创建一个仓库 名字: github用户名.github.io
这个创库的命名规则不能弄错了!!!!!!

修改博客配置文件(hexo/_config.yml),在文件里找到下面内容并修改

# Deployment 注释
## Docs: https://hexo.io/docs/deployment.html
deploy:
  # 类型
  type: git
  # 仓库
  repo: git@github.com:用户名/用户名.github.io.git
  # 分支
  branch: master

记得一定要修改成自己的用户名!!!! 这种方式使用ssh链接(前提是你添加了公钥到github)
还有一种方式是把repo 修改为下面

 repo: https://github.com/用户名/用户名.github.io

由于我用得两个github账号,建立hexo博客是换了一个新的账号 使用这种方式总是报 403 错误 我是改用ssh链接github

输入下面的命令将hexo博客部署到github中:

# 清空静态页面
hexo clean
# 生成静态页面
hexo generate
# 部署 
hexo deploy

这里有一点建议:发布时最好连续执行这三个命令,以免部署到github的hexo为以前的,就相当于刷新一下缓存。


hexo替换主题

我使用的next主题
1.打开git bash 并切换到你的博客目录下 比如我的博客目录是 /hexo

#自己切换自己的博客目录
$ cd hexo
# 执行下面命令
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

2.修改博客配置文件 /hexo/_config.yml 如下:

# Extensions
## Plugins: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/
#以前的选项为     theme: landscape
theme: next

3.修改主题配置文件 /hexo/themes/next/_config.yml

menu修改

找到下面内容

# ---------------------------------------------------------------
# Menu Settings
# ---------------------------------------------------------------
menu:
  home: / || home
  #about: /about/ || user
  tags: /tags/ || tags
  #categories: /categories/ || th
  #archives: /archives/ || archive
  #schedule: /schedule/ || calendar
  #sitemap: /sitemap.xml || sitemap
  #commonweal: /404/ || heartbeat

去掉 # 就可以多一个菜单栏 比如去掉

menu:
  home: / || home
  #about: /about/ || user
  tags: /tags/ || tags
  categories: /categories/ || th
  #archives: /archives/ || archive
  #schedule: /schedule/ || calendar
  #sitemap: /sitemap.xml || sitemap
  #commonweal: /404/ || heartbeat

虽然在首页能看见这个菜单,但是是不能使用
点击菜单 categories 会返回 can't get /categories/ 错误信息
首先要安装categories对应插件

$ npm install hexo-generator-category --save

再在gitbash输入(hexo目录下)

$ hexo new page categories

在/hexo/source 目录下发现多的一个categories文件夹 进入 编辑 index.md

---
title: categories
date: 2018-1-22 12:39:04
type: "categories"
comments: false
---

在/hexo/source/_post 目录建立 test.md 内容如下

---
title: test
categories:
  - Testing
---

注意空格!!!!注意空格!!!!注意空格!!!!注意空格!!!!


赞赏功能问题

在添加赞赏功能是替换了图片不能出现赞赏功能
next赞赏功能启用
在主题配置文件 找到如下内容 并修改如下:

# Reward
reward_comment: Donate
wechatpay: /images/wechatpay.png
alipay: /images/alipay.jpg
#bitcoin: /images/bitcoin.png

自己图片位置在 Hexo/themes/next/source image文件内
修改成这样过后但是还是不能显示赞赏功能。至少我是这样,经过百度终于解决了。在 主题配置文件查找

# Automatically Excerpt. Not recommend.
# Please use <!-- more --> in the post to control excerpt accurately.
auto_excerpt:
  enable: false
  length: 150

修改如下:

# Automatically Excerpt. Not recommend.
# Please use <!-- more --> in the post to control excerpt accurately.
auto_excerpt:
  enable: true
  length: 150

在执行

$ hexo clean && hexo generate &&  hexo s 

这下应该可以!


本地搜索配置

1.hexo配置文件(/hexo/_config.yml)添加

#search
search:
  path: search.xml
  field: post
  format: html
  limit: 10000

2.安装插件

 $ npm install hexo-generator-search --save
 $ npm install hexo-generator-searchdb --save

3.修改 主题配置文件(/hexo/themes/next/_config.yml)

# Local search
# Dependencies: https://github.com/flashlab/hexo-generator-search
local_search:
  enable: false
  # if auto, trigger search by changing input
  # if manual, trigger search by pressing enter key or search button
  trigger: auto
  # show top n results per article, show all results by setting to -1
  top_n_per_article: 1

修改为

# Local search
# Dependencies: https://github.com/flashlab/hexo-generator-search
local_search:
  enable: true
  # if auto, trigger search by changing input
  # if manual, trigger search by pressing enter key or search button
  trigger: auto
  # show top n results per article, show all results by setting to -1
  top_n_per_article: 1

集成gitment评论问题

自己按照网上教程安装的几次,但出现的问题是 “未开发评论” 点击login出现404错误
经过一天的努力终于知道原因的,需要发布到git上去,再用自己的git账号登录一下就OK了!
由于没有清除浏览器缓存,出现发布了但未更新。评论还是以前那样。记得清除浏览器缓存,或者换一个浏览器。
集成步骤:
1.注册OAuth Application 点击 https://github.com/settings/applications/new
2.修改 themes/next/_config.yml

# Gitment
# Introduction: https://imsun.net/posts/gitment-introduction/
# You can get your Github ID from https://api.github.com/users/<Github username>
gitment:
  enable: true
  mint: false 
  # RECOMMEND, A mint on Gitment, to support count, language and proxy_gateway
  count: true 
  # Show comments count in post meta area
  lazy: false 
  # 需要懒加载的 修改为true
  # Comments lazy loading with a button
  cleanly: true 
  # Hide 'Powered by ...' on footer, and more
  language: 
  # Force language, or auto switch by theme
  github_user: 你的github用户名
  github_repo: 用户名.github.io
  client_id: 创建OAuth Application时用户id
  client_secret: 填写你自己的client_secret
  #proxy_gateway: # Address of api proxy, See: https://github.com/aimingoo/intersect
  #redirect_protocol: # Protocol of redirect_uri with force_redirect_protocol when mint enabled

其他的就不用修改了。默认就OK了!等以后玩熟了再自定义配置!


参考文档

next参考文档
hexo参考文档

没事就多看看官方文档,应该能解决问题的!加油!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,036评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,046评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,411评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,622评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,661评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,521评论 1 304
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,288评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,200评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,644评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,837评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,953评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,673评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,281评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,889评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,011评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,119评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,901评论 2 355

推荐阅读更多精彩内容