File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { config } from '@/client_config.js'
2+
3+ export async function redirectToFullUrl ( ) {
4+ const message_el = document . getElementById ( "message_404" )
5+ message_el . innerText = "Redirecting"
6+
7+ const response = await fetch ( `${ config . base } /api/redirect` )
8+ const redirects = await response . json ( )
9+ let pathname = window . location . pathname . substring ( 1 )
10+ if ( pathname in redirects ) {
11+ window . location . href = redirects [ pathname ] ;
12+ } else {
13+ message_el . innerText = "Page not found"
14+ }
15+ }
16+
17+ document . addEventListener ( 'DOMContentLoaded' , redirectToFullUrl ) ;
Original file line number Diff line number Diff line change 1+ ---
2+ import Layout from " @/layout/Layout.astro"
3+
4+ ---
5+ <Layout title ={ " 404" } headings ={ []} >
6+ <div id =" message_404" ></div >
7+ </Layout >
8+
9+ <script src =" ../libs/redirect.js" />
Original file line number Diff line number Diff line change 1+ import { load_json_abs } from '@/libs/utils.js'
2+ import { config } from '@/config'
3+ import { join } from 'path'
4+
5+ export async function GET ( ) {
6+ const documents = await load_json_abs ( join ( config . collect_content . outdir , 'document_list.json' ) )
7+ const redirects = documents . reduce ( ( acc , doc ) => {
8+ acc [ doc . sid ] = doc . url ;
9+ return acc ;
10+ } , { } ) ;
11+ return new Response (
12+ JSON . stringify ( redirects ) , {
13+ status : 200 ,
14+ headers : { 'Content-Type' : 'json' }
15+ } ) ;
16+ }
Original file line number Diff line number Diff line change 1- import { createReadStream } from 'fs' ;
1+ import { createReadStream } from 'fs'
22import { resolve , join } from 'path'
3- import { config } from " @/config" ;
3+ import { config } from ' @/config'
44import { load_json_abs } from '@/libs/utils.js'
55import { file_mime } from '@/libs/assets.js'
66import { remove_base } from '@/libs/assets.js'
You can’t perform that action at this time.
0 commit comments