Nanfeng

Notes on software development, code, and curious ideas

Publishing Hexo Content in a WeChat Mini Program

The original mini program could be found by searching for it前端农民工 in WeChat or scanning this code:

Mini program QR code

Generate an API from Hexo

Install hexo-generator-wxapi:

1
npm install hexo-generator-wxapi --save

See the project documentation for current usage details.

Add the required API configuration to the root Hexo _config.yml:

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
26
27
28
restful_api:
site: true
posts_size: 8
posts_props:
title: true
slug: true
date: true
updated: true
comments: true
path: true
excerpt: false
cover: true
content: false
keywords:
categories: true
tags: true
categories: true
use_category_slug: false
tags: true
use_tag_slug: false
post: true
pages: false
swipers_list: []
search_all:
enable: true
path: api/search.json
field: post
content: true

Configure the mini program

Clone the front-end project and import it into WeChat Developer Tools:

1
git clone https://github.com/Rr210/hexo-wx-api

Open config/config.js and update the site-specific values:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const DOMAIN = 'lengmo714.top';
const WEBSITENAME = 'Nanfeng';
const ZANIMAGEURL = '../../static/images/wechat.png';
const LOGO = '../../static/images/logo-icon.png';
const ARTICLE_AUTHOR_NAME = 'Nanfeng';
const ARTICLE_AUTHOR_IMG = '../../static/images/author.png';

const ISAD = {
enable: false,
bannerId: ''
};

export default {
getDomain: DOMAIN,
getWebsiteName: WEBSITENAME,
getZanImageUrl: ZANIMAGEURL,
getLogo: LOGO,
getAuthorname: ARTICLE_AUTHOR_NAME,
getAuthorImg: ARTICLE_AUTHOR_IMG,
getAd: ISAD
};

The home-page navigation can also be customized in this file. Its redirecttype distinguishes internal pages, other mini programs, and web views. Global styling is defined in app.wxss.

Upload

Use WeChat Developer Tools to upload the build, then complete the Mini Program submission and review workflow. Before publishing, configure the permitted request domains in the WeChat console and confirm that the Hexo API is served over HTTPS.

+