提交 397674c4 编写于 作者: J JJ Kasper 提交者: 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
上级 34be0017
......@@ -14,6 +14,7 @@ export function pageNotFoundError(page: string): Error {
}
export const tryAmp = (manifest: any, page: string) => {
page = page === '/' ? '/index' : page
const hasAmp = manifest[page + '.amp']
if (hasAmp) {
page += '.amp'
......
......@@ -59,7 +59,7 @@ export default async function (dir, options, configuration) {
if (isAmp) {
defaultPathMap[path].query = { amp: 1 }
const nonAmp = cleanAmpPath(path).replace(/\/$/, '')
const nonAmp = cleanAmpPath(path).replace(/\/$/, '') || '/'
if (!defaultPathMap[nonAmp]) {
defaultPathMap[path].query.ampOnly = true
}
......
export default () => (
<p>Simple hybrid amp/non-amp page</p>
)
......@@ -56,4 +56,14 @@ describe('Export with default map', () => {
const $ = cheerio.load(html)
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册