2019-04-24 16:47:50 +02:00
|
|
|
import { BLOCKED_PAGES } from '../lib/constants'
|
2018-11-18 20:44:50 +01:00
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
const internalPrefixes = [/^\/_next\//, /^\/static\//]
|
2018-10-02 00:55:31 +02:00
|
|
|
|
2018-12-31 14:44:27 +01:00
|
|
|
export function isInternalUrl(url: string): boolean {
|
2018-10-02 00:55:31 +02:00
|
|
|
for (const prefix of internalPrefixes) {
|
|
|
|
if (prefix.test(url)) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2018-11-18 20:44:50 +01:00
|
|
|
|
2018-12-31 14:44:27 +01:00
|
|
|
export function isBlockedPage(pathname: string): boolean {
|
2019-05-29 13:57:26 +02:00
|
|
|
return BLOCKED_PAGES.indexOf(pathname) !== -1
|
2018-11-18 20:44:50 +01:00
|
|
|
}
|
2019-03-20 04:53:47 +01:00
|
|
|
|
|
|
|
export function cleanAmpPath(pathname: string): string {
|
2019-04-15 11:26:23 +02:00
|
|
|
if (pathname.match(/\?amp=(y|yes|true|1)/)) {
|
2019-11-10 21:44:15 +01:00
|
|
|
pathname = pathname.replace(/\?amp=(y|yes|true|1)&?/, '?')
|
2019-04-15 11:26:23 +02:00
|
|
|
}
|
|
|
|
if (pathname.match(/&=(y|yes|true|1)/)) {
|
2019-11-10 21:44:15 +01:00
|
|
|
pathname = pathname.replace(/&=(y|yes|true|1)/, '')
|
2019-04-15 11:26:23 +02:00
|
|
|
}
|
|
|
|
pathname = pathname.replace(/\?$/, '')
|
|
|
|
return pathname
|
2019-03-20 04:53:47 +01:00
|
|
|
}
|