Skip to content

Commit

Permalink
Merge pull request #236 from brandenburg/anchor-fix
Browse files Browse the repository at this point in the history
propagate hash fragment (=href anchor) when redirecting URLs
  • Loading branch information
Zimmi48 authored Dec 22, 2023
2 parents b7102d0 + a6a0337 commit 294a8c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 7 additions & 6 deletions pages/404.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<#include "incl/macros.html">
<script>
const path = window.location.pathname;
const hash = window.location.hash;
const stdlibRegex = /^\/(stdlib|library)\//;
const refmanRegex = /^\/distrib\/(.*)\/refman\//;
const V80refmanRegex = /^\/distrib\/V8.0\/doc\//;
Expand All @@ -10,25 +11,25 @@
const bugSearchRegex = /^\?id=(.*)/;
const wikiRegex = /^\/cocorico\/(.*)/;
if (stdlibRegex.test(path)) {
window.location = path.replace(stdlibRegex, "/doc/<#CURRENTVERSIONTAG>/stdlib/");
window.location = path.replace(stdlibRegex, "/doc/<#CURRENTVERSIONTAG>/stdlib/") + hash;
} else if (refmanRegex.test(path)) {
const version = path.match(refmanRegex)[1];
if (version == "current") {
window.location = path.replace(refmanRegex, "/doc/<#CURRENTVERSIONTAG>/refman/");
window.location = path.replace(refmanRegex, "/doc/<#CURRENTVERSIONTAG>/refman/") + hash;
}
else {
window.location = path.replace(refmanRegex, "/doc/" + version + "/refman/");
window.location = path.replace(refmanRegex, "/doc/" + version + "/refman/") + hash;
}
} else if (stdlibDistribRegex.test(path)) {
const version = path.match(stdlibDistribRegex)[1];
if (version == "current") {
window.location = path.replace(stdlibDistribRegex, "/doc/<#CURRENTVERSIONTAG>/stdlib/");
window.location = path.replace(stdlibDistribRegex, "/doc/<#CURRENTVERSIONTAG>/stdlib/") + hash;
}
else {
window.location = path.replace(stdlibDistribRegex, "/doc/" + version + "/stdlib/");
window.location = path.replace(stdlibDistribRegex, "/doc/" + version + "/stdlib/") + hash;
}
} else if (V80refmanRegex.test(path)) {
window.location = path.replace(V80refmanRegex, "/doc/V8.0/doc/");
window.location = path.replace(V80refmanRegex, "/doc/V8.0/doc/") + hash;
} else if (bugSimplifiedRegex.test(path)) {
const bugId = path.match(bugSimplifiedRegex)[1];
// To avoid having to rely on the correspondence table from the migration, we redirect to the search page
Expand Down
20 changes: 17 additions & 3 deletions srv/server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
from http.server import SimpleHTTPRequestHandler
import socketserver

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

class Handler(SimpleHTTPRequestHandler):
def send_error(self, code, message=None):
if code == 404:
with open("404.html", "rb") as err_msg:
page404 = err_msg.read()

self.send_response(code)
self.send_header("Connection", "close")
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(page404)))
self.end_headers()
self.wfile.write(page404)
else:
SimpleHTTPRequestHandler.send_error(self, code, message)


Handler.extensions_map={
'.manifest': 'text/cache-manifest',
Expand Down

0 comments on commit 294a8c8

Please sign in to comment.