通过 hexo 生成静态博客

摘要:
args){^语法错误:意外标记=atexports.runInThisContext(vm.js:32)atFunction.Module.load(Module.js:12)atModule.require(Module.js:17)atrequire(internal/Module.js:1)atModules.compile(Module.js:
通过 hexo 生成静态博客

背景

在对比了很多博客网站以后,我决定开始慢慢迁移我的文章,以后有时间的话还会搭建自己的网站,目前主流的静态博客生成器有三个: jekyll, hexo, hugo.

静态博客生成器是一种将 文档(主流是markdown 格式)生成静态网站页面文件的工具;当我们再将生成的结果放到page服务上,就可以变为静态博客。

接下来我们就围绕 hexo 和博客搭建来展开,如果你具有前端编程能力我推荐你一开始就是用 hugo 来搭建自己的博客,如果你不熟悉前端知识建议你使用 hexo 实现,因为 hexo 的优势就是有很多现成的插件, 而且可选的主题样式比较多。唯一的缺点就是生成的速度可能会比较慢,但半个小时内的速度对于我本人是可以接受的。

host平台   :Ubuntu 16.04

步骤

我们使用 Hexo 只需要如下几个步骤就可以实现一个最基本的网站,甚至都不需要自定义。接下来先从大概搭建步骤上简要说明过程:

安装 Hexo

Hexo 安装的前提条件 安装 Node.js 和 npm 环境:

npm install -g hexo-cli
npm install -g hexo-server

如果遇到nodejs版本太低会遇到下面的问题:

$ hexo -version
/usr/local/lib/node_modules/hexo-cli/lib/hexo.js:15
function entry(cwd = process.cwd(), args) {
                   ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/hexo-cli/bin/hexo:5:1)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)


$ nodejs --version
v4.2.6

部署

安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

$ hexo init <folder>
$ cd <folder>
$ npm install

新建完成后,指定文件夹的目录如下:

.
├── _config.yml
├── package.json
├── scaffolds
├── source
|   ├── _drafts
|   └── _posts
└── themes

_config.yml

网站的 配置 信息,您可以在此配置大部分的参数。

package.json

应用程序的信息。EJS, StylusMarkdown renderer 已默认安装,您可以自由移除。

package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": ""
  },
  "dependencies": {
    "hexo": "^3.8.0",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.1",
    "hexo-generator-tag": "^0.2.0",
    "hexo-renderer-ejs": "^0.3.1",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-renderer-marked": "^0.3.2",
    "hexo-server": "^0.3.3"
  }
}

scaffolds

模版 文件夹。当您新建文章时,Hexo 会根据 scaffold 来建立文件。

Hexo的模板是指在新建的文章文件中默认填充的内容。例如,如果您修改scaffold/post.md中的Front-matter内容,那么每次新建一篇文章时都会包含这个修改。

source

资源文件夹是存放用户资源的地方。除 _posts 文件夹之外,开头命名为 _ (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。

themes

主题 文件夹。Hexo 会根据主题来生成静态页面

创建文章

创建一篇新的文章

hexo new "my-first-post"

生成静态文件

使用以下命令,成功以后在public目录看到生成的静态文件内容,只需要将该内容同步到服务器即可。

hexo g

测试

为了方便测试,hexo提供了本地服务,在当前目录下使用以下命令

hexo server

然后在 浏览器中打开http://localhost:4000,即可看到效果

安装新的主题

hexo | them 可以选择自己喜欢的主题。这里以“NexT”为例。

下载

git clone https://github.com/theme-next/hexo-theme-next.git

下载以后,放到 theme文件夹,改名为next

修改配置

修改_config.yml,将theme改为 next

重新生成

hexo clean && hexo d -g

添加新的页面

修改_config.yml,添加

# ---------------------------------------------------------------
# Menu Settings
# ---------------------------------------------------------------
 
# When running the site in a subdirectory (e.g. domain.tld/blog), remove the leading slash from link value (/archives -> archives).
# Usage: `Key: /link/ || icon`
# Key is the name of menu item. If the translation for this item is available, the translated text will be loaded, otherwise the Key name will be used. Key is case-senstive.
# Value before `||` delimiter is the target link.
# Value after `||` delimiter is the name of FontAwesome icon. If icon (with or without delimiter) is not specified, question icon will be loaded.
# External url should start with http:// or https://
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

输入以下命令:

hexo new page "about" &&
hexo new page "tags" && 
hexo new page "categories"

打开各页面对应的index.md文件,编辑如下内容,title和date是默认生成的,增加type即可:

type: "about"type: "tags"type: "categories"

重新部署

hexo clean && hexo d -g

测试

hexo server

免责声明:文章转载自《通过 hexo 生成静态博客》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇itouch/iphone/ipad充不上电的解决办法Java 9 尝鲜之JShell交互式编程环境下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Python 基础之推导式

一.列表推导式 通过一行循环判断,遍历出一系列数据的方式就是推导式 特点:方便,简洁,可以实现一些简单的功能推导式当中只能跟循环和判断(单项分支)种类分为三种: 列表推导式  集合推导式  字典推导式 1.推导式内容讲解 #(1) 基本语法#例: #[1,2,3,4] => [2,4,6,8]lst = [1,2,3,4]lst2 = []for i...

ADO中记录集recordSet的使用

_RecordsetPtr使用方法 _variant_t vUsername,vID,vname; //变量声明_RecordsetPtr m_pRecordset;     //记录集CString strid;_ConnectionPtr connection;m_pRecordset.CreateInstance(__uuidof( Record...

PHP 网页快照

安装libwkhtmltox http://code.google.com/p/wkhtmltopdf/downloads/list下载,解压到/usr下 安装php-libwkhtmltox,方式为PHP插件,http://github.com/mreiferson/php-wkhtmltox下,用phpize编译 安装以上软件.即可.详情看php-wk...

微信语音短消息amr文件转WAV

“ 微信语音短消息amr文件转WAV。” 在《SILK编码语音转WAV格式》中提到过,“腾讯系产品,包括QQ、微信、小程序,在语音相关的实现中,也大量使用到SILK编码”,并对SILK编码、WAV格式及SILK转WAV进行了介绍。 本文将针对微信语音短消息amr后缀文件转换成WAV文件的方法进行说明。 而QQ语音流、微信语音流的SILK解码方式与此...

Nginx大文件(百M以上)的上传下载实现技术

javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求     1. 通过form表单向后端发送请求          <form id="postForm" action="${pageContext.request.contextPath}/UploadServlet" m...

QString 和 TCHAR 的相互转换

参考资料: http://www.cnblogs.com/fuyanwen/p/3200536.htmlhttp://www.cnblogs.com/wendao/archive/2012/07/27/2612597.html 不能直接用: QString szqFileName = QString::fromLocal8Bit("data");const...