Hexo全过程记录 从Centos到Fluid
Hexo全过程记录 从Centos到Fluid
Description
简单记录一下从0到1搭建Hexo的过程.
本文首发于cnblogs
个人博客地址为 potassium.site ,可以访问查看效果.网站基于Fluid主题配置.
参考:
BKG
腾讯云轻量化应用服务器,CentOS 8.2 64bit.
S1:安装Hexo的依赖
安装Nodejs
使用nodesource
安装,目前(2021年12月29日)最新LTS是V16.13.1
.
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install nodejs
然后y
确定.
安装Git
sudo yum install git-core
安装Hexo
npm install -g hexo-cli
更新node/npm
更新npm
npm -v
npm install npm@latest -g
更新node
node -v
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
S2:初始化
初始化Hexo
Note: Fluid位置默认在/root/node_modules/hexo-theme-fluid/
.
建立一个博客文件夹hexoblog
mkdir hexoblog
在该文件夹路径下:
hexo init
npm install
初始化完成后应该有下面的文件结构:
.
├── _config.landscape.yml
├── _config.yml
├── node_modules
├── package.json
├── package-lock.json
├── scaffolds
├── source
└── themes
初始化Fluid
在博客目录下安装Fluid:
npm install --save hexo-theme-fluid
在博客目录下创建 _config.fluid.yml
.将主题的 _config.yml
内容复制过去.
S3:配置hexo
Note:此后的根路径为博客文件夹所在路径
hexoblog
可以先看看hexo默认的模板,直接部署:
hexo g -d
hexo server
默认在4000
端口启动.
默认网站长这样:
在./_config.yml
中:
theme: fluid # 指定主题
language: zh-CN # 指定语言,会影响主题显示的语言,按需修改
创建关于页
hexo new page about
然后在./source/about/index.md
中添加layout
.
---
title: about
date: 2021-12-29 16:32:56
layout: about
---
about
内容支持markdown,内容以后再填.
个性化配置
网站基本信息,按需填写.
# Site
title: Hexo #显示在标签页上的名字
subtitle: '' #副标题,会被主题中的配置覆盖不用写
description: '' #描述
keywords:
author: John Doe #默认作者名
language: zh-CN #语言
timezone: '' #时区,填Asia/Shanghai
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://example.com #网站的域名
permalink: :year/:month/:hash/ #文章的URL格式,可以不改.或者参考下面的实例
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks
-
url
:填写准备使用的域名.调试阶段可以填公网IP,基本完成后再改成域名. -
permalink
:参考hexo.io:
变量 | 描述 |
---|---|
:year |
文章的发表年份(4 位数) |
:month |
文章的发表月份(2 位数) |
:i_month |
文章的发表月份(去掉开头的零) |
:day |
文章的发表日期 (2 位数) |
:i_day |
文章的发表日期(去掉开头的零) |
:hour |
文章发表时的小时 (2 位数) |
:minute |
文章发表时的分钟 (2 位数) |
:second |
文章发表时的秒钟 (2 位数) |
:title |
文件名称 (relative to “source/_posts/“ folder) |
:name |
文件名称 |
:post_title |
文章标题 |
:id |
文章 ID (not persistent across cache reset) |
:category |
分类。如果文章没有分类,则是 default_category 配置信息。 |
:hash |
SHA1 hash of filename (same as :title ) and date (12-hexadecimal) |
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'
实际上也没必要改,除非打算玩点花活.
其他暂时不用改.
S4:配置Fluid-重要
标题带*的不属于必须部分,可以不修改.
npm install --save hexo-theme-fluid
重新启动,应该就是Fluid的默认界面了.
hexo clean
hexo g -d
hexo server
如果服务器出现下面信息则代表前面做的应该是正确的:
INFO Validating config
INFO Start processing
INFO [Fluid] 读取 _config.yml 中 theme_config 配置项覆盖配置
INFO
------------------------------------------------
| |
| ________ __ _ __ |
| |_ __ |[ | (_) | ] |
| | |_ \_| | | __ _ __ .--.| | |
| | _| | |[ | | | [ |/ /'`\' | |
| _| |_ | | | \_/ |, | || \__/ | |
| |_____| [___]'.__.'_/[___]'.__.;__] |
| |
| 感谢使用 Fluid 主题 ! |
| 文档: https://hexo.fluid-dev.com/docs/ |
| |
------------------------------------------------
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
这是Fluid的默认界面,下面会对其进行必要的个性化修改,以及一些花活.注意,Fluid自有的配置文件_config.fluid.yml
会覆盖hexo的配置文件.
导航栏设定
需要填入的表项有:
-
博客标题
blog_title
-
导航菜单:
-
link
表项不动 -
如果有友链页面,取消最后一行的注释.
-
不需要管的表项:
ground_glass
:这个还是实验室功能,最好不要动
# 导航栏的相关配置
# Navigation bar
navbar:
# 导航栏左侧的标题,为空则按 hexo config 中 `title` 显示
# The title on the left side of the navigation bar. If empty, it is based on `title` in hexo config
blog_title: "Fluid"
# 导航栏毛玻璃特效,实验性功能,可能会造成页面滚动掉帧和抖动,部分浏览器不支持会自动不生效
# Navigation bar frosted glass special animation. It is an experimental feature
ground_glass:
enable: false
# 模糊像素,只能为数字,数字越大模糊度越高
# Number of blurred pixel. the larger the number, the higher the blur
px: 3
# 不透明度,数字越大透明度越低,注意透明过度可能看不清菜单字体
# Ratio of opacity, 1.0 is completely opaque
# available: 0 - 1.0
alpha: 0.7
# 导航栏菜单,可自行增减,key 用来关联 languages/*.yml,如不存在关联则显示 key 本身的值;icon 是 css class,可以省略;增加 name 可以强制显示指定名称
# Navigation bar menu. `key` is used to associate languages/*.yml. If there is no association, the value of `key` itself will be displayed; if `icon` is a css class, it can be omitted; adding `name` can force the display of the specified name
menu:
- { key: "home", link: "/", icon: "iconfont icon-home-fill" }
- { key: "archive", link: "/archives/", icon: "iconfont icon-archive-fill" }
- { key: "category", link: "/categories/", icon: "iconfont icon-category-fill" }
- { key: "tag", link: "/tags/", icon: "iconfont icon-tags-fill" }
- { key: "about", link: "/about/", icon: "iconfont icon-user-fill" }
#- { key: "links", link: "/links/", icon: "iconfont icon-link-fill" }
首页配置
#---------------------------
# 首页
# Home Page
#---------------------------
index:
# 首页 Banner 头图,可以是相对路径或绝对路径,以下相同
# Path of Banner image, can be a relative path or an absolute path, the same on other pages
banner_img: /img/default.png
# 头图高度,屏幕百分比
# Height ratio of banner image
# Available: 0 - 100
banner_img_height: 100
# 头图黑色蒙版的不透明度,available: 0 - 1.0, 1 是完全不透明
# Opacity of the banner mask, 1.0 is completely opaque
# Available: 0 - 1.0
banner_mask_alpha: 0.3
# 首页副标题的独立设置
# Independent config of home page subtitle
slogan:
enable: true
# 为空则按 hexo config.subtitle 显示
# If empty, text based on `subtitle` in hexo config
text: "An elegant Material-Design theme for Hexo"
# 通过 API 接口作为首页副标题的内容,必须返回的是 JSON 格式,如果请求失败则按 text 字段显示,该功能必须先开启 typing 打字机功能
# Subtitle of the homepage through the API, must be returned a JSON. If the request fails, it will be displayed in `text` value. This feature must first enable the typing animation
api:
enable: false
# 请求地址
# Request url
url: ""
# 请求方法
# Request method
# Available: GET | POST | PUT
method: "GET"
# 请求头
# Request headers
headers: {}
# 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
# The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
keys: []
# 自动截取文章摘要
# Auto extract post
auto_excerpt:
enable: true
# 打开文章的标签方式
# The browser tag to open the post
# Available: _blank | _self
post_url_target: _self
# 是否显示文章信息(时间、分类、标签)
# Meta information of post
post_meta:
date: true
category: true
tag: true
# 文章通过 sticky 排序后,在首页文章标题前显示图标
# If the posts are sorted by `sticky`, an icon is displayed in front of the post title
post_sticky:
enable: true
icon: "iconfont icon-top"
Banner配置
该字段配置主页的大图.可以使用本地图片也可使用图床,甚至可以使用随机图片API.详见附录.调试阶段还是用默认背景比较稳定.尺寸字段可根据需要调整.
x:
# 首页 Banner 头图,可以是相对路径或绝对路径,以下相同
# Path of Banner image, can be a relative path or an absolute path, the same on other pages
banner_img: /img/default.png
# 头图高度,屏幕百分比
# Height ratio of banner image
# Available: 0 - 100
banner_img_height: 100#取100时会充满整个屏幕
# 头图黑色蒙版的不透明度,available: 0 - 1.0, 1 是完全不透明
# Opacity of the banner mask, 1.0 is completely opaque
# Available: 0 - 1.0
banner_mask_alpha: 0.3
Slogan配置
该字段配置首页副标题.这里可以使用随机文字api返回随机文字.详见附录.
# 首页副标题的独立设置
# Independent config of home page subtitle
slogan:
enable: true#是否使用slogan
# 为空则按 hexo config.subtitle 显示
# If empty, text based on `subtitle` in hexo config
text: "An elegant Material-Design theme for Hexo"
# 通过 API 接口作为首页副标题的内容,必须返回的是 JSON 格式,如果请求失败则按 text 字段显示,该功能必须先开启 typing 打字机功能
# Subtitle of the homepage through the API, must be returned a JSON. If the request fails, it will be displayed in `text` value. This feature must first enable the typing animation
api:
enable: false#如果设定为true,则覆盖text字段
# 请求地址
# Request url
url: ""
# 请求方法
# Request method
# Available: GET | POST | PUT
method: "GET"
# 请求头
# Request headers
headers: {}
# 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
# The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
keys: []
文章页
Banner配置
和首页的banner配置同.
banner_img: /img/default.png
banner_img_height: 70
banner_mask_alpha: 0.3
# 文章在首页的默认封面图,当没有指定 index_img 时会使用该图片,若两者都为空则不显示任何图片
# Path of the default post cover when `index_img` is not set. If both are empty, no image will be displayed
default_index_img:
第三个字段表示文章在首页的默认图片.也可以后续使用api进行美化.
元信息配置
字数统计和阅读时常最好不要改.
date
字段参考链接修改.文档 | Moment.js 中文网 (momentjs.cn).这里使用LL HH
表示September 4 1986 23:59
.
meta:
# 作者,优先根据 front-matter 里 author 字段,其次是 hexo 配置中 author 值
# Author, based on `author` field in front-matter, if not set, based on `author` value in hexo config
author:
enable: false
# 文章日期,优先根据 front-matter 里 date 字段,其次是 md 文件日期
# Post date, based on `date` field in front-matter, if not set, based on create date of .md file
date:
enable: true
# 格式参照 ISO-8601 日期格式化
# ISO-8601 date format
# See: http://momentjs.cn/docs/#/parsing/string-format/
format: "LL a"
# 字数统计
# Word count
wordcount:
enable: true
# 显示的文本,{}是数字的占位符(必须包含),下同
# Displayed text, {} is a placeholder for numbers (must be included), the same below
format: "{} 字"
# 估计阅读全文需要的时长
# Estimated reading time
min2read:
enable: true
format: "{} 分钟"
# 每个字词的长度,建议:中文≈2,英文≈5,中英混合可自行调节
# Average word length (chars count in word), ZH ≈ 2, EN ≈ 5
awl: 2
# 每分钟阅读字数,如果大部分是技术文章可适度调低
# Words per minute
wpm: 60
文章目录TOC
不需要动.实际上可以只留到h4
.
# 文章右侧目录
# Table of contents (TOC)
toc:
enable: true
# 目录会选择这些节点作为标题
# TOC will select these nodes as headings
headingSelector: "h1,h2,h3,h4,h5,h6"
# 层级的折叠深度,0 是全部折叠,大于 0 后如果存在下级标题则默认展开
# Collapse depth. If 0, all headings collapsed. If greater than 0, it will be expanded by default if there are sub headings
collapseDepth: 0
Latex公式支持
这个一定要打开!specific
字段可视具体情况打开.
# 数学公式,开启之前需要更换 Markdown 渲染器,否则复杂公式会有兼容问题,具体请见:https://hexo.fluid-dev.com/docs/guide/##latex-数学公式
# Mathematical formula. If enable, you need to change the Markdown renderer, see: https://hexo.fluid-dev.com/docs/en/guide/#math
math:
# 开启后文章默认可用,自定义页面如需使用,需在 Front-matter 中指定 `math: true`
# If you want to use math on the custom page, you need to set `math: true` in Front-matter
enable: false
# 开启后,只有在文章 Front-matter 里指定 `math: true` 才会在文章页启动公式转换,以便在页面不包含公式时提高加载速度
# If true, only set `math: true` in Front-matter will enable math, to load faster when the page does not contain math
specific: false
# Options: mathjax | katex
engine: mathjax
归档/分类/标签/关于页配置
改改banner就行了.其他的不需要动.
注意关于页的字段,根据自己的情况填写.示例用的是默认字段.
banner_img
:页面的大图
avatar
:头像图片的url
icons
:各个平台链接.视情况增减.
这里可用的icon参见https://hexo.fluid-dev.com/docs/icon/
#---------------------------
# 归档页
# Archive Page
#---------------------------
archive:
banner_img: /img/default.png
banner_img_height: 60
banner_mask_alpha: 0.3
subtitle:
#---------------------------
# 分类页
# Category Page
#---------------------------
category:
enable: true
banner_img: /img/default.png
banner_img_height: 60
banner_mask_alpha: 0.3
subtitle:
# 分类的排序字段,前面带减号是倒序,不带减号是正序
# Sort field for categories, with a minus sign is reverse order
# Options: length | name
order_by: "name"
# 层级的折叠深度,0 是全部折叠,大于 0 后如果存在子分类则默认展开
# Collapse depth. If 0, all posts collapsed. If greater than 0, it will be expanded by default if there are subcategories
collapse_depth: 0
# 文章的排序字段,前面带减号是倒序,不带减号是正序
# Sort field for posts, with a minus sign is reverse order
# Options: date | title | or other field of front-matter
post_order_by: "-date"
# 单个分类中折叠展示文章数的最大值,超过限制会显示 More,0 则不限制
# The maximum number of posts in a single category. If the limit is exceeded, it will be displayed More. If 0 no limit
post_limit: 10
#---------------------------
# 标签页
# Tag Page
#---------------------------
tag:
enable: true
banner_img: /img/default.png
banner_img_height: 80
banner_mask_alpha: 0.3
subtitle:
tagcloud:
min_font: 15
max_font: 30
unit: px
start_color: "#BBBBEE"
end_color: "#337ab7"
#---------------------------
# 关于页
# About Page
#---------------------------
about:
enable: true
banner_img: /img/default.png
banner_img_height: 60
banner_mask_alpha: 0.3
subtitle:
avatar: /img/avatar.png
name: "Fluid"
intro: "An elegant theme for Hexo"
# 更多图标可从 https://hexo.fluid-dev.com/docs/icon/ 查找,`class` 代表图标的 css class,添加 `qrcode` 后,图标不再是链接而是悬浮二维码
# More icons can be found from https://hexo.fluid-dev.com/docs/en/icon/ `class` is the css class of the icon. If adding `qrcode`, The icon is no longer a link, but a hovering QR code
icons:
- { class: "iconfont icon-github-fill", link: "https://github.com", tip: "GitHub" }
- { class: "iconfont icon-douban-fill", link: "https://douban.com", tip: "豆瓣" }
- { class: "iconfont icon-wechat-fill", qrcode: "/img/favicon.png" }
S5:配置Fluid:美化
这里是非必要的部分,可以选择配置.
标题配置(*)
# 用于浏览器标签的图标
# Icon for browser tab
favicon: /img/favicon.png
# 用于苹果设备的图标
# Icon for Apple touch
apple_touch_icon: /img/favicon.png
# 浏览器标签页中的标题分隔符,效果: 文章名 - 站点名
# Title separator in browser tab, eg: article - site
tab_title_separator: " - "
这里正常填入即可.路径可以用本地的也可以用图床的URL.
代码块配置(*)
这里配置代码块高亮等项目.
可以玩玩的地方有行号,copy键,高亮方式等.
高亮风格参考highlight.js demo (highlightjs.org)填入.
# 代码块的增强配置
# Enhancements to code blocks
code:
# 是否开启复制代码的按钮
# Enable copy code button
copy_btn: true
# 代码高亮
# Code highlight
highlight:
enable: true
# 代码块是否显示行号
# If true, the code block display line numbers
line_number: true
# 实现高亮的库,对应下面的设置
# Highlight library
# Options: highlightjs | prismjs
lib: "highlightjs"
highlightjs:
# 在链接中挑选 style 填入
# Select a style in the link
# See: https://highlightjs.org/static/demo/
style: "Github Gist"
# 是否根据 style 改变代码背景色(如果 style 是深色背景别忘了开启此项)
# If true, the code background will change color based on the style (If style has a dark background, don't forget to true)
bg_color: false
prismjs:
# 在下方链接页面右侧的圆形按钮挑选 style 填入,也可以直接填入 css 链接
# Select the style button on the right side of the link page, you can also set the CSS link
# See: https://prismjs.com/
style: "default"
# 设为 true 高亮将本地静态生成(并只支持部分 prismjs 插件),设为 false 高亮将在浏览器通过 js 生成
# If true, it will be generated locally (but some prismjs plugins are not supported). If false, it will be generated via JS in the browser
preprocess: true
网页字体设定(*)
这里设定主题的字体.一般来说西文应该使用无衬线字体.
font-family
字段可以参考如何优雅的选择字体(font-family) - SegmentFault 思否选择.
# 主题字体配置
# Font
font:
font_size: 16px
font_family:
letter_spacing: 0.02em
code_font_size: 85%
网站PV/UV统计(*)
数据来源使用busuanzi或者leancloud.两个都不太好使.
# 展示网站的 PV、UV 统计数
# Display website PV and UV statistics
statistics:
enable: false
# 统计数据来源,使用 leancloud 需要设置 `web_analytics: leancloud` 中的参数;使用 busuanzi 不需要额外设置,但是有时不稳定,另外本地运行时 busuanzi 显示统计数据很大属于正常现象,部署后会正常
# Data source. If use leancloud, you need to set the parameter in `web_analytics: leancloud`
# Options: busuanzi | leancloud
source: "busuanzi"
# 页面显示的文本,{}是数字的占位符(必须包含),下同
# Displayed text, {} is a placeholder for numbers (must be included), the same below
pv_format: "总访问量 {} 次"
uv_format: "总访客数 {} 人"
备案信息(*)
# 国内大陆服务器的备案信息
# For Chinese mainland website policy, other areas keep disable
beian:
enable: false
# ICP证号
icp_text: 京ICP证123456号
# 公安备案号,不填则只显示ICP
police_text: 京公网安备12345678号
# 公安备案的编号,用于URL跳转查询
police_code: 12345678
# 公安备案的图片. 为空时不显示备案图片
police_icon: /img/police_beian.png
文章最后更新时间
# 在文章开头显示文章更新时间,该时间默认是 md 文件更新时间,可通过 front-matter 中 `updated` 手动指定(和 date 一样格式)
# Update date is displayed at the beginning of the post. The default date is the update date of the md file, which can be manually specified by `updated` in front-matter (same format as date)
updated:
enable: false
# 描述文字
# Descriptive text before date
content: 本文最后更新于:
# 是否使用相对时间表示,比如:"3 天前"
# If true, it will be a relative time, such as: "3 days ago"
relative: false
enable
设置为true
打开该配置.
杂项
# 自动截取文章摘要
# Auto extract post
auto_excerpt:
enable: true
# 打开文章的标签方式
# The browser tag to open the post
# Available: _blank | _self
post_url_target: _self
# 是否显示文章信息(时间、分类、标签)
# Meta information of post
post_meta:
date: true
category: true
tag: true
推荐设置为true
,_blank
,true
.
部署与测试
部署网页并启动服务器:
hexo clean
hexo d -g
hexo server
此时应该可以看到个性化之后的界面.
S6:一些花活
随机头图API
这里使用unsplash提供的api接口.文档见Unsplash Image API | Free HD Photo API.由于是境外网站,可能拖累网站整体加载速度,在使用之前应慎重考虑.
可以注册api使用者,这里用一个比较老的api.
基本api接口:
https://source.unsplash.com/random
返回一个随机图片.
尺寸跟在random后.
附加随机图片主题使用topics
参数,多个关键词用,
分隔:
虽然真的很慢...
另外注意,如果一个页面多个地方引用该api,返回的图片是一样的.这也是防止api被滥用吧.
几种随机subtitles的API
使用随机诗词API作用于Slogan,也就是index.slogan
处.
下面给出了三个API的配置方式.
今日诗词
今日诗词 - 一言API - 诗词实时智能推荐 - 今日诗词开放接口 - 今日诗词 API (jinrishici.com)
该接口特点在于可以根据ip,时间,天气等智能推荐诗词
获取token: https://v2.jinrishici.com/token
请求和返回解析在配置的index-slogan
字段.
api:
enable: true
# 请求地址
# Request url
url: "https://v2.jinrishici.com/sentence"
# 请求方法
# Request method
# Available: GET | POST | PUT
method: "GET"
# 请求头
# Request headers
headers: {X-User-Token:""}#填token
# 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
# The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
keys: ["data", "content"]
返回示例如下,取json的data.content
域:
{
"status":"success",
"data":{
"id":"5b8b9572e116fb3714e7288e",
"content":"怀家寒食夜,中酒落花天。",
"popularity":1770,
"origin":{
"title":"临江仙·暮春",
"dynasty":"宋代",
"author":"赵长卿",
"content":[
"过尽征鸿来尽燕,故园消息茫然。一春憔悴有谁怜。怀家寒食夜,中酒落花天。",
"见说江头春浪渺,殷勤欲送归船。别来此处最萦牵。短篷南浦雨,疏柳断桥烟。"
],
"translate":null
},
"matchTags":[
"晚上",
"寒冷"
],
"recommendedReason":"",
"cacheAt":""
},
"token":"",
"ipAddress":"",
"warning":null
}
但不知道为什么完全没法用...应该是主题的问题.我确定配置没错.如果有大佬解决了这个问题的话肯定比旧版接口要强的.
hitikoto接口
新的请求配置为:
api:
enable: true
# 请求地址
# Request url
url: "https://v1.hitokoto.cn/"
# 请求方法
# Request method
# Available: GET | POST | PUT
method: GET
# 请求头
# Request headers
headers: {"c": "i"}
# 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
# The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
keys: ["hitokoto"]
返回json为:
{
"id":5526,
"uuid":"41891de3-5794-4139-832a-3cdf28e67b09",
"hitokoto":"青山依旧在,几度夕阳红。",
"type":"i",
"from":"临江仙·滚滚长江东逝水",
"from_who":"杨慎",
"creator":"a632079",
"creator_uid":1044,
"reviewer":1044,
"commit_from":"api",
"created_at":"1586266066",
"length":12
}
但这个放进去不能指定句子类型,于是就会有很多尴尬癌犯了的中二病句子...无语了.
jinrisici
这是今日诗词的旧版接口,但仍然在维护.
仅仅能返回随机的诗句.完全的随机.
配置如下:
api:
enable: true
# 请求地址
# Request url
url: "https://v1.jinrishici.com/all.json"
# 请求方法
# Request method
# Available: GET | POST | PUT
method: GET
# 请求头
# Request headers
headers: {}
# 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
# The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
keys: ["content"]
返回格式为:
{
"content" : "夜来风雨声,花落知多少。",
"origin" : "春晓",
"author" : "孟浩然",
"category" : "古诗文-天气-写风"
}
该api还可以手动选择分类,详见https://v1.jinrishici.com.
S7:持久化部署
调试完毕后,就可以着手持久化部署了.修改占位字符串为正式字符串.
参考Linux后台运行hexo - 云+社区 - 腾讯云 (tencent.com)
安装pm2
npm install -g pm2
在博客目录下创建hexo_run.js
//run
const { exec } = require('child_process')
exec('hexo server',(error, stdout, stderr) => {
if(error){
console.log('exec error: ${error}')
return
}
console.log('stdout: ${stdout}');
console.log('stderr: ${stderr}');
})
在博客目录下执行:
pm2 start hexo_run.js
就可以持续运行了.域名还没有切换,到时候再说吧.
需要修改的话,需要将pm2的任务撤下来:
pm2 list # 列表 PM2 启动的所有的应用程序
pm2 monit # 显示每个应用程序的CPU和内存占用情况
pm2 show [app-name] # 显示应用程序的所有信息
pm2 logs # 显示所有应用程序的日志
pm2 logs [app-name] # 显示指定应用程序的日志
pm2 flush
pm2 stop all # 停止所有的应用程序
pm2 stop 0 # 停止 id为 0的指定应用程序
修改默认端口
hexo默认端口是4000
,用域名需要在后面加上:4000
.可以通过在启动脚本中server
改成hexo s -p 80
,也可以在node_modules \ hexo-server\ index.js
中修改默认值.但80端口属于权限端口要用root
打开.
常见的莫名其妙问题
has been blocked by CORS policy
非常怪...用Edge就会出现这个,可以参考关闭,但并不靠谱.
查F12发现是CDN被认定为跨域被拦截了.
解决方法:上Chrome
附录
调试用一键部署脚本:
hexo clean
hexo d -g
hexo server
持久化一键部署脚本:
hexo clean
hexo d -g
pm2 start hexo_run.js
pm2相关操作:
后续会将配置文件放在post中以备参考.博客文章的撰写也会在后续记录.