如题,我打算把我自己的博客移植,因为感觉有时候从手机上甩给别人一个链接不方便,还是微信小程序更方便一些。

fc3cd489ab144017a145f2d3170w

hexo插件安装

首先是需要一个插件的,这个插件的是hexo-generator-restful,作用就是可以将 hexo 中的某些东西可以转换生成 restful 接口供其他地方调用。

这是一个 restful 风格的 json 文件接口,可以直接去访问这个文件,获得静态网页的信息。

下面是这个插件在 Github 上的说明:

https://github.com/yscoder/hexo-generator-restful

安装

打开 CMD,将路径cd到博客下,直接在 CMD 中打入以下命令就可以安装:

1
npm install hexo-generator-restful

配置

首先打开配置文件_config.yaml,可以通过修改配置文件信息来实现其他功能,但最开始还没有这些配置,需要手动复制以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 对外API
restful:
# site 可配置为数组选择性生成某些属性
# site: ['title', 'subtitle', 'description', 'author', 'since', email', 'favicon', 'avatar']
site: true # hexo.config mix theme.config
posts_size: 10 # 文章列表分页,0 表示不分页
posts_props: # 文章列表项的需要生成的属性
title: true
slug: true
date: true
updated: true
comments: true
path: true
excerpt: false
cover: true # 封面图,取文章第一张图片
content: true
keywords: true
categories: true
tags: true
categories: true # 分类数据
use_category_slug: true # Use slug for filename of category data
tags: true # 标签数据
use_tag_slug: true # Use slug for filename of tag data
post: true # 文章数据
pages: true

上面是官方给的一个模板,我就没怎么修改了,有些设置感觉没必要,这些信息就足够了,所以就暂时这样。

使用方法

以上配置完成后,就可以先使用hexo g命令来静态编译一下,注意一定要有上面的那些命令,否则会出现一些错误。

在博客的环境下有一个api文件夹,里面就是一些自己编译出来的接口,所以直接使用即可。

(长期更新,未完待续)