@@ -9,7 +9,6 @@ const host = `http://localhost:${port}`
99const scrape = require ( 'website-scraper' )
1010const program = require ( 'commander' )
1111const rimraf = require ( 'rimraf' ) . sync
12- const mkdirp = require ( 'mkdirp' ) . sync
1312const version = require ( '../../lib/enterprise-server-releases' ) . oldestSupported
1413const archivalRepoName = 'help-docs-archived-enterprise-versions'
1514const archivalRepoUrl = `https://github.com/github/${ archivalRepoName } `
@@ -173,18 +172,20 @@ async function main () {
173172 console . log ( `\n\ndone scraping! added files to ${ path . relative ( process . cwd ( ) , finalDirectory ) } \n` )
174173
175174 // create redirect html files to preserve frontmatter redirects
176- await createRedirectPages ( permalinksPerVersion , pageMap , finalDirectory )
175+ await createRedirectsFile ( permalinksPerVersion , pageMap , finalDirectory )
177176
178177 console . log ( `next step: deprecate ${ version } in lib/enterprise-server-releases.js` )
179178
180179 process . exit ( )
181180 } )
182181}
183182
184- async function createRedirectPages ( permalinks , pageMap , finalDirectory ) {
183+ async function createRedirectsFile ( permalinks , pageMap , finalDirectory ) {
185184 const pagesPerVersion = permalinks . map ( permalink => pageMap [ permalink ] )
186185 const redirects = await loadRedirects ( pagesPerVersion , pageMap )
187186
187+ const redirectsPerVersion = { }
188+
188189 Object . entries ( redirects ) . forEach ( ( [ oldPath , newPath ] ) => {
189190 // remove any liquid variables that sneak in
190191 oldPath = oldPath
@@ -193,31 +194,8 @@ async function createRedirectPages (permalinks, pageMap, finalDirectory) {
193194 // ignore any old paths that are not in this version
194195 if ( ! ( oldPath . includes ( `/enterprise-server@${ version } ` ) || oldPath . includes ( `/enterprise/${ version } ` ) ) ) return
195196
196- const fullPath = path . join ( finalDirectory , oldPath )
197- const filename = `${ fullPath } /index.html`
198- const html = getRedirectHtml ( newPath )
199-
200- mkdirp ( fullPath )
201- fs . writeFileSync ( filename , html )
197+ redirectsPerVersion [ oldPath ] = newPath
202198 } )
203199
204- console . log ( 'done creating redirect files!\n' )
205- }
206-
207- // redirect html files already exist in <=2.12 because these versions were deprecated on the old static site
208- function getRedirectHtml ( newPath ) {
209- return `<!DOCTYPE html>
210- <html>
211- <head>
212- <meta charset="utf-8">
213- <title>Redirecting...</title>
214- <link rel="canonical" href="${ newPath } ">
215- <meta http-equiv="refresh" content="0; url=${ newPath } ">
216- </head>
217- <body>
218- <h1>Redirecting...</h1>
219- <a href="${ newPath } ">Click here if you are not redirected.</a>
220- <script>location='${ newPath } '</script>
221- </body>
222- </html>`
200+ fs . writeFileSync ( path . posix . join ( finalDirectory , 'redirects.json' ) , JSON . stringify ( redirectsPerVersion , null , 2 ) )
223201}
0 commit comments