Unverified Commit 5e55c3c3 authored by Oleg Zuev's avatar Oleg Zuev Committed by GitHub

Remove useless async declaration and replace regexp to plain string in AMP postProcessor (#42495)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent fcfe914b
...@@ -22,6 +22,10 @@ type middlewareSignature = { ...@@ -22,6 +22,10 @@ type middlewareSignature = {
condition: ((options: postProcessOptions) => boolean) | null condition: ((options: postProcessOptions) => boolean) | null
} }
type PostProcessorFunction =
| ((html: string) => Promise<string>)
| ((html: string) => string)
const middlewareRegistry: Array<middlewareSignature> = [] const middlewareRegistry: Array<middlewareSignature> = []
function registerPostProcessor( function registerPostProcessor(
...@@ -175,7 +179,7 @@ async function postProcessHTML( ...@@ -175,7 +179,7 @@ async function postProcessHTML(
renderOpts: RenderOpts, renderOpts: RenderOpts,
{ inAmpMode, hybridAmp }: { inAmpMode: boolean; hybridAmp: boolean } { inAmpMode, hybridAmp }: { inAmpMode: boolean; hybridAmp: boolean }
) { ) {
const postProcessors: Array<(html: string) => Promise<string>> = [ const postProcessors: Array<PostProcessorFunction> = [
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode process.env.NEXT_RUNTIME !== 'edge' && inAmpMode
? async (html: string) => { ? async (html: string) => {
const optimizeAmp = require('./optimize-amp') const optimizeAmp = require('./optimize-amp')
...@@ -226,8 +230,8 @@ async function postProcessHTML( ...@@ -226,8 +230,8 @@ async function postProcessHTML(
} }
: null, : null,
inAmpMode || hybridAmp inAmpMode || hybridAmp
? async (html: string) => { ? (html: string) => {
return html.replace(/&amp;amp=1/g, '&amp=1') return html.replaceAll('&amp;amp=1', '&amp=1')
} }
: null, : null,
].filter(nonNullable) ].filter(nonNullable)
......
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