Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect pages: Add 404 pages #121137

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 84 additions & 30 deletions .ci/generate_redirects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,52 @@ function package_path(args...)
joinpath("webroot", "packages", "redirect_to_repo", args...)
end

function style_block(backgroundcolor, color)
"""
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
background-color: #f9f9f9;
}
.centered-div {
border: 3px solid $color;
background-color: $backgroundcolor;
border-radius: 10px;
padding: 20px;
margin: 20px;
text-align: center;
color: #333;
max-width: 30em;
word-wrap: break-word;
}
.centered-div a {
color: $color;
font-weight: bold;
}
</style>
"""
end

function create_redirect_page(; name, path)
repo = get_repo(path)
host = get_host(repo)
jlname = name * ".jl"
should_redirect = known_host(host)
meta_redirection = should_redirect ? """<meta http-equiv="refresh" content="0; url=$repo">""" : ""
message = if should_redirect
"""Redirecting to $name...<br><br>Click the link below if you are not redirected automatically to the registered repository for the Julia package $name<br><br><a href="$repo" rel="nofollow">$repo</a>"""
"""Redirecting to $jlname...<br><br>Click the link below if you are not redirected automatically to the registered repository for the Julia package $jlname<br><br><a href="$repo" rel="nofollow">$repo</a>"""
else
"""Click the link below to go to the registered repository for the Julia package $name<br><br><a href="$repo" rel="nofollow">$repo</a>"""
"""Click the link below to go to the registered repository for the Julia package $jlname<br><br><a href="$repo" rel="nofollow">$repo</a>"""
end
title = if should_redirect
"Redirecting to $name..."
"Redirecting to $jlname..."
else
"Confirm redirect to $name"
"Confirm redirect to $jlname"
end

open(package_path(name * ".html"), "w") do io
Expand All @@ -52,32 +84,7 @@ function create_redirect_page(; name, path)
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>$title</title>
$meta_redirection
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
background-color: #f9f9f9;
}
.centered-div {
border: 3px solid #9558B2;
background-color: #f8e9ff;
border-radius: 10px;
padding: 20px;
margin: 20px;
text-align: center;
color: #333;
max-width: 30em;
word-wrap: break-word;
}
.centered-div a {
color: #9558B2;
font-weight: bold;
}
</style>
$(style_block("#f8e9ff", "#9558B2"))
</head>
<body>
<div class="centered-div">
Expand All @@ -89,13 +96,60 @@ function create_redirect_page(; name, path)
end
end

function create_404_page()
open(joinpath("webroot", "404.html"), "w") do io
write(io, """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page not found</title>
$(style_block("#ffcbc8", "#CB3C33"))
</head>
<body>
<div class="centered-div">
<p>No page exists here.<br><br>Redirection pages for registered Julia packages follow the format packages/redirect_to_repo/SomePackage.</p>
</div>

<script>
// Get the current URL path
const urlPath = window.location.pathname;

// Define the regex pattern to match the URL structure
const pattern = /\\/packages\\/redirect_to_repo\\/([^\\/]+?)(\\.html)?\$/;

// Check if the URL matches the pattern
const match = urlPath.match(pattern);

if (match) {
const packageName = match[1]; // Extract the package name
const messageElement = document.querySelector(".centered-div p");
// Update the paragraph text
messageElement.innerHTML = `\
There is no package \${packageName}.jl registered in the Julia General Registry.\
<br><br>\
Would you like to try searching <a href="https://github.com/search?q=\${packageName}.jl&type=repositories">GitHub</a>, \
<a href="https://about.gitlab.com/search/?searchText=\${packageName}.jl">GitLab</a>, \
<a href="https://www.google.com/search?q=\${packageName}.jl">Google</a>, \
or <a href="https://duckduckgo.com/?q=\${packageName}.jl">DuckDuckGo</a> for it?`;
}
</script>
</body>
</html>
""")
end
return
end

function main()
cd(joinpath(@__DIR__, "..")) do
mkpath(package_path())
packages_info = get_packages_info()
for (; name, path) in packages_info
create_redirect_page(; name, path)
end
create_404_page()
end
end

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/redirects_page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- master
paths:
- '**/Package.toml' # avoids redeploys on version or compat changes
- '.github/workflows/redirects_page.yml'
- '.ci/generate_redirects.jl'


jobs:
build-and-deploy:
Expand Down
Loading