Skip to content

Commit

Permalink
fix(getTwitterCardTags): summary_large_image twitter card type
Browse files Browse the repository at this point in the history
This change fixes support for summary_large_image Twitter Card type
which was incorrectly defined as summary_with_large_image.

Closes #24
  • Loading branch information
Jonathan Golden committed Aug 17, 2020
1 parent 4b17979 commit 1cb41fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
54 changes: 54 additions & 0 deletions __tests__/utils/getTwitterCardTags.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

import getTwitterCardTags from '../../src/utils/getTwitterCardTags';

global.console = {
warn: jest.fn(),
};

describe('getTwitterCardTags', () => {
describe('summary card', () => {
it('should provide the tags for a summary card', () => {
Expand All @@ -40,6 +44,56 @@ describe('getTwitterCardTags', () => {
});
});

describe('summary with large image card', () => {
it('should provide the tags for a summary with large image card', () => {
const config = {
card: 'summary_large_image',
site: '@Example',
title: 'Some title',
description: 'Some description',
image: {
src: 'http://example.com/ogp.jpg',
alt: 'A shiny red apple with a bite taken out',
},
irrelevantProperty: 'foo',
};

expect(getTwitterCardTags(config)).toEqual([
{ name: 'twitter:card', content: 'summary_large_image' },
{ name: 'twitter:site', content: '@Example' },
{ name: 'twitter:title', content: 'Some title' },
{ name: 'twitter:description', content: 'Some description' },
{ name: 'twitter:image', content: 'http://example.com/ogp.jpg' },
{ name: 'twitter:image:alt', content: 'A shiny red apple with a bite taken out' },
]);
});

it('should warn about deprecation of summary_with_large_image', () => {
const config = {
card: 'summary_with_large_image',
site: '@Example',
title: 'Some title',
description: 'Some description',
image: {
src: 'http://example.com/ogp.jpg',
alt: 'A shiny red apple with a bite taken out',
},
irrelevantProperty: 'foo',
};

expect(getTwitterCardTags(config)).toEqual([
{ name: 'twitter:card', content: 'summary_large_image' },
{ name: 'twitter:site', content: '@Example' },
{ name: 'twitter:title', content: 'Some title' },
{ name: 'twitter:description', content: 'Some description' },
{ name: 'twitter:image', content: 'http://example.com/ogp.jpg' },
{ name: 'twitter:image:alt', content: 'A shiny red apple with a bite taken out' },
]);

expect(global.console.warn).toHaveBeenCalled();
});
});

describe('player card', () => {
it('should provide the tags for a player card', () => {
const config = {
Expand Down
14 changes: 13 additions & 1 deletion src/utils/getTwitterCardTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ const schemas = {
player: TWITTER_PLAYER_CARD_SCHEMA,
app: TWITTER_APP_CARD_SCHEMA,
summary: TWITTER_SUMMARY_CARD_SCHEMA,
summary_with_large_image: TWITTER_SUMMARY_CARD_SCHEMA,
summary_large_image: TWITTER_SUMMARY_CARD_SCHEMA,
};

const getTwitterCardTags = (tags) => {
if (tags.card === 'summary_with_large_image') {
// eslint-disable-next-line no-console
console.warn(
'summary_with_large_image is deprecated and will be removed in the next major release. Please use summary_large_image instead. See https://github.com/americanexpress/react-seo/issues/24 for more information'
);

return getTagsFromSchema(schemas.summary_large_image, {
...tags,
card: 'summary_large_image',
});
}

if (schemas[tags.card]) {
return getTagsFromSchema(schemas[tags.card], tags);
}
Expand Down

0 comments on commit 1cb41fc

Please sign in to comment.