aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormr4tt <78581772+mr4tt@users.noreply.github.com>2024-07-30 15:21:34 +0800
committerGitHub <noreply@github.com>2024-07-30 09:21:34 +0200
commitef37632af8d6f5bc7d2efce2dafe3b0cda1f10f2 (patch)
tree31d254184870b384054d68c20c3afa515a9fb019
parent74fb998e1df2fdb914d83e6fbc448152b8081e9b (diff)
downloadpelican-themes-ef37632af8d6f5bc7d2efce2dafe3b0cda1f10f2.tar.gz
Add 404 Page when theme not found (#777)
-rw-r--r--.gitignore2
-rw-r--r--build-theme-previews.py50
-rw-r--r--pelican-sad.pngbin0 -> 1030179 bytes
3 files changed, 49 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index e79f6b5..ba5436c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,4 +19,4 @@ Thumbs.db
# Preview artifacts #
#####################
_pelican
-_output \ No newline at end of file
+_output
diff --git a/build-theme-previews.py b/build-theme-previews.py
index 327fba5..3ad6740 100644
--- a/build-theme-previews.py
+++ b/build-theme-previews.py
@@ -59,7 +59,7 @@ HTML_HEADER = """\
<style>
h1 {
- margin 20px auto;
+ margin: 20px auto;
text-align: center;
}
@@ -134,6 +134,40 @@ Failed to build <a href="failed.html" class="fail">{fail} themes</a>
</html>
"""
+HTML_404 = """\
+<!DOCTYPE html>
+<html>
+<head>
+<title>Not Found</title>
+</head>
+<style>
+h1 {
+ margin: 20px auto;
+ text-align: center;
+}
+p {text-align: center;}
+h3 {text-align: center;}
+a {color: black;}
+.center {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+ width: 50%;
+}
+</style>
+<body>
+
+<h1>Not Found</h1>
+<h3>What you’re looking for isn’t here. <br> It may have moved, or something unfortunate may have befallen it.</h3>
+
+<p>Double-check the URL and try again, or <a href="https://www.pelicanthemes.com">head home</a>.</p>
+
+<img src="pelican-sad.png" alt="sad pelican" class="center">
+
+</body>
+</html>
+"""
+
def setup_folders(args):
theme_root = os.path.abspath(os.path.dirname(__file__))
@@ -235,6 +269,17 @@ def write_index_files(output_root, success, fail):
logger.info(f"failed {len(fail)} themes")
+def write_404_file(output_root):
+ logger.info("generating 404 page file...")
+ with open(os.path.join(output_root, "404.html"), "w") as outfile:
+ outfile.write(HTML_404)
+
+ pelican_pic_path = os.path.join(output_root, "pelican-sad.png")
+ subprocess.call(["cp", "pelican-sad.png", pelican_pic_path])
+
+ logger.info("wrote 404 page file")
+
+
def parse_args(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument(
@@ -273,7 +318,8 @@ def main(argv=None):
theme_root, samples_root, output_root, screenshot_root = setup_folders(args)
success, fail = build_theme_previews(theme_root, samples_root, output_root, screenshot_root)
write_index_files(output_root, success, fail)
+ write_404_file(output_root)
if __name__ == "__main__":
- main() \ No newline at end of file
+ main()
diff --git a/pelican-sad.png b/pelican-sad.png
new file mode 100644
index 0000000..3893d1c
--- /dev/null
+++ b/pelican-sad.png
Binary files differ