-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(seo): add support for alternate links (#26)
- add support for <link rel=alternate /> tags - can be used to point to pages in alternate languages and locales - https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel#attr-alternate
- Loading branch information
1 parent
531e9d5
commit af7b5a3
Showing
8 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2020 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express | ||
* or implied. See the License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import getAlternateLinks from '../../src/utils/getAlternateLinks'; | ||
|
||
describe('getAlternateLinks', () => { | ||
it('should add the rel: alternate key value pair to entires', () => { | ||
const mockData = [ | ||
{ hreflang: 'en-CA', href: 'https://example.com/en-CA' }, | ||
{ hreflang: 'fr-CA', href: 'https://example.com/fr-CA' }, | ||
]; | ||
|
||
expect(getAlternateLinks(mockData)).toEqual([ | ||
{ rel: 'alternate', hreflang: 'en-CA', href: 'https://example.com/en-CA' }, | ||
{ rel: 'alternate', hreflang: 'fr-CA', href: 'https://example.com/fr-CA' }, | ||
]); | ||
}); | ||
|
||
it('should return an empty array if incorrect inputs are supplied', () => { | ||
expect(getAlternateLinks(null)).toEqual([]); | ||
expect(getAlternateLinks(undefined)).toEqual([]); | ||
expect(getAlternateLinks('string')).toEqual([]); | ||
expect(getAlternateLinks(1)).toEqual([]); | ||
expect(getAlternateLinks({ hreflang: 'en-CA', href: 'https://example.com/en-CA' })).toEqual([]); | ||
}); | ||
|
||
it('should return an empty array if an empty array is supplied', () => { | ||
expect(getAlternateLinks([])).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2020 American Express Travel Related Services Company, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express | ||
* or implied. See the License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
function getAlternateLinks(alternateLinks) { | ||
if (!alternateLinks || !Array.isArray(alternateLinks)) { | ||
return []; | ||
} | ||
|
||
return alternateLinks.map((x) => ({ rel: 'alternate', ...x })); | ||
} | ||
|
||
export default getAlternateLinks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters