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

Support custom 404 page #227

Closed
melaniewalsh opened this issue Oct 6, 2020 · 11 comments
Closed

Support custom 404 page #227

melaniewalsh opened this issue Oct 6, 2020 · 11 comments
Labels
bug Something isn't working

Comments

@melaniewalsh
Copy link

Describe the bug

I know that Jupyter Book will not work predictably with custom Sphinx extensions, but I've been trying to integrate this Sphinx Not Found Page extension into my Jupyter Book so that I can have a custom 404 page. And I think this could be potentially useful for all Jupyter Book users.

Anyway, when I use this extension, I get the following error:

An error happened in rendering the page 404.
Reason: ValueError("'/' does not start with '/Users/melaniewalsh/mybookname'")

@humitos has been helping me debug this issue and usefully identified that there seems to be a problem in sphinx-book-theme in the function find_url_relative_to_root, which is called from generate_nav_html.

So I was wondering if there were any suggestions about how to make the Sphinx Not Found extension work with the Sphinx Book Theme. Thanks!

To Reproduce

  1. Add Sphinx Not Found Page extension to _config.yml
sphinx:
  extra_extensions: 
  - notfound.extension  
  config:
    notfound_context:
        body: "<h1>Page not found.</h1>"
    notfound_no_urls_prefix: True
  1. Build Jupyter Book
  2. See error
An error happened in rendering the page 404.
Reason: ValueError("'/' does not start with '/Users/melaniewalsh/mybookname'")

Expected behavior

Custom 404 page is built that preserves CSS and JavaScript from Sphinx Book Theme

Environment

  • Python Version [e.g. 3.7.1]: 3.8
  • Package versions or output of jupyter-book --version:
    Jupyter Book: 0.8.2
    MyST-NB: 0.10.1
    Sphinx Book Theme: 0.0.36
    MyST-Parser: 0.12.10
    Jupyter-Cache: 0.4.1
    NbClient: 0.4.0
  • Operating System: Mac OS
@melaniewalsh melaniewalsh added the bug Something isn't working label Oct 6, 2020
@welcome
Copy link

welcome bot commented Oct 6, 2020

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@melaniewalsh
Copy link
Author

Sorry I just realized that a custom 404 page was previously mentioned by @chrisjsewell #221! The Sphinx Not Found Page extension wouldn't be necessary if a custom 404 page was integrated in a different way

@chrisjsewell
Copy link
Member

chrisjsewell commented Oct 11, 2020

Oh yeh was going to mention.
I didn't know about this extension though so thanks for pointing it out 😀
Will have at look to see if any of it's implementation should be incorporated here, or we just allow for comparability with it

@humitos
Copy link

humitos commented Oct 12, 2020

I'm the author of the sphinx-notfound-extension. Let me know if I can be useful in some way here.

I don't see specific needs in #221 that won't allow people using sphinx-book-theme to use the extension. In fact, in the description of the issue, the linked project using a custom 404 page is using the sphinx-notfound-page 😄

If there is anything needed to be added to the extension to make it compatible with the sphinx-book-theme, I'd be happy to incorporate it.

@chrisjsewell
Copy link
Member

thanks @humitos!
Yeh I'm sure we can work out the issue to support this extension and will let you know 😄

@chrisjsewell chrisjsewell changed the title Unable to make custom 404 page with Sphinx extension Support Custom 404 page Oct 12, 2020
@chrisjsewell chrisjsewell changed the title Support Custom 404 page Support custom 404 page Oct 12, 2020
@melaniewalsh
Copy link
Author

melaniewalsh commented Aug 31, 2021

Hey! I just wanted to share that I was finally able to get the sphinx-notfound-extension working and create a custom 404 page in my Jupyter Book.

I needed to add a "url prefix" to my own repository, which I did in the _config.yml file here.

You can see an example of the custom 404 page here.

Thanks for the great extension, @humitos!

@choldgraf
Copy link
Member

ah that's very cool! Thanks for sharing your solution!

@choldgraf
Copy link
Member

choldgraf commented Sep 1, 2021

@melaniewalsh - any interest in making a quick post to the jupyter book discussions board that shows off this pattern? Maybe others would find it useful!

Then I think that we could consider this issue closed?

@humitos
Copy link

humitos commented Sep 1, 2021

Thanks @melaniewalsh for sharing the solution!

any interest in making a quick post to the jupyter book discussions board that shows off this pattern? Maybe others would find it useful!

Hehe, I was about to suggest adding an entry in the FAQ of the sphinx-notfound-page project at https://sphinx-notfound-page.readthedocs.io/en/latest/faq.html

Either work to me. So, happy to have it documented somewhere.

@melaniewalsh
Copy link
Author

@choldgraf Sure, I'd be happy to write a quick post for the Jupyter Book discussion board! Also @humitos I could add an entry to the sphinx-notfound-page FAQ, too.

But yes I think this issue is closed 🎉

@choldgraf
Copy link
Member

amazing! thanks for being so helpful @melaniewalsh :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants