hexo-generator-amp
AMP ⚡ HTML (Accelerated Mobile Pages Project HTML) generator for Hexo.
Orverview
This plugin automatically generates AMP HTML pages.
Output file path is ./your-parmalink/amp/
. Also, You can freely choose the template(.ejs) and style(.css).
Update Notice v1.0.3
Added cache
option. This option improves the generation speed. Old articles will not be generated AMP HTML again. Old articles will use cache.
DEMO
First of all, please see the examples. The following is my hexo blog.
Installation
$ npm install hexo-generator-amp --save
Usage
1. Edit your theme
First, add the following in your template files. For example , Please edit themes/(your-theme)/layout/_partial/head.ejs
.
<% if (is_post() && config.generator_amp){ %>
<link rel="amphtml" href="./amp/index.html">
<% } %>
Please refer follow as about how to use this plugin with based other templates.
2. Add your config file
Please set the following options. Please edit _config.yml
.
generator_amp:
templateDir: amp-template
assetDistDir: amp-dist
logo:
path: sample/sample-logo.png
width: 600
height: 60
substituteTitleImage:
path: sample/sample-substituteTitleImage.png
width: 1024
height: 800
warningLog: false
3. Run server
Starts a local server. By default, this is at http://localhost:4000/
.
$ hexo server
4. Validate AMP Pages
This plugin generated the AMP HTML. Output file path is ./your-parmalink/amp/
.
Now validate your AMP pages. Open your AMP page in your browser. Open the Chrome DevTools console and check for validation errors. Please Append http://localhost:4000/your-parmalink/amp/#development=1
to the URL. Please see below for the details.
Accelerated Mobile Pages Project - Validate AMP Pages
How to validate AMP - my blog
Options
This plugin can set the following options. Please edit _config.yml
.
generator_amp:
substituteGoogle_adsense:
data_ad_client: ca-pub-123456789876543
data_ad_slot: 0123456789
width: 336
height: 280
templateDir: amp-template
assetDistDir: amp-dist
logo:
path: sample/sample-logo.png
width: 600
height: 60
logo_topImage:
path: sample/sample-yoursite-logo.png
width: 1024
height: 400
substituteTitleImage:
path: sample/sample-substituteTitleImage.png
width: 1024
height: 800
cssFilePath: sample/sample-amp.css
templateFilePath: sample/sample-amp.ejs
google_analytics: UA-123456789-1
html_minifier:
warningLog: true
cache: hexo-generator-amp-cached.json
authorDetail:
authorReading: Your name description
avatar:
path: sample/sample-avator.png
width: 150
height: 150
description: Self introduction
copyright_notice: The footer copyright notice
A description of the options
Option can use as follows.
1. Google Adsense Option
If an advertisement is found in an article, it will be converted to AMP specification.
Adout Google Adsense , please see Create an AMP ad unit for the details.
option | description |
---|
data_ad_client | substitute data_ad_client id |
data_ad_slot | substitute data_ad_slot id |
width | substitute ad width |
height | substitute ad height |
2. Template Option
templateDir & assetDistDir
option | description |
---|
templateDir | File path of a your AMP template files. |
assetDistDir | File path of a your public AMP Assets. |
logo
option | description |
---|
path | File path of a your logo (schema.org logo for AMP) image. |
width | Width of a your logo (schema.org logo for AMP) image. (width <= 600px) |
height | Height of a your logo (schema.org logo for AMP) image. (height <= 60px) |
logo_topImage
option | description |
---|
path | File path of a your site logo image. |
width | Width of a your site logo image. |
height | Height of a your site logo image. |
substituteTitleImage
option | description |
---|
path | File path of a your substitute title image. (Use this when the image is not in the markdown) |
width | Width of a your substitute title image. (width >= 696px) |
height | Height of a your substitute title image. |
cssFilePath & templateFilePath
3. Google Analytics Option
option | description |
---|
google_analytics | Your google analytics tracking ID. |
4. Minify Option
option | description |
---|
html_minifier | Enabled html_minifier. Please see kangax/html-minifier for the details. |
5. Log Option
option | description |
---|
warningLog | Enabled warnings. |
6. Cache Option
option | description |
---|
cache | This option improves the generation speed. Old articles will not be generated AMP HTML again. Old articles will use cache. |
authorReading
option | description |
---|
authorReading | Your name description. |
avatar
option | description |
---|
path | File path of a your avator image. |
width | Width of a your avator image. |
height | Height of a your avator image. |
description
option | description |
---|
description | Self introduction. |
copyright_notice
option | description |
---|
copyright_notice | The footer copyright notice. |
Front-matter option.
ampSettings.titleImage.path (optional)
You can choose path of schema.org image on a per post. If your post is not contain this option , this plugin search image from content.
For example : hello-world.md
, Please set the following options.
---
title: Hello World
ampSettings:
titleImage:
path: titleImage-on-the-local-folder.png
---
Welcome to [Hexo](https://hexo.io/)! This is your very first post.
...
If image on the external , Please set the width and height options.
---
title: Hello World
ampSettings:
titleImage:
path: http://titleImage-on-the-external.png
width: 1024
height: 800
---
Welcome to [Hexo](https://hexo.io/)! This is your very first post.
...
Supports external services
Supports the following external services.
License
MIT