feat: 404
This commit is contained in:
parent
fd2a128d40
commit
96d10fb7c6
2 changed files with 43 additions and 2 deletions
9
app.py
9
app.py
|
|
@ -5,7 +5,7 @@ import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import Flask, jsonify, render_template, send_from_directory
|
from flask import Flask, jsonify, render_template, send_from_directory, abort
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.formatters import HtmlFormatter
|
from pygments.formatters import HtmlFormatter
|
||||||
from pygments.lexers import TextLexer, get_lexer_for_filename
|
from pygments.lexers import TextLexer, get_lexer_for_filename
|
||||||
|
|
@ -102,7 +102,7 @@ def serve_gist(filename):
|
||||||
file_path = os.path.join(GIST_PATH, filename)
|
file_path = os.path.join(GIST_PATH, filename)
|
||||||
|
|
||||||
if not os.path.exists(file_path) or not os.path.isfile(file_path):
|
if not os.path.exists(file_path) or not os.path.isfile(file_path):
|
||||||
return "File not found", 404
|
abort(404)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r", encoding="utf-8") as f:
|
with open(file_path, "r", encoding="utf-8") as f:
|
||||||
|
|
@ -122,6 +122,11 @@ def serve_gist(filename):
|
||||||
return render_template("gist.html", filename=filename, highlighted_code=highlighted)
|
return render_template("gist.html", filename=filename, highlighted_code=highlighted)
|
||||||
|
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def not_found(error):
|
||||||
|
return render_template("404.html"), 404
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/repo/<int:repo_id>")
|
@app.route("/api/repo/<int:repo_id>")
|
||||||
def get_repo(repo_id):
|
def get_repo(repo_id):
|
||||||
repositories = [repo for repo in get_repositories() if repo.exported]
|
repositories = [repo for repo in get_repositories() if repo.exported]
|
||||||
|
|
|
||||||
36
templates/404.html
Normal file
36
templates/404.html
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="/styles/common.css" />
|
||||||
|
<link rel="stylesheet" href="/styles/index.css" />
|
||||||
|
<link rel="icon" type="image/webp" href="/public/logo.webp" />
|
||||||
|
<title>404 - Not Found</title>
|
||||||
|
</head>
|
||||||
|
<body class="graph-background">
|
||||||
|
<site-header></site-header>
|
||||||
|
<main class="main" style="justify-content: center; align-items: center;">
|
||||||
|
<h1 style="font-size: 5em; font-weight: normal; margin: 0;">404</h1>
|
||||||
|
</main>
|
||||||
|
<site-footer></site-footer>
|
||||||
|
<script src="/scripts/common.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
const terminalText = " /not-found";
|
||||||
|
const terminalPrompt = document.querySelector(".terminal-prompt");
|
||||||
|
const delay = 250;
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
function typechar() {
|
||||||
|
if (i < terminalText.length) {
|
||||||
|
terminalPrompt.innerHTML += terminalText.charAt(i++);
|
||||||
|
setTimeout(typechar, delay / terminalText.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
typechar();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue