hexo-theme-cactus icon indicating copy to clipboard operation
hexo-theme-cactus copied to clipboard

Handle 404's with page

Open chelsea-codes opened this issue 2 years ago • 8 comments

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

chelsea-codes avatar Oct 06 '21 02:10 chelsea-codes

I agree. Pull requests are welcome!

probberechts avatar Oct 06 '21 09:10 probberechts

Is it even possible to add this feature? If I am not mistaken, this is something handled by the web-server.

metters avatar Jun 25 '22 21:06 metters

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.

probberechts avatar Jun 25 '22 21:06 probberechts

  1. 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.
  1. In order to add styling I need to add an *.ejs-file, lets say I named it notfound.ejs, because I am afraid 404.ejs will cause issues. I am going to rename it to 404.ejs at the end, if possible.
  2. 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 compile 404.md to 404.html?
  • Is there another way you recommend?

metters avatar Jun 27 '22 18:06 metters

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 avatar Jun 27 '22 18:06 metters

@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.

veraposeidon avatar Sep 16 '22 09:09 veraposeidon

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.

metters avatar Sep 17 '22 09:09 metters

You may check the hexo_project/public folder after running hexo generate. It should generate a 404.html there.

veraposeidon avatar Sep 17 '22 18:09 veraposeidon

i believe this issue can be closed.

metters avatar Dec 30 '22 22:12 metters