1
0
mirror of synced 2025-12-22 03:16:52 -05:00
Files
docs/lib/redirects/exception-redirects.js
Laura Coursen 8f964ea2cb GHEC version (#20947)
Co-authored-by: Matt Pollard <mattpollard@users.noreply.github.com>
Co-authored-by: Grace Park <gracepark@github.com>
Co-authored-by: Steve Guntrip <12534592+stevecat@users.noreply.github.com>
Co-authored-by: Robert Sese <sese@github.com>
Co-authored-by: Peter Bengtsson <peterbe@github.com>
Co-authored-by: Rachael Sewell <rachmari@github.com>
2021-10-15 15:41:33 -05:00

29 lines
760 B
JavaScript

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
export default function getExceptionRedirects() {
const exceptions = {}
const exceptionRedirectsLines = fs
.readFileSync(path.join(__dirname, './static/redirect-exceptions.txt'), 'utf-8')
.split('\n')
.filter(Boolean)
.map((line) => line.trim())
.filter((line) => !line.startsWith('#'))
let parent = null
for (const line of exceptionRedirectsLines) {
if (line.startsWith('-')) {
if (!parent) {
throw new Error("first line can't start with a `-`")
}
exceptions[line.slice(1).trim()] = parent
} else {
parent = line
}
}
return exceptions
}