metalsmith-youtube
Advanced tools
Comparing version 0.0.1-alpha-290816 to 1.0.0
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -32,5 +34,4 @@ | ||
function plugin(_options) { | ||
var options = options || {}; | ||
var options = _options || {}; | ||
return function (files, metalsmith, done) { | ||
//setImmediate(done); | ||
var metadata = metalsmith.metadata(); | ||
@@ -58,4 +59,7 @@ var collections = metadata.collections; | ||
privacy: options.privacy || true, | ||
controls: options.controls || true | ||
controls: options.controls || true, | ||
width: 560, | ||
height: 315 | ||
}; | ||
_extends(this.options, options); | ||
} | ||
@@ -68,4 +72,13 @@ | ||
var self = this; | ||
Object.keys(this.files).forEach(function (file) { | ||
console.log('file', file, _this.files[file].youtube); | ||
var article_text = _this.files[file].contents.toString(); | ||
var matches = _this._getYoutubes(article_text); | ||
if (matches !== null) { | ||
matches.forEach(function (element, index) { | ||
var id = element.split('|')[1]; | ||
var iframe = _this._createIframeBody(id, _this.options.width, _this.options.height); | ||
_this.files[file].contents = article_text.replace(element, iframe); | ||
}); | ||
} | ||
}); | ||
@@ -75,5 +88,20 @@ cb(); | ||
}, { | ||
key: '_getYoutubes', | ||
value: function _getYoutubes(content) { | ||
return content.match(/youtube\|.\S*/g); | ||
} | ||
}, { | ||
key: '_createIframeBody', | ||
value: function _createIframeBody() { | ||
// <iframe width="1280" height="720" src="https://www.youtube.com/embed/Q_Gjvvxi2jU" frameborder="0" allowfullscreen></iframe> | ||
value: function _createIframeBody(id, width, height) { | ||
var url = void 0; | ||
if (this.options.privacy) { | ||
url = 'https://www.youtube-nocookie.com/embed/' + id; | ||
} else { | ||
url = 'https://www.youtube.com/embed/' + id; | ||
} | ||
url += this.options.suggested ? '?rel=0&' : '?'; | ||
url += this.options.showTitle ? '&showinfo=0' : ''; | ||
url += this.options.controls ? '&controls=0' : ''; | ||
var iframe = '<iframe width="' + width + '" height="' + height + '" src="' + url + '" frameborder="0" allowfullscreen></iframe>'; | ||
return iframe; | ||
} | ||
@@ -80,0 +108,0 @@ }]); |
{ | ||
"name": "metalsmith-youtube", | ||
"version": "0.0.1-alpha-290816", | ||
"version": "1.0.0", | ||
"description": "A Metalsmith plugin that lets you get embed Youtube Videos", | ||
@@ -8,6 +8,11 @@ "main": "lib/index.js", | ||
"build": "babel src -d lib", | ||
"build:w": "babel src -d lib --watch", | ||
"prepublish": "npm run build", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": ["metalsmith", "youtube", "plugin"], | ||
"keywords": [ | ||
"metalsmith", | ||
"youtube", | ||
"plugin" | ||
], | ||
"author": "Juan Picado <juanpicado19@gmail.com> (https://www.jotadeveloper.com/)", | ||
@@ -18,3 +23,3 @@ "license": "MIT", | ||
}, | ||
"files" : [ | ||
"files": [ | ||
"lib", | ||
@@ -25,2 +30,3 @@ "package.json" | ||
"babel-cli": "^6.16.0", | ||
"babel-plugin-transform-object-assign": "^6.8.0", | ||
"babel-polyfill": "^6.16.0", | ||
@@ -27,0 +33,0 @@ "babel-preset-es2015": "^6.16.0" |
@@ -17,2 +17,4 @@ # metalsmith-youtube | ||
metalsmith.use(youtube({ | ||
width: 560, // optional, width video (default 560) | ||
height: 315, // optional, height video (default 560) | ||
suggested: true, // optional, display suggested videos | ||
@@ -32,9 +34,4 @@ controls: true, // optional, display controls | ||
Hello World | ||
## youtube url | ||
youtube:https://www.youtube.com/watch?v=hWhMKalEic8 | ||
## only the id | ||
youtube:hWhMKalEic8 | ||
youtube|hWhMKalEic8 | ||
@@ -50,6 +47,8 @@ ``` | ||
"metalsmith-youtube": { | ||
"width:": "560", | ||
"height": "315", | ||
"suggested": "true", | ||
"controls": "true", | ||
"controls": "true", | ||
"showTitle": "true", | ||
"privacy" : "true" | ||
"privacy" : "true" | ||
} | ||
@@ -56,0 +55,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5587
91
2
4
59