Commit 397674c4 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Fix export not checking amp right for /index.amp (#6748)

* Fix export not checking amp right for /index.amp

* Add test checking hybrid amp index behavior
parent 34be0017
...@@ -14,6 +14,7 @@ export function pageNotFoundError(page: string): Error { ...@@ -14,6 +14,7 @@ export function pageNotFoundError(page: string): Error {
} }
export const tryAmp = (manifest: any, page: string) => { export const tryAmp = (manifest: any, page: string) => {
page = page === '/' ? '/index' : page
const hasAmp = manifest[page + '.amp'] const hasAmp = manifest[page + '.amp']
if (hasAmp) { if (hasAmp) {
page += '.amp' page += '.amp'
......
...@@ -59,7 +59,7 @@ export default async function (dir, options, configuration) { ...@@ -59,7 +59,7 @@ export default async function (dir, options, configuration) {
if (isAmp) { if (isAmp) {
defaultPathMap[path].query = { amp: 1 } defaultPathMap[path].query = { amp: 1 }
const nonAmp = cleanAmpPath(path).replace(/\/$/, '') const nonAmp = cleanAmpPath(path).replace(/\/$/, '') || '/'
if (!defaultPathMap[nonAmp]) { if (!defaultPathMap[nonAmp]) {
defaultPathMap[path].query.ampOnly = true defaultPathMap[path].query.ampOnly = true
} }
......
export default () => (
<p>Simple hybrid amp/non-amp page</p>
)
...@@ -56,4 +56,14 @@ describe('Export with default map', () => { ...@@ -56,4 +56,14 @@ describe('Export with default map', () => {
const $ = cheerio.load(html) const $ = cheerio.load(html)
expect($('link[rel=amphtml]').attr('href')).toBe('/info.amp') expect($('link[rel=amphtml]').attr('href')).toBe('/info.amp')
}) })
it('should export hybrid index amp page correctly', async () => {
expect.assertions(3)
await expect(access(join(outdir, 'index.html'))).resolves.toBe(undefined)
await expect(access(join(outdir, 'index.amp/index.html'))).resolves.toBe(undefined)
const html = await readFile(join(outdir, 'index.html'))
const $ = cheerio.load(html)
expect($('link[rel=amphtml]').attr('href')).toBe('/index.amp')
})
}) })
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