Add basic set of error pages
Some checks failed
/ Run tests (push) Failing after 1m10s
/ Run system tests (push) Failing after 1m15s
/ Build, push and deploy image (push) Has been skipped

This commit is contained in:
david 2024-11-01 13:16:26 +01:00
parent 823284d6ba
commit d649dc7da3
10 changed files with 115 additions and 41 deletions

BIN
app/assets/images/404.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 MiB

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class ErrorPagesController < ApplicationController
def not_found; end
def unprocessable_content; end
def internal_server_error; end
end

View file

@ -6,18 +6,35 @@ export default class extends Controller {
COOKIE_NAME = "modeTheme"
connect() {
console.log("connect switcher")
console.log("connect switcher", this.init())
}
init() {
const cookieValue = Cookie.get(this.COOKIE_NAME);
const newThemeValue = cookieValue == "dark" ? "dark" : "light";
Cookie.set("init modeTheme", newThemeValue);
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", newThemeValue);
const icon = this.element.getElementsByTagName("i")[0];
if (newThemeValue == "dark") {
icon.classList.remove("bi-sun-fill")
icon.classList.add("bi-moon-stars-fill")
} else {
icon.classList.add("bi-sun-fill")
icon.classList.remove("bi-moon-stars-fill")
}
}
switch() {
const cookieValue = Cookie.get(this.COOKIE_NAME);
const newThemeValue = cookieValue == "dark" ? "light" : "dark";
Cookie.set("modeTheme", newThemeValue);
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", newThemeValue);
const icon = this.element.getElementsByTagName("i")[0];
if(newThemeValue == "dark") {
if (newThemeValue == "dark") {
icon.classList.remove("bi-sun-fill")
icon.classList.add("bi-moon-stars-fill")
} else {

View file

@ -0,0 +1,5 @@
h1 Es ist ein Fehler aufgetreten
p Das kann leider vorkommen. Bitte versuche es nocheinmal und falls der Fehler weiter auftritt, hoffe dass er bald repariert wird, sorry
p == '¯\_(ツ)_/¯'

View file

@ -0,0 +1,6 @@
h1 Error 404
p Diese Seite existiert nicht (mehr), sorry.
p
img src="data:image/gif;base64,#{Base64.strict_encode64(Rails.application.assets['404.gif'].to_s)}"

View file

@ -0,0 +1,3 @@
h1 Es ist ein Fehler aufgetreten
p Ich konnte deine Anfrage nicht verstehen.

View file

@ -1,38 +0,0 @@
<!doctype html>
<html data-bs-theme="<%= cookies[:"modeTheme"] || "light" %>" data-controller="set-theme">
<head>
<title>a11ydive</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
</head>
<body class="">
<%= render partial: "layouts/navigation" %>
<div class="container-fluid">
<div class="row">
<%= render partial: "layouts/sidebar" %>
<main class="col ps-md-2 pt-2 <%= "border-start" if sidebar? %>">
<div class="container-fluid">
<%# render partial: "layouts/flash" %>
<% if false && sidebar? %>
<a href="#" data-bs-target="#sidebar" data-bs-toggle="collapse" class="p-1 text-decoration-none">
<i class="bi bi-list bi-lg py-2 p-1"></i>
Menu
</a>
<% end %>
<div id="main-content" data-controller="rich-text-link-targets">
<%= yield %>
</div>
</div>
</main>
</div>
</div>
<footer class="container-fluid mt-auto border-top"><%= Rails.configuration.build_version && "Version: #{Rails.configuration.build_version}" %>
</body>
</html>

View file

@ -0,0 +1,20 @@
doctype html
html data-bs-theme="#{cookies[:"modeTheme"] || "light"}" data-controller="set-theme"
head
title a11ydive
meta[name="viewport" content="width=device-width,initial-scale=1"]
= csrf_meta_tags
= csp_meta_tag
= stylesheet_link_tag "application", "data-turbo-track": "reload"
= javascript_include_tag "application", "data-turbo-track": "reload", type: "module"
body
= render partial: "layouts/navigation"
.container-fluid
.row
= render partial: "layouts/sidebar"
main.col.ps-md-2.pt-2
.container-fluid
#main-content[data-controller="rich-text-link-targets"]
= yield
footer.container-fluid.mt-auto.border-top
= Rails.configuration.build_version && "Version: #{Rails.configuration.build_version}"

View file

@ -0,0 +1,25 @@
doctype html
html data-bs-theme="light" data-controller="set-theme"
head
title a11ydive
meta[name="viewport" content="width=device-width,initial-scale=1"]
= csrf_meta_tags
= csp_meta_tag
/ = stylesheet_link_tag "application", "data-turbo-track": "reload"
/ = javascript_include_tag "application", "data-turbo-track": "reload", type: "module"
style
== Rails.application.assets.find_asset('application.css').to_s
script
== Rails.application.assets.find_asset('application.js').to_s
end
body
= render partial: "layouts/navigation"
.container-fluid
.row
= render partial: "layouts/sidebar"
main.col.ps-md-2.pt-2
.container-fluid
#main-content[data-controller="rich-text-link-targets"]
= yield
footer.container-fluid.mt-auto.border-top
= Rails.configuration.build_version && "Version: #{Rails.configuration.build_version}"

29
lib/tasks/app.rake Normal file
View file

@ -0,0 +1,29 @@
desc "Generates error pages"
task generate_error_pages: :environment do
# unless Rails.env.production?
# puts "Skipping generate_error_pages page generation outside production"
# next
# end
Rails.application.config.action_controller.perform_caching = false
pages = {
"error_pages/not_found" => "404.html",
"error_pages/unprocessable_content" => "422.html",
"error_pages/internal_server_error" => "500.html"
}
pages.each do |page, output|
puts "Generating #{output}..."
outpath = Rails.root.join("public", output)
renderer = ApplicationController.renderer.new(http_host: ENV.fetch("APP_HOST") { "jwa11y.top" }, https: true)
html = renderer.render(template: page, layout: "layouts/errors")
if html.present?
File.delete(outpath) if File.exist?(outpath)
File.open(outpath, "w") do |f|
f.write(html)
end
else
puts "Error generating #{output}!"
end
end
end