Skip to content

Commit

Permalink
Supports automatic acquisition of external image width and height #22
Browse files Browse the repository at this point in the history
…Closes , fixed sample template. added validateAMP option.
  • Loading branch information
twpl committed Apr 19, 2017
1 parent 7a93873 commit 7392ed3
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 277 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $ npm install -g hexo-cli
$ hexo init hexo6101
$ cd hexo6101
$ npm install
$ npm install this-plugin-name --save
$ npm install hexo-generator-amp --save
```

## For BUG
Expand Down
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ You must add AMP HTML's link to non-AMP.

> Accelerated Mobile Pages Project - [Prepare Your Page for Discovery and Distribution](https://www.ampproject.org/docs/get_started/create/prepare_for_discovery)
First, add the following in your template files. For example , Please edit `themes/(your-theme)/layout/_partial/head.ejs` as following .
First, add the following in your template files. For example , Please edit `themes/(your-theme)/layout/_partial/head.ejs` as following . For example , In [hexo-theme-landscape](https://github.com/hexojs/hexo-theme-landscape) you will edit `themes/landscape/layout/_partial/head.ejs`.

``` ejs
<% if (is_post() && config.generator_amp){ %>
Expand Down Expand Up @@ -80,7 +80,7 @@ generator_amp:
path: sample/sample-substituteTitleImage.png
width: 1024
height: 800
warningLog: false # To AMP HTML validate automatically, please set true.
warningLog: false # To display warning, please set true.
```
### 3. Run server
Expand Down Expand Up @@ -111,12 +111,12 @@ Now validate your AMP HTML. First off all , open your AMP HTML page in [Chrome D

This plugin can validate without being conscious AMP HTML automatically by [amphtml-validator ( AMP HTML validator command line tool )](https://www.npmjs.com/package/amphtml-validator).

To use Internal Validation , please change the `warningLog: true`.
To use Internal Validation , please change the `validateAMP: true`.

``` yaml
# Please edit _config.yml.
generator_amp:
warningLog: true # To AMP HTML validate automatically,, please set true.
validateAMP: true # To AMP HTML validate automatically, please set true.
```

For example , when occur the AMP validation error , this plugin displaying following error message .
Expand Down Expand Up @@ -200,8 +200,11 @@ generator_amp:
# 6. Cache Option
cache: hexo-generator-amp-cached.json #(optional)
# onlyForDeploy: false #(optional) #Deprecated <= v1.0.3
# 7. Automatically validate AMP HTML
validateAMP: true #(optional)
# 7. Footer Option (authorDetail)
# 8. Footer Option (authorDetail)
authorDetail:
authorReading: Your name description #(optional)
avatar: #(optional)
Expand Down Expand Up @@ -319,7 +322,16 @@ This option improves the generation speed. Old articles will not be generated AM
| :---: | :--- |
|cache| Enabled cache |

#### 7. Footer Option (authorDetail)

#### 7. Automatically validate AMP HTML option

To AMP HTML validate automatically, please set true. Please see [Validate AMP HTML](https://github.com/tea3/hexo-generator-amp#4-validate-amp-html) for more detail.

| option | description |
| :---: | :--- |
| validateAMP | Enable AMP HTML validate automatically |

#### 8. Footer Option (authorDetail)

This option use for sample template for AMP HTML.

Expand Down Expand Up @@ -377,23 +389,6 @@ Welcome to [Hexo](https://hexo.io/)! This is your very first post.
```

If image on the external , Please set the width and height options.

``` markdown
---
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.
Expand Down
12 changes: 8 additions & 4 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getAddObj(inPath, inPostPath , inDate , inEyeCatchImage , inTitleImageF
//---------------------------------------
// Writing cache file
//---------------------------------------
function createCacheFile(inPath, hexoConfig, inPostPath , inDate , inEyeCatchImage , inTitleImageForAmp, inEyeCatchImageProperty , inXml){
function createCacheFile(inPath, hexoConfig, inPostPath , inDate , inEyeCatchImage , inTitleImageForAmp, inEyeCatchImageProperty , inXml , callback){

var cacheData;
var newObj = {
Expand Down Expand Up @@ -106,6 +106,8 @@ function createCacheFile(inPath, hexoConfig, inPostPath , inDate , inEyeCatchIma

newObj = null;
addObj = null;

if(callback)callback();
}


Expand Down Expand Up @@ -162,15 +164,17 @@ module.exports.getCacheHash = function(hexoConfig){
//---------------------------------------
// Generation of Eyecatch image cache
//---------------------------------------
module.exports.saveCache_eyeCatchImg = function(post, hexoConfig){
module.exports.saveCache_eyeCatchImg = function(post, hexoConfig , callback){
if( existsOption(hexoConfig) ){
// console.log(post.path);
// console.log(post.updated._i);
// console.log(" -> " + post.eyeCatchImage);
// console.log(" -> " + post.titleImageForAmp);
// console.log(" -> " + post.eyeCatchImageProperty);

createCacheFile( getCachePath(hexoConfig), hexoConfig , post.path , post.updated._i , post.eyeCatchImage , post.titleImageForAmp , post.eyeCatchImageProperty , null );
createCacheFile( getCachePath(hexoConfig), hexoConfig , post.path , post.updated._i , post.eyeCatchImage , post.titleImageForAmp , post.eyeCatchImageProperty , null , callback );
}else{
callback();
}
};

Expand All @@ -185,6 +189,6 @@ module.exports.saveCache_amp = function(post, inXml , hexoConfig){
// console.log(post.updated._i);
// console.log(" -> " + xml);

createCacheFile( getCachePath(hexoConfig), hexoConfig , post.path , post.updated._i , null , null , null , inXml );
createCacheFile( getCachePath(hexoConfig), hexoConfig , post.path , post.updated._i , null , null , null , inXml , null );
}
};
Loading

0 comments on commit 7392ed3

Please sign in to comment.