Commit b7efb3ff authored by Liran Cohen's avatar Liran Cohen Committed by JJ Kasper

Allow manually setting amphtml (#9098)

* allow to remove amphtml from desktop page

* only 1 link with amphtml rel

* clean up

* remove checkup for amphtml link

* Dedupe looping
parent 499808fa
...@@ -273,19 +273,17 @@ export class Head extends Component< ...@@ -273,19 +273,17 @@ export class Head extends Component<
let hasCanonicalRel = false let hasCanonicalRel = false
// show warning and remove conflicting amp head tags // show warning and remove conflicting amp head tags
head = !inAmpMode head = React.Children.map(head || [], child => {
? head
: React.Children.map(head || [], child => {
if (!child) return child if (!child) return child
const { type, props } = child const { type, props } = child
if (inAmpMode) {
let badProp: string = '' let badProp: string = ''
if (type === 'meta' && props.name === 'viewport') { if (type === 'meta' && props.name === 'viewport') {
badProp = 'name="viewport"' badProp = 'name="viewport"'
} else if (type === 'link' && props.rel === 'canonical') { } else if (type === 'link' && props.rel === 'canonical') {
hasCanonicalRel = true hasCanonicalRel = true
} else if (type === 'link' && props.rel === 'amphtml') {
hasAmphtmlRel = true
} else if (type === 'script') { } else if (type === 'script') {
// only block if // only block if
// 1. it has a src and isn't pointing to ampproject's CDN // 1. it has a src and isn't pointing to ampproject's CDN
...@@ -314,6 +312,12 @@ export class Head extends Component< ...@@ -314,6 +312,12 @@ export class Head extends Component<
) )
return null return null
} }
} else {
// non-amp mode
if (type === 'link' && props.rel === 'amphtml') {
hasAmphtmlRel = true
}
}
return child return child
}) })
......
...@@ -200,6 +200,7 @@ describe('AMP Usage', () => { ...@@ -200,6 +200,7 @@ describe('AMP Usage', () => {
const html = await renderViaHTTP(appPort, '/manual-rels') const html = await renderViaHTTP(appPort, '/manual-rels')
const $ = cheerio.load(html) const $ = cheerio.load(html)
expect($('link[rel=amphtml]').attr('href')).toBe('/my-custom-amphtml') expect($('link[rel=amphtml]').attr('href')).toBe('/my-custom-amphtml')
expect($('link[rel=amphtml]')).toHaveLength(1)
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment