鱼之乐

子非鱼安知鱼之乐


  • 首页

  • 标签

  • 分类

  • 归档

  • 关于

hexo 使用初步

发表于 2019-08-07 更新于 2019-11-06 分类于 工具 评论数:

安装

npm install -g hexo

项目初始化

选择新建项目所在文件夹,执行以下命令

hexo init myhexo #初始化项目文档
cd myhexo
npm install #安装依赖
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)

主题变更

将目标主题clone到/themes文件夹下

yilia
$ git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
modernist
$ git clone https://github.com/heroicyang/hexo-theme-modernist.git themes/modernist
jacman
$ git clone https://github.com/cnfeat/cnfeat.git themes/jacman
next
$ git clone https://github.com/theme-next/hexo-theme-next 

修改配置参照以下,综合添加评论的复杂度,推荐next+valine。

项目配置

修改配置文件_config.yml

# Site
title: 鱼之乐
subtitle: 子非鱼安知鱼之乐
description:
keywords:
author: 鱼之乐
language:
timezone:

......

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next    #指定使用的主题,主题放在/themes文件夹下

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
    type: git   
        repo: https://github.com/hmilywb/hmilywb.github.io
        branch: master

代码上传

必要条件:

  1. 配置SSH KEY,相当于用户名密码

  2. 配置_config.yml中有关deploy的部分,已在上文项目配置搞定

  3. 安装插件hexo-deployer-git

    npm install hexo-deployer-git –save

正常代码上传可通过

hexo d 

注: 此时可能会报错,显示

Fatal: HttpRequestException encountered.

这是因为Github禁用了TLS v1.0 and v1.1这种弱加密标准,需要手动更新Windows的git凭证管理器,可从Github官方
下载较新版本安装即可。

hexo 常用命令&简写

hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help  # 查看帮助
hexo version  #查看Hexo的版本

缩写:

hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy

组合命令:

hexo s -g #生成并本地预览
hexo d -g #生成并上传

写博客

定位到hexo根目录,执行命令:

hexo new 'my-first-page'

自动在_posts下生成相关md文件my-first-page.md

这个命令的好处是帮我们自动生成了默认内容,打开这个文件即可开始写博客了,默认生成如下内容:

title: postName #文章页面上的显示名称,一般是中文
date: 2013-12-02 15:30:16 #文章生成时间,一般不改,当然也可以任意修改
categories: 默认分类 #分类
tags: [tag1,tag2,tag3] #文章标签,可空,多标签请用格式,注意:后面有个空格
description: 附加一段文章摘要,字数最好在140字以内,会出现在meta的description里面

菜单设置

菜单包括:首页、归档、分类、标签、关于等等,默认的只有首页和归档两个,可打开主题配置文件找到Menu Settings

menu:
home: / || home                          //首页
archives: /archives/ || archive          //归档
categories: /categories/ || th           //分类
tags: /tags/ || tags                     //标签
about: /about/ || user                   //关于
#schedule: /schedule/ || calendar        //日程表
#sitemap: /sitemap.xml || sitemap        //站点地图
#commonweal: /404/ || heartbeat          //公益404

以archives: /archives/ || archive为例:
|| 之前的/archives/表示标题“归档”,关于标题的格式可以去themes/next/languages/zh-Hans.yml中参考或修改
||之后的archive表示图标,可以去Font Awesome中查看或修改,Next主题所有的图标都来自Font Awesome。

创建新的菜单页面,注意在next主题的配置文件中,categories/tags/about是关键词

hexo new page categories # or tags/about

修改/source/文件夹下index.md文件,以categories为例

---
title: categories
date: 2018-03-02 12:33:16
type: "categories"
---

## Next主题样式设置

Next主题有4种风格可供选择,打开主题配置文件找到Scheme Settings

# Schemes
# scheme: Muse
# scheme: Mist
# scheme: Pisces
scheme: Gemini

4种风格大同小异,目前使用的是Gemini风格。

添加搜索功能

安装hexo-generator-searchdb插件

npm install hexo-generator-searchdb --save

打开站点配置文件找到Extensions,在下面添加

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

打开主题配置文件找到Local search,将enable设置为true

添加评论功能

推荐使用valine,首先注册valine 国际版

  1. 创建一个开发版应用(免费)
  2. 在LeanCloud-设置-安全中心,把除数据存储其他选项都关闭,安全域名中添加域名
  3. 在LeanCloud-存储,添加两个class,分别为Comment和Counter,无限制
  4. 在LeanCloud-设置-应用key,获取appid和appkey,以备后用

打开主题配置文件(即next主题中的_config.yml),找到valine的配置

valine:
    enable: true 
    appid: xxxxx # Your leancloud application appid
    appkey: xxxxx # Your leancloud application appkey

hexo重新generate和server,最好clean一下。

# hexo
github配置
markdown 语法初步
  • 文章目录
  • 站点概览
鱼之乐

鱼之乐

11 日志
3 分类
8 标签
  1. 1. 安装
  2. 2. 项目初始化
  3. 3. 主题变更
  4. 4. 项目配置
    1. 4.1. 代码上传
    2. 4.2. hexo 常用命令&简写
    3. 4.3. 写博客
    4. 4.4. 菜单设置
    5. 4.5. 添加搜索功能
    6. 4.6. 添加评论功能
© 2019 鱼之乐
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Gemini v7.3.0