Skip to content

Commit 17c2bbb

Browse files
authored
Merge pull request #3806 from curbengh/https-iframe
refactor(iframe_tags): utilize htmlTag function
2 parents b9ad605 + 6f55e6b commit 17c2bbb

8 files changed

Lines changed: 63 additions & 21 deletions

File tree

lib/plugins/tag/iframe.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
'use strict';
22

3+
const { htmlTag } = require('hexo-util');
4+
35
/**
46
* Iframe tag
57
*
68
* Syntax:
79
* {% iframe url [width] [height] %}
810
*/
911

10-
function iframeTag(args, content) {
11-
const url = args[0];
12+
function iframeTag(args) {
13+
const src = args[0];
1214
const width = args[1] && args[1] !== 'default' ? args[1] : '100%';
1315
const height = args[2] && args[2] !== 'default' ? args[2] : '300';
1416

15-
return `<iframe src="${url}" width="${width}" height="${height}" frameborder="0" loading="lazy" allowfullscreen></iframe>`;
17+
const attrs = {
18+
src,
19+
width,
20+
height,
21+
frameborder: '0',
22+
loading: 'lazy',
23+
allowfullscreen: true
24+
};
25+
26+
return htmlTag('iframe', attrs, '');
1627
}
1728

1829
module.exports = iframeTag;

lib/plugins/tag/jsfiddle.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
'use strict';
22

3+
const { htmlTag } = require('hexo-util');
4+
35
/**
46
* jsFiddle tag
57
*
68
* Syntax:
79
* {% jsfiddle shorttag [tabs] [skin] [height] [width] %}
810
*/
911

10-
function jsfiddleTag(args, content) {
12+
function jsfiddleTag(args) {
1113
const id = args[0];
1214
const tabs = args[1] && args[1] !== 'default' ? args[1] : 'js,resources,html,css,result';
1315
const skin = args[2] && args[2] !== 'default' ? args[2] : 'light';
1416
const width = args[3] && args[3] !== 'default' ? args[3] : '100%';
1517
const height = args[4] && args[4] !== 'default' ? args[4] : '300';
18+
const src = `https://jsfiddle.net/${id}/embedded/${tabs}/${skin}`;
19+
20+
const attrs = {
21+
scrolling: 'no',
22+
width,
23+
height,
24+
src,
25+
frameborder: '0',
26+
loading: 'lazy',
27+
allowfullscreen: true
28+
};
1629

17-
return `<iframe scrolling="no" width="${width}" height="${height}" src="//jsfiddle.net/${id}/embedded/${tabs}/${skin}" frameborder="0" loading="lazy" allowfullscreen></iframe>`;
30+
return htmlTag('iframe', attrs, '');
1831
}
1932

2033
module.exports = jsfiddleTag;

lib/plugins/tag/vimeo.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
'use strict';
22

3+
const { htmlTag } = require('hexo-util');
4+
35
/**
46
* Vimeo tag
57
*
68
* Syntax:
79
* {% vimeo video_id %}
810
*/
911

10-
function vimeoTag(args, content) {
11-
const id = args[0];
12+
function vimeoTag(id) {
13+
const src = 'https://player.vimeo.com/video/' + id;
14+
15+
const iframeTag = htmlTag('iframe', {
16+
src,
17+
frameborder: '0',
18+
loading: 'lazy',
19+
allowfullscreen: true
20+
}, '');
1221

13-
return `<div class="video-container"><iframe src="//player.vimeo.com/video/${id}" frameborder="0" loading="lazy" allowfullscreen></iframe></div>`;
22+
return htmlTag('div', { class: 'video-container' }, iframeTag, false);
1423
}
1524

1625
module.exports = vimeoTag;

lib/plugins/tag/youtube.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
'use strict';
22

3+
const { htmlTag } = require('hexo-util');
4+
35
/**
46
* Youtube tag
57
*
68
* Syntax:
79
* {% youtube video_id %}
810
*/
911

10-
function youtubeTag(args, content) {
11-
const id = args[0];
12+
function youtubeTag(id) {
13+
const src = 'https://www.youtube.com/embed/' + id;
14+
15+
const iframeTag = htmlTag('iframe', {
16+
src,
17+
frameborder: '0',
18+
loading: 'lazy',
19+
allowfullscreen: true
20+
}, '');
1221

13-
return `<div class="video-container"><iframe src="//www.youtube.com/embed/${id}" frameborder="0" loading="lazy" allowfullscreen></iframe></div>`;
22+
return htmlTag('div', { class: 'video-container' }, iframeTag, false);
1423
}
1524

1625
module.exports = youtubeTag;

test/scripts/tags/iframe.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('iframe', () => {
88
it('url', () => {
99
const $ = cheerio.load(iframe(['https://zespia.tw']));
1010

11-
$('iframe').attr('src').should.eql('https://zespia.tw');
11+
$('iframe').attr('src').should.eql('https://zespia.tw/');
1212
$('iframe').attr('width').should.eql('100%');
1313
$('iframe').attr('height').should.eql('300');
1414
$('iframe').attr('frameborder').should.eql('0');
@@ -19,7 +19,7 @@ describe('iframe', () => {
1919
it('width', () => {
2020
const $ = cheerio.load(iframe(['https://zespia.tw', '500']));
2121

22-
$('iframe').attr('src').should.eql('https://zespia.tw');
22+
$('iframe').attr('src').should.eql('https://zespia.tw/');
2323
$('iframe').attr('width').should.eql('500');
2424
$('iframe').attr('height').should.eql('300');
2525
$('iframe').attr('frameborder').should.eql('0');
@@ -30,7 +30,7 @@ describe('iframe', () => {
3030
it('height', () => {
3131
const $ = cheerio.load(iframe(['https://zespia.tw', '500', '600']));
3232

33-
$('iframe').attr('src').should.eql('https://zespia.tw');
33+
$('iframe').attr('src').should.eql('https://zespia.tw/');
3434
$('iframe').attr('width').should.eql('500');
3535
$('iframe').attr('height').should.eql('600');
3636
$('iframe').attr('frameborder').should.eql('0');

test/scripts/tags/jsfiddle.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ describe('jsfiddle', () => {
88
it('id', () => {
99
const $ = cheerio.load(jsfiddle(['foo']));
1010

11-
$('iframe').attr('src').should.eql('//jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
11+
$('iframe').attr('src').should.eql('https://jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
1212
});
1313

1414
it('tabs', () => {
1515
let $ = cheerio.load(jsfiddle(['foo', 'default']));
1616

17-
$('iframe').attr('src').should.eql('//jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
17+
$('iframe').attr('src').should.eql('https://jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
1818

1919
$ = cheerio.load(jsfiddle(['foo', 'html,css']));
2020

21-
$('iframe').attr('src').should.eql('//jsfiddle.net/foo/embedded/html,css/light');
21+
$('iframe').attr('src').should.eql('https://jsfiddle.net/foo/embedded/html,css/light');
2222
});
2323

2424
it('skin', () => {
2525
let $ = cheerio.load(jsfiddle(['foo', 'default', 'default']));
2626

27-
$('iframe').attr('src').should.eql('//jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
27+
$('iframe').attr('src').should.eql('https://jsfiddle.net/foo/embedded/js,resources,html,css,result/light');
2828

2929
$ = cheerio.load(jsfiddle(['foo', 'default', 'dark']));
3030

31-
$('iframe').attr('src').should.eql('//jsfiddle.net/foo/embedded/js,resources,html,css,result/dark');
31+
$('iframe').attr('src').should.eql('https://jsfiddle.net/foo/embedded/js,resources,html,css,result/dark');
3232
});
3333

3434
it('width', () => {

test/scripts/tags/vimeo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('vimeo', () => {
99
const $ = cheerio.load(vimeo(['foo']));
1010

1111
$('.video-container').html().should.be.ok;
12-
$('iframe').attr('src').should.eql('//player.vimeo.com/video/foo');
12+
$('iframe').attr('src').should.eql('https://player.vimeo.com/video/foo');
1313
$('iframe').attr('frameborder').should.eql('0');
1414
$('iframe').attr('allowfullscreen').should.eql('');
1515
$('iframe').attr('loading').should.eql('lazy');

test/scripts/tags/youtube.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('youtube', () => {
99
const $ = cheerio.load(youtube(['foo']));
1010

1111
$('.video-container').html().should.be.ok;
12-
$('iframe').attr('src').should.eql('//www.youtube.com/embed/foo');
12+
$('iframe').attr('src').should.eql('https://www.youtube.com/embed/foo');
1313
$('iframe').attr('frameborder').should.eql('0');
1414
$('iframe').attr('allowfullscreen').should.eql('');
1515
$('iframe').attr('loading').should.eql('lazy');

0 commit comments

Comments
 (0)