diff --git a/src/article-transforms.ts b/src/article-transforms.ts index cfc3f22..1a5c972 100644 --- a/src/article-transforms.ts +++ b/src/article-transforms.ts @@ -130,3 +130,31 @@ export const reworkScriptSrcs = ( attribs.src = src } } + +export const reworkRedirect = ( + $html: any, + selector = 'meta[http-equiv="refresh"]', + fns: ((href: string) => string)[] = [ + moveRelativeLinksDownOneLevel + ] +) => { + const redirects = $html(selector) + + for (const redirect of Object.values(redirects)) { + const attribs = redirect.attribs + + if (!attribs || !attribs.content) { + continue + } + + let { content } = attribs + + let [ delay, url ] = content.split(';url=') + + for (const fn of fns) { + url = fn(url) + } + + attribs.content = `${delay};url=${url}` + } +} diff --git a/src/site-transforms.ts b/src/site-transforms.ts index 1fea720..8dfdc2d 100644 --- a/src/site-transforms.ts +++ b/src/site-transforms.ts @@ -28,7 +28,8 @@ import { moveRelativeLinksDownOneLevel, prefixRelativeRoot, reworkLinks, - reworkScriptSrcs + reworkScriptSrcs, + reworkRedirect } from './article-transforms' import { Directories, Options } from './domain' import { downloadFile } from './utils/download-file' @@ -151,6 +152,7 @@ export const fixExceptions = async ({ reworkLinks($fileHtml, 'link[href^="../"]', linkFixups) reworkScriptSrcs($fileHtml, 'img', linkFixups) reworkScriptSrcs($fileHtml, 'script', linkFixups) + reworkRedirect($fileHtml, 'meta[http-equiv="refresh"]', linkFixups) // console.log(` fixed relative paths in ${filePath}`) // renameSync(filePath, `${filePath}.original`)