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

Add 404 Page when theme not found #777

Merged
merged 6 commits into from
Jul 30, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Thumbs.db
# Preview artifacts #
#####################
_pelican
_output
_output
50 changes: 48 additions & 2 deletions build-theme-previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def install_translator(self, generator):
<style>

h1 {
margin 20px auto;
margin: 20px auto;
text-align: center;
}

Expand Down Expand Up @@ -134,6 +134,40 @@ def install_translator(self, generator):
</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__))
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
main()
Binary file added pelican-sad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.