hexo-generator-amp
Advanced tools
Comparing version 0.1.11 to 0.1.12
15
index.js
@@ -11,2 +11,3 @@ 'use strict'; | ||
var logoPath = '../template/sample-logo.png'; | ||
var sitelogoPath= '../template/sample-yoursite-logo.png'; | ||
var avatorPath = '../template/sample-avator.png'; | ||
@@ -20,3 +21,3 @@ var substituteTitleImagePath = '../template/sample-substituteTitleImage.png'; | ||
if(hexo.config.generator_amp && hexo.config.generator_amp.templateDir && hexo.config.generator_amp.assetDistDir && hexo.config.generator_amp.logo && hexo.config.generator_amp.logo.path && hexo.config.generator_amp.substituteTitleImage && hexo.config.generator_amp.substituteTitleImage.path){ | ||
ic.initCopy(hexo.config.generator_amp.templateDir, [ejsPath, cssPath, logoPath, substituteTitleImagePath, avatorPath]); | ||
ic.initCopy( pathFn.join(hexo.config.generator_amp.templateDir) , [ejsPath, cssPath, logoPath, sitelogoPath, substituteTitleImagePath, avatorPath]); | ||
}else{ | ||
@@ -27,7 +28,15 @@ console.log("\u001b[31m[hexo-generator-amp] (error) please setting option.\u001b[0m "); | ||
var avatorDefaultPath = pathFn.basename( avatorPath ); | ||
var avatorDefaultPath = "sample/" + pathFn.basename( avatorPath ); | ||
if(hexo.config.authorDetail && hexo.config.authorDetail.avatar && hexo.config.authorDetail.avatar.path){ | ||
avatorDefaultPath = hexo.config.authorDetail.avatar.path; | ||
} | ||
var copyAssetsStatus = ic.copyAssets(hexo.config.generator_amp.templateDir, hexo.config.generator_amp.assetDistDir, [hexo.config.generator_amp.logo.path, hexo.config.generator_amp.substituteTitleImage.path, avatorDefaultPath]); | ||
var siteLogImagePath = ""; | ||
if(hexo.config.generator_amp.logo_topImage && hexo.config.generator_amp.logo_topImage.path){ | ||
siteLogImagePath = hexo.config.generator_amp.logo_topImage.path; | ||
}else{ | ||
siteLogImagePath = hexo.config.generator_amp.logo.path; | ||
} | ||
var copyAssetsStatus = ic.copyAssets(hexo.config.generator_amp.templateDir, hexo.config.generator_amp.assetDistDir, [hexo.config.generator_amp.logo.path, hexo.config.generator_amp.substituteTitleImage.path, avatorDefaultPath, siteLogImagePath]); | ||
if(!copyAssetsStatus)return null; | ||
@@ -34,0 +43,0 @@ |
@@ -5,2 +5,3 @@ | ||
var pathFn = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var absolutePathReg = /^[a-zA-Z0-9]*?\:\/\// | ||
@@ -11,13 +12,17 @@ | ||
var hexoAssetPath = pathFn.join(process.env.PWD , assetDirName); | ||
if(fs.existsSync(hexoAssetPath)){ | ||
return false; | ||
}else{ | ||
var hexoAssetPath_sampleDir = pathFn.join(process.env.PWD , assetDirName , "sample"); | ||
if(!fs.existsSync(hexoAssetPath)){ | ||
//create dir | ||
fs.mkdirSync(hexoAssetPath); | ||
for(var i=0; i< assetFiles.length; i++){ | ||
fs.createReadStream( pathFn.join(__dirname , assetFiles[i]) ).pipe(fs.createWriteStream( pathFn.join(hexoAssetPath , pathFn.basename(assetFiles[i])) )); | ||
mkdirp.sync( hexoAssetPath_sampleDir ); | ||
console.log("\u001b[32m[hexo-generator-amp] (initial copy asset)\u001b[0m asset dir: "+ hexoAssetPath_sampleDir); | ||
} | ||
for(var i=0; i< assetFiles.length; i++){ | ||
if(!fs.existsSync( pathFn.join(hexoAssetPath_sampleDir , pathFn.basename(assetFiles[i])) )){ | ||
mkdirp.sync( pathFn.dirname( pathFn.join(hexoAssetPath_sampleDir , pathFn.basename(assetFiles[i])) )); | ||
fs.createReadStream( pathFn.join(__dirname , assetFiles[i]) ).pipe(fs.createWriteStream( pathFn.join(hexoAssetPath_sampleDir , pathFn.basename(assetFiles[i])) )); | ||
} | ||
console.log("\u001b[32m[hexo-generator-amp] (initial copy asset)\u001b[0m asset dir: "+ hexoAssetPath); | ||
return true; | ||
} | ||
return true; | ||
}; | ||
@@ -29,6 +34,8 @@ | ||
//copy asset dir | ||
if( !fs.existsSync(pathFn.join(process.env.PWD , "source" , distDirName)) )fs.mkdirSync( pathFn.join(process.env.PWD , "source" , distDirName) ); | ||
if( !fs.existsSync(pathFn.join(process.env.PWD , "source" , distDirName)) )mkdirp.sync( pathFn.join(process.env.PWD , "source" , distDirName) ); | ||
for(var i=0; i< copyFiles.length; i++){ | ||
if(fs.existsSync( pathFn.join(hexoAssetPath , copyFiles[i]) )){ | ||
fs.createReadStream( pathFn.join(hexoAssetPath , copyFiles[i]) ).pipe(fs.createWriteStream( pathFn.join(process.env.PWD , "source" , distDirName , pathFn.basename(copyFiles[i])) )); | ||
// fs.createReadStream( pathFn.join(hexoAssetPath , copyFiles[i]) ).pipe(fs.createWriteStream( pathFn.join(process.env.PWD , "source" , distDirName , pathFn.basename(copyFiles[i])) )); | ||
mkdirp.sync( pathFn.dirname( pathFn.join(process.env.PWD , "source" , distDirName , copyFiles[i]))); | ||
fs.createReadStream( pathFn.join(hexoAssetPath , copyFiles[i]) ).pipe(fs.createWriteStream( pathFn.join(process.env.PWD , "source" , distDirName , copyFiles[i]) )); | ||
}else if( absolutePathReg.test(copyFiles[i]) ){ | ||
@@ -35,0 +42,0 @@ // External path |
@@ -24,3 +24,3 @@ 'use strict'; | ||
//------------------------------------ | ||
var ejsTemplateRelativePath = pathFn.basename(config.generator_amp.defaultAssetsPath.ejs); | ||
var ejsTemplateRelativePath = "sample/" + pathFn.basename(config.generator_amp.defaultAssetsPath.ejs); | ||
if(config.generator_amp && config.generator_amp.templateFilePath){ | ||
@@ -41,3 +41,3 @@ ejsTemplateRelativePath = config.generator_amp.templateFilePath; | ||
//------------------------------------ | ||
cssFilePath = pathFn.join(process.env.PWD , config.generator_amp.templateDir, pathFn.basename(config.generator_amp.defaultAssetsPath.css) ); | ||
cssFilePath = pathFn.join(process.env.PWD , config.generator_amp.templateDir, "sample/" + pathFn.basename(config.generator_amp.defaultAssetsPath.css) ); | ||
if(config.generator_amp && config.generator_amp.cssFilePath){ | ||
@@ -72,10 +72,38 @@ cssFilePath = pathFn.join(process.env.PWD , config.generator_amp.templateDir,config.generator_amp.cssFilePath); | ||
//------------------------------------ | ||
//authorDetail.avatar.path | ||
var logoPath_template; | ||
var logoPath_for_amp; | ||
var logoPath_template_width; | ||
var logoPath_template_height; | ||
//site logo image | ||
if(config.generator_amp.logo_topImage && config.generator_amp.logo_topImage.path){ | ||
if(config.generator_amp.logo_topImage.width && config.generator_amp.logo_topImage.height){ | ||
if(absolutePathReg.test(config.generator_amp.logo_topImage.path)){ | ||
logoPath_template = config.generator_amp.logo_topImage.path; | ||
}else{ | ||
logoPath_template = pathFn.join(config.root + config.generator_amp.assetDistDir ,config.generator_amp.logo_topImage.path); | ||
} | ||
logoPath_template_width = config.generator_amp.logo_topImage.width; | ||
logoPath_template_height = config.generator_amp.logo_topImage.height; | ||
}else{ | ||
console.log("\u001b[31m[hexo-generator-amp] (error) Please setting generator_amp.logo_topImage.width and height option. \u001b[0mCheck this the file. : "+"_config.yml" ); | ||
return null; | ||
} | ||
} | ||
//schema.org logo image | ||
if(absolutePathReg.test(config.generator_amp.logo.path)){ | ||
logoPath_template = config.generator_amp.logo.path; | ||
if(!logoPath_template){ | ||
logoPath_template = config.generator_amp.logo.path; | ||
logoPath_template_width = config.generator_amp.logo.width; | ||
logoPath_template_height = config.generator_amp.logo.height; | ||
} | ||
logoPath_for_amp = config.generator_amp.logo.path; | ||
}else{ | ||
logoPath_template = pathFn.join(config.root + config.generator_amp.assetDistDir ,config.generator_amp.logo.path); | ||
if(!logoPath_template){ | ||
logoPath_template = pathFn.join(config.root + config.generator_amp.assetDistDir ,config.generator_amp.logo.path); | ||
logoPath_template_width = config.generator_amp.logo.width; | ||
logoPath_template_height = config.generator_amp.logo.height; | ||
} | ||
logoPath_for_amp = config.url + pathFn.join(config.root, config.generator_amp.assetDistDir ,config.generator_amp.logo.path); | ||
@@ -88,2 +116,3 @@ } | ||
return locals.posts.map(function(post){ | ||
@@ -308,2 +337,4 @@ | ||
logoPath : logoPath_template, | ||
logoPath_width : logoPath_template_width, | ||
logoPath_height : logoPath_template_height, | ||
logoPathForAmp : logoPath_for_amp | ||
@@ -310,0 +341,0 @@ |
{ | ||
"name": "hexo-generator-amp", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"main": "index", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -15,3 +15,3 @@ # hexo-generator-amp | ||
DEMO : [HTML page](https://tea3.github.io/p/hexo-markdown-notation/index.html) | [generated AMP HTML page](https://tea3.github.io/p/hexo-markdown-notation/index.amp.html#development=1) | ||
DEMO : [HTML page](https://tea3.github.io/p/hexo-markdown-notation/index.html) | [generated AMP HTML page](https://tea3.github.io/p/hexo-markdown-notation/amp/index.html#development=1) | ||
@@ -45,7 +45,7 @@ ## Installation | ||
logo: | ||
path: sample-logo.png | ||
path: sample/sample-logo.png | ||
width: 600 | ||
height: 60 | ||
substituteTitleImage: | ||
path: sample-substituteTitleImage.png | ||
path: sample/sample-substituteTitleImage.png | ||
width: 1024 | ||
@@ -81,22 +81,26 @@ height: 800 | ||
logo: | ||
path: sample-logo.png | ||
width: 600 | ||
height: 60 | ||
path: sample/sample-logo.png | ||
width: 600 # width <= 600px | ||
height: 60 # width <= 60px | ||
logo_topImage: #(optional) | ||
path: sample/sample-yoursite-logo.png #(optional) | ||
width: 1024 #(optional) | ||
height: 400 #(optional) | ||
substituteTitleImage: | ||
path: sample-substituteTitleImage.png | ||
width: 1024 | ||
path: sample/sample-substituteTitleImage.png | ||
width: 1024 # width >= 696px | ||
height: 800 | ||
cssFilePath: sample-amp.css #(optional) | ||
templateFilePath: sample-amp.ejs #(optional) | ||
cssFilePath: sample/sample-amp.css #(optional) | ||
templateFilePath: sample/sample-amp.ejs #(optional) | ||
google_analytics: UA-123456789-1 | ||
html_minifier: #(optional) | ||
html_minifier: #(optional) | ||
warningLog: true | ||
authorDetail: | ||
authorReading: Your name description #(optional) | ||
authorReading: Your name description #(optional) | ||
avatar: | ||
path: sample-avator.png #(optional) | ||
width: 150 #(optional) | ||
height: 150 #(optional) | ||
description: Self introduction #(optional) | ||
path: sample/sample-avator.png #(optional) | ||
width: 150 #(optional) | ||
height: 150 #(optional) | ||
description: Self introduction #(optional) | ||
copyright_notice: The footer copyright notice #(optional) | ||
@@ -119,5 +123,9 @@ ``` | ||
- logo | ||
- **logo.path**: File path of a your logo image. | ||
- **logo.width**: Width of a your logo image. ([width <= 600px](https://developers.google.com/structured-data/carousels/top-stories#logo_guidelines)) | ||
- **logo.height**: Height of a your logo image. ([height <= 60px](https://developers.google.com/structured-data/carousels/top-stories#logo_guidelines)) | ||
- **logo.path**: File path of a your logo (schema.org logo for AMP) image. | ||
- **logo.width**: Width of a your logo (schema.org logo for AMP) image. ([width <= 600px](https://developers.google.com/structured-data/carousels/top-stories#logo_guidelines)) | ||
- **logo.height**: Height of a your logo (schema.org logo for AMP) image. ([height <= 60px](https://developers.google.com/structured-data/carousels/top-stories#logo_guidelines)) | ||
- logo_topImage | ||
- **logo_topImage.path**: File path of a your site logo image. | ||
- **logo_topImage.width**: Width of a your site logo image. | ||
- **logo_topImage.height**: Height of a your site logo image. | ||
- substituteTitleImage | ||
@@ -124,0 +132,0 @@ - **substituteTitleImage.path**: File path of a your substitute title image. (Use this when the image is not in the markdown) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
102977
15
2882
194
15