Add basic set of error pages
This commit is contained in:
parent
823284d6ba
commit
d649dc7da3
10 changed files with 115 additions and 41 deletions
BIN
app/assets/images/404.gif
Normal file
BIN
app/assets/images/404.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 MiB |
7
app/controllers/error_pages_controller.rb
Normal file
7
app/controllers/error_pages_controller.rb
Normal 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
|
||||
|
|
@ -6,7 +6,24 @@ 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() {
|
||||
|
|
@ -17,7 +34,7 @@ export default class extends Controller {
|
|||
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 {
|
||||
|
|
|
|||
5
app/views/error_pages/internal_server_error.html.slim
Normal file
5
app/views/error_pages/internal_server_error.html.slim
Normal 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 == '¯\_(ツ)_/¯'
|
||||
6
app/views/error_pages/not_found.html.slim
Normal file
6
app/views/error_pages/not_found.html.slim
Normal 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)}"
|
||||
3
app/views/error_pages/unprocessable_content.html.slim
Normal file
3
app/views/error_pages/unprocessable_content.html.slim
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
h1 Es ist ein Fehler aufgetreten
|
||||
|
||||
p Ich konnte deine Anfrage nicht verstehen.
|
||||
|
|
@ -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>
|
||||
20
app/views/layouts/application.html.slim
Normal file
20
app/views/layouts/application.html.slim
Normal 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}"
|
||||
25
app/views/layouts/errors.html.slim
Normal file
25
app/views/layouts/errors.html.slim
Normal 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
29
lib/tasks/app.rake
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue