hexo-theme-cactus
hexo-theme-cactus copied to clipboard
Handle 404's with page
It would be nice to have 404's handled with a page out-of-the-box - or maybe have it be optional.
Thanks for the theme!
Chelsea
I agree. Pull requests are welcome!
Is it even possible to add this feature? If I am not mistaken, this is something handled by the web-server.
The webserver can be configured to show a specific page on a 404 error, but by default it typically redirects to a 404.html
page at the root if such a page exists. The requested feature is to implement such a custom 404 page.
- I add a new page with
hexo new page 404
and add some text:
---
title: 404
date: 2022-06-27 19:57:51
---
Cannot find the page you are searching for.
- In order to add styling I need to add an
*.ejs
-file, lets say I named itnotfound.ejs
, because I am afraid404.ejs
will cause issues. I am going to rename it to404.ejs
at the end, if possible. - Since, the 404 page is of type page I need to add the processing step the
page.ejs
:
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
<%- partial('_partial/post/gallery') %>
<div class="content" itemprop="articleBody">
<% if (page.notfound) { %>
<%- partial('_partial/notfound') %>
<% } else if (page.search || page.type === "search") { %>
<%- partial('_partial/search') %>
<% } else if (page.type === "tags") { %>
... and so on
- Is this correct so far?
- How can I tell in
notfound.ejs
to compile404.md
to404.html
? - Is there another way you recommend?
I am aware that the 404 page is being generated as index.html
inside a 404
-directory at the moment. This is something, I need to resolve too. Maybe my whole approach does not work, because the goal is to have the 404 in the root directory.
@metters You can use Hexo Generator to register a route for /404.html
.
Also, I added 404-page-generating support in this PR #330, and you can merge this PR to have a try.
Thanks!
I tried and my screen stays white when I do a local hexo server
.
Probably a mistake on my side, I am going to try again sometime this weekend.
You may check the hexo_project/public
folder after running hexo generate
. It should generate a 404.html
there.
i believe this issue can be closed.