59b328b5c3
* Remove client bundles for AMP pages after build since they are not used * Remove trailing white space * Use async-sema to limit removing AMP client bundles * Bring AMP client bundle removing semaphore concurrency down to 20 * Don't check blocked pages when deleting AMP client bundles * Update client bundle removing for AMP pages * Add error handling for removing client AMP pages * rethrow error unless ENOENT during deleting AMP client pages * Handle error during removing AMP client pages the same during dev * Fix throwing instead of rejecting * Make sure next/config is set before requiring page * Update error check * return on reject * Fix next/config
33 lines
819 B
TypeScript
33 lines
819 B
TypeScript
import React from 'react'
|
|
import {AmpModeContext} from './amphtml-context'
|
|
|
|
export function isAmp({
|
|
enabled= false,
|
|
hybrid= false,
|
|
hasQuery= false,
|
|
} = {}) {
|
|
return enabled && (!hybrid || (hybrid && hasQuery))
|
|
}
|
|
|
|
export function useAmp() {
|
|
const ampMode = React.useContext(AmpModeContext)
|
|
// un-comment below to not be considered AMP in dirty mode
|
|
return isAmp(ampMode) // && ampMode.hasQuery
|
|
}
|
|
|
|
export function withAmp(
|
|
Component: any,
|
|
{ hybrid = false } = {},
|
|
): any {
|
|
function WithAmpWrapper(props= {}) {
|
|
const ampMode = React.useContext(AmpModeContext)
|
|
ampMode.enabled = true
|
|
ampMode.hybrid = hybrid
|
|
|
|
return React.createElement(Component, props)
|
|
}
|
|
|
|
WithAmpWrapper.__nextAmpOnly = !hybrid
|
|
WithAmpWrapper.getInitialProps = Component.getInitialProps
|
|
return WithAmpWrapper
|
|
}
|