Hexo-next-添加pdf插件

People who are crazy enough to think they can change the world, are the ones who do.
Apple Computers

本文由 简悦 SimpRead 转码, 原文地址 blog.csdn.net

需求:

希望能在 GitHub 搭建的博客中上传本地 PDF 文件,同时提供下载功能。

一、安装插件

1
2
# 在博客bash中执行下列命令安装
$ npm install --save hexo-pdf

next/_config.yml _config.next.yml中修改此处:打开 pdf功能

1
2
3
4
5
6
7
8
9
10
11
12
13
# PDF tag
# NexT will try to load pdf files natively, if failed, pdf.js will be used.
# So, you have to install the dependency of pdf.js if you want to use pdf tag and make it available to all browsers.
# Dependencies: https://github.com/next-theme/theme-next-pdf
pdf:
enable: true
# Default height
height: 500px
pdfobject:
# Use 2.1.1 as default, jsdelivr as default CDN, works everywhere even in China
cdn: //cdn.jsdelivr.net/npm/pdfobject@2.1.1/pdfobject.min.js
# CDNJS, provided by cloudflare, maybe the best CDN, but not works in China
#cdn: //cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js

编写方法

在md 文件中添加 pdf

1
2
3
4
外部链接:
{% pdf http://7xov2f.com1.z0.glb.clouddn.com/bash_freshman.pdf %}
本地连接:
{% pdf ./pdf名字.pdf %}

建立页面

若建立页面如下图,

20190310135840682.png

在博客 source\,文件夹下创建一个文件夹如books,内部新建 index.md, 同时需要再创建一个同名的 test 文件夹,放我们要上传的 PDF 文章

创建 book 页面

1
2
3
4
5
6
7
8
9
10
11
12
13
---
title: 测试使用
date: 2019-03-10 20:07:12
tags: 测试
categories: 测试
---


## **测试**


{% pdf 路径.pdf %}

还要如图设置:

20190310135959597.png

建立文章

外部文章网页链接

1
{% pdf http://7xov2f.com1.z0.glb.clouddn.com/bash_freshman.pdf %}

在博客 source\_posts\,文件夹下创建一个文章如 test.md, 同时需要再创建一个同名的 test 文件夹,放我们要上传的 PDF 文章

1
2
3
4
5
6
7
8
9
10
11
12
---
title: 测试使用
date: 2019-03-10 20:07:12
tags: 测试
categories: 测试
---


## **测试**


{% pdf 路径.pdf %}

最后使用命令:hexo g 生成; hexo d 发布后,即可实现需求

20190310152801944.png