This is a plugin that allows to preview PDF files in the blog pages.
If the browser supports embedded PDFs natively, NexT will create a <embed>
tag and include the PDF file on your website. Otherwise, it will create a <iframe>
tag and uses PDF.js by @mozilla to render the pdf file.
Follow the guide below to install the plugin.
Change dir to Hexo directory. There must be source
, themes
and other directories:
$ cd hexo-site
$ ls
_config.next.yml db.json package-lock.json scaffolds themes
_config.yml node_modules package.json source
If you have already added the Hexo directory to a git repository, then install this plugin as a git submodule:
$ git submodule add https://github.com/next-theme/theme-next-pdf source/lib/pdf
Otherwise, install the plugin to source/lib
directory via git clone
:
$ git clone https://github.com/next-theme/theme-next-pdf source/lib/pdf
Enable the plugin in NexT _config.next.yml
file:
# 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.
# See: https://github.com/next-theme/theme-next-pdf
pdf:
enable: true
# Default height
height: 500px
Find and edit skip_render
settings in Hexo _config.yml
file:
skip_render:
- lib/**/*
In order to embed PDF files in the article, you just need to create pdf
tags with the URL of your local PDF file, e.g.
{% pdf /path/to/your/file.pdf %}
Notice: Do not use cross-origin PDF files, it might be blocked by the CORS policy.
Enjoy it!
$ cd hexo-site/source/lib/pdf
$ git pull