Skip to content

Commit 348e4f5

Browse files
feat: handle more the meta tag with the property attribute (social networks markup)
1 parent 4e41876 commit 348e4f5

File tree

11 files changed

+599
-84
lines changed

11 files changed

+599
-84
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Supported tags and attributes:
8686
- the `xlink:href` attribute of the `use` tag
8787
- the `href` attribute of the `use` tag
8888
- the `href` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`
89-
- the `content` attribute of the `meta` tag when the `name` attribute is `msapplication-tileimage`, `msapplication-square70x70logo`, `msapplication-square150x150logo`, `msapplication-wide310x150logo`, `msapplication-square310x310logo`, `msapplication-config`
89+
- the `content` attribute of the `meta` tag when the `name` attribute is `msapplication-tileimage`, `msapplication-square70x70logo`, `msapplication-square150x150logo`, `msapplication-wide310x150logo`, `msapplication-square310x310logo`, `msapplication-config` or when the `property` attribute is `og:image`, `og:image:url`, `og:image:secure_url`, `og:audio`, `og:audio:secure_url`, `og:video`, `og:video:secure_url`, `vk:image`
9090

9191
#### `Boolean`
9292

src/utils.js

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ function getAttributeValue(attributes, name) {
428428
return attributes[lowercasedAttributes[name.toLowerCase()]];
429429
}
430430

431-
// TODO refactor
432431
function scriptSrcFilter(tag, attribute, attributes) {
433432
let type = getAttributeValue(attributes, 'type');
434433

@@ -484,29 +483,54 @@ function linkHrefFilter(tag, attribute, attributes) {
484483
function metaContentFilter(tag, attribute, attributes) {
485484
let name = getAttributeValue(attributes, 'name');
486485

487-
if (!name) {
488-
return false;
489-
}
486+
if (name) {
487+
name = name.trim();
488+
489+
if (!name) {
490+
return false;
491+
}
490492

491-
name = name.trim();
493+
name = name.toLowerCase();
492494

493-
if (!name) {
494-
return false;
495+
const allowedNames = [
496+
// msapplication-TileImage
497+
'msapplication-tileimage',
498+
'msapplication-square70x70logo',
499+
'msapplication-square150x150logo',
500+
'msapplication-wide310x150logo',
501+
'msapplication-square310x310logo',
502+
'msapplication-config',
503+
];
504+
505+
return allowedNames.includes(name);
495506
}
496507

497-
name = name.toLowerCase();
508+
let property = getAttributeValue(attributes, 'property');
498509

499-
const allowedNames = [
500-
// msapplication-TileImage
501-
'msapplication-tileimage',
502-
'msapplication-square70x70logo',
503-
'msapplication-square150x150logo',
504-
'msapplication-wide310x150logo',
505-
'msapplication-square310x310logo',
506-
'msapplication-config',
507-
];
510+
if (property) {
511+
property = property.trim();
512+
513+
if (!property) {
514+
return false;
515+
}
516+
517+
property = property.toLowerCase();
518+
519+
const allowedProperties = [
520+
'og:image',
521+
'og:image:url',
522+
'og:image:secure_url',
523+
'og:audio',
524+
'og:audio:secure_url',
525+
'og:video',
526+
'og:video:secure_url',
527+
'vk:image',
528+
];
529+
530+
return allowedProperties.includes(property);
531+
}
508532

509-
return allowedNames.includes(name);
533+
return false;
510534
}
511535

512536
const defaultAttributes = [

test/__snapshots__/attributes-option.test.js.snap

Lines changed: 316 additions & 32 deletions
Large diffs are not rendered by default.

test/__snapshots__/esModule-option.test.js.snap

Lines changed: 84 additions & 9 deletions
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

Lines changed: 28 additions & 3 deletions
Large diffs are not rendered by default.

test/__snapshots__/minimize-option.test.js.snap

Lines changed: 102 additions & 15 deletions
Large diffs are not rendered by default.

test/attributes-option.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe("'attributes' option", () => {
280280
],
281281
},
282282
{
283-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|css|xml)$/i,
283+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|webp|xml|webmanifest|mp3|mp4|css)$/i,
284284
loader: 'file-loader',
285285
options: { esModule: false, name: '[name].[ext]' },
286286
},
@@ -315,7 +315,7 @@ describe("'attributes' option", () => {
315315
],
316316
},
317317
{
318-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|css|xml)$/i,
318+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|webp|xml|webmanifest|mp3|mp4|css)$/i,
319319
loader: 'file-loader',
320320
options: { esModule: true, name: '[name].[ext]' },
321321
},
@@ -350,7 +350,7 @@ describe("'attributes' option", () => {
350350
],
351351
},
352352
{
353-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|css|xml)$/i,
353+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|webp|xml|webmanifest|mp3|mp4|css)$/i,
354354
loader: 'file-loader',
355355
options: { esModule: false, name: '[name].[ext]' },
356356
},
@@ -385,7 +385,7 @@ describe("'attributes' option", () => {
385385
],
386386
},
387387
{
388-
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|css|xml)$/i,
388+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|ogg|pdf|vtt|webp|xml|webmanifest|mp3|mp4|css)$/i,
389389
loader: 'file-loader',
390390
options: { esModule: true, name: '[name].[ext]' },
391391
},

test/fixtures/simple.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,24 @@ <h2>An Ordered HTML List</h2>
386386
<meta name="msapplication-TileImage" content="./image.png">
387387
<meta name="msapplication-config" content="./browserconfig.xml">
388388
<meta name="theme-color" content="#ffffff">
389-
<meta content="name=Check Order Status;action-uri=./orderStatus.aspx?src=IE9;icon-uri=./favicon.ico" name="msapplication-task">
389+
<meta content="name=Check Order Status;action-uri=./orderStatus.aspx?src=IE9;icon-uri=./favicon.ico" name="msapplication-task">
390+
391+
<meta property="og:url" content="http://www.nytimes.com/2015/02/19/arts/international/when-great-minds-dont-think-alike.html" />
392+
<meta property="og:type" content="article" />
393+
<meta property="og:title" content="When Great Minds Don’t Think Alike" />
394+
<meta property="og:description" content="How much does culture influence creative thinking?" />
395+
<meta property="og:image" content="./image.png" />
396+
<meta property="og:image:url" content="./image.png" />
397+
<meta property="og:image:secure_url" content="./image.png" />
398+
399+
<meta property="og:audio" content="./sound.mp3" />
400+
<meta property="og:audio:secure_url" content="./sound.mp3" />
401+
<meta property="og:audio:type" content="audio/mpeg" />
402+
403+
<meta property="og:video" content="./video.mp4" />
404+
<meta property="og:video:secure_url" content="./video.mp4" />
405+
<meta property="og:video:type" content="video/mp4" />
406+
<meta property="og:video:width" content="400" />
407+
<meta property="og:video:height" content="300" />
408+
409+
<meta property="vk:image" content="./image.png" />

test/fixtures/sound.mp3

Whitespace-only changes.

test/fixtures/video.mp4

Whitespace-only changes.

0 commit comments

Comments
 (0)