Skip to content

Commit

Permalink
Fix loading from incorrect URI on 404 page. (#1843)
Browse files Browse the repository at this point in the history
* Present a list of possible options when encountering a 404.
* Also affix cccl/ onto URL since that's what GitHub does.

* Update gitignore to exclude _site
  • Loading branch information
wmaxey authored Jun 12, 2024
1 parent bc08dfa commit bbf6533
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ build*/
.config
_deps/catch2-src/
.vscode/
_site/
compile_commands.json
CMakeUserPresets.json
62 changes: 36 additions & 26 deletions docs/404.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting to nvidia.github.io/cccl/thrust</title>
<title>CCCL - 404</title>

<html>
<head>
<link rel="stylesheet" href="/cccl/_static/basic.css" type="text/css"/>
<link rel="stylesheet" href="/cccl/_static/css/theme.css" type="text/css"/>
</head>
<body>
<h1>404 - That link no longer works.</h1>
<p>Here is a list of possible options:</p>
<ul>
<div id="linkGen"></div>
</ul>
<script type="module">
import Fuse from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/fuse.mjs'
var localUri = window.location.pathname;
var hostUrl = window.location.protocol + "//" + window.location.host
var pagelistUrl = hostUrl + "/pagelist.txt"
import Fuse from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/fuse.mjs'
var localUri = window.location.pathname;
var hostUrl = window.location.protocol + "//" + window.location.host
var pagelistUrl = hostUrl + "/cccl/pagelist.txt"

fetch(pagelistUrl)
.then((response) => response.text())
.then((text) => {
const pagelist = text.split(",")
console.log(pagelist)
fetch(pagelistUrl)
.then((response) => response.text())
.then((text) => {
const pagelist = text.split(",")

const options = {
includeScore: true,
distance: 100,
threshold: 0.8,
}
const options = {
includeScore: true,
distance: 100,
threshold: 0.8,
ignoreLocation: true
}

const fuse = new Fuse(pagelist, options)
const result = fuse.search(localUri)
// cccl/device_vector.html => 'cccl 'device 'vector
const query = localUri.replace(/\/|-|_/gi," '").replace(".html","")
console.log("query:" + query)
const fuse = new Fuse(pagelist, options)
const result = fuse.search(query, {limit: 10})

if (result.length) {
console.log(result[0])
var possibleUri = hostUrl + "/" + result[0].item
window.location.href = possibleUri
} else {
window.location.href = hostUrl + "/index.html"
}
})
const listItem = '<li><a href=\"{2}{0}\">{0}</a> - Score: {1}</li>'.replace(/\{2\}/g, hostUrl + "/")
document.getElementById('linkGen').innerHTML = ""
result.forEach(element => {
document.getElementById('linkGen').innerHTML += listItem.replace(/\{0\}/g, element.item).replace(/\{1\}/g, element.score.toFixed(2))
});
})
</script>
</head>
</body>
</html>
2 changes: 1 addition & 1 deletion docs/scrape_docs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cd $SCRIPT_PATH

thrust=$(
cd $path_to_docs;
find ./ -iname "*.html" -printf '%P,'
find ./ -iname "*.html" -printf 'cccl/%P,'
)

echo "$thrust" > $path_to_docs/pagelist.txt

0 comments on commit bbf6533

Please sign in to comment.