File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Redirection</ title >
7+ </ head >
8+ < body >
9+ < h1 > Redirecting...</ h1 >
10+ < script src ="../redirect.js "> </ script >
11+ </ body >
12+ </ html >
Original file line number Diff line number Diff line change 1+ // Fetch the content of the 'urls.md' file
2+ fetch ( 'urls.md' )
3+ . then ( response => {
4+ if ( ! response . ok ) {
5+ throw new Error ( 'Network response was not ok ' + response . statusText ) ;
6+ }
7+ return response . text ( ) ;
8+ } )
9+ . then ( data => {
10+ // Parse the content of the file
11+ const lines = data . split ( '\n' ) ;
12+ const mappings = { } ;
13+
14+ lines . forEach ( line => {
15+ const [ key , url ] = line . split ( '\t' ) ;
16+ if ( key && url ) {
17+ mappings [ key . trim ( ) ] = url . trim ( ) ;
18+ }
19+ } ) ;
20+
21+ // Get the last part of the URL path
22+ const path = window . location . pathname . split ( '/' ) . filter ( Boolean ) . pop ( ) ;
23+
24+ // Check if the path exists in the mappings and redirect
25+ if ( path in mappings ) {
26+ window . location . href = mappings [ path ] ;
27+ } else {
28+ document . body . innerHTML = '<h1>404: Page Not Found</h1>' ;
29+ }
30+ } )
31+ . catch ( error => {
32+ console . error ( 'There was a problem with the fetch operation:' , error ) ;
33+ document . body . innerHTML = '<h1>Error loading redirection data</h1>' ;
34+ } ) ;
Original file line number Diff line number Diff line change 1+ projects https://hello.com
2+ some-website https://google.com
3+ another-example https://example.com
You can’t perform that action at this time.
0 commit comments