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

Added simple "create 404 page" plugin. #175

Merged
merged 13 commits into from Oct 9, 2016
Merged

Conversation

@felixfontein
Copy link
Contributor

felixfontein commented Oct 2, 2016

Using the new feature in getnikola/nikola#2517.

@felixfontein
Copy link
Contributor Author

felixfontein commented Oct 2, 2016

I think I'd like to generalize this plugin a bit before it is merged. (I just noticed I'd also like to have a 403 error message ;) ) So please wait with merging :)

@felixfontein
Copy link
Contributor Author

felixfontein commented Oct 2, 2016

Ok, I think I'm now happy with the current state. Ready to merge from my side.

Copy link
Member

Kwpolska left a comment

Overall, good. Just a few minor warts and things that could be simplified.

By the way, perhaps a shorter name like errorpages would look better?

for a 404 error page, and
~~~
# Create 404 and 403 error pages
CREATE_ERROR_PAGES=[403,404]

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member

(minor wart) this line could use a few space characters, so could conf.py.sample

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

Done.

~~~
for both 403 and 404 error pages. Note that you need to provide a `403.tmpl` template for the latter example.

You also need to configure your web server accordingly. You can find documentation on how to do that for common webservers here: [Apache](https://httpd.apache.org/docs/2.4/custom-error.html), [Nginx](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member
It will work out of the box on [GitHub Pages](https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/).

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

Done.

@@ -0,0 +1,57 @@
from nikola.plugin_categories import Task

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member

Add a copyright notice and license of your choice. (Steal the header from Nikola and change the names if you don’t have a favorite license.)

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

Done.

def prepare_error_page(self, destination, lang, template):
context = {}

deps = self.site.template_system.template_deps(template)

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member

Could this be done without copy-pasting heavy bits of nikola.py? Since you already depend on future versions of Nikola, perhaps you could modify the generic page renderer to do this?

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

Let me take a look.

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

This should be no problem with getnikola/nikola#2519.

<div class="title">
<h1 class="entry-title">{{ messages('Page not found', lang) }}</h1>
</div>
<div>

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member

(minor wart) do we really need a classless div here?

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

No, that's not needed here. It's just a leftover from my personal theme.

@felixfontein
Copy link
Contributor Author

felixfontein commented Oct 2, 2016

I now renamed the plugin to errorpages.



class CreateErrorPages(Task):
name = "create_error_pages"

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member

Should also say errorpages.

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

Done.

def set_site(self, site):
super(CreateErrorPages, self).set_site(site)

def prepare_error_page(self, destination, lang, template):

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 2, 2016

Member

So, no way not to copy-paste this?

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 2, 2016

Author Contributor

You mean what you mentioned above? I'm still looking at nikola.py...

Copy link
Member

Kwpolska left a comment

Now that getnikola/nikola#2519 is merged, please use generic_renderer here.


To use this, you need a template `XXX.tmpl` for every [HTTP status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) `XXX`. The plugin provides simple templates `404.tmpl` both for Mako and Jinja, but you can easily adjust them to your needs. These default templates assume that the strings `'Page not found'` and `'The page you are trying to access does not exist. Please use your browser\'s "back" button to return to the previous page.'` are translated. If your blog uses another language than English, you need to translate these strings yourself and provide the translations in your theme's `messages_XX.py` files. Or (for simple one-language blogs) simply adjust the strings in `XXX.tmpl`.

To tell the plugin which error pages to create, add `CREATE_ERROR_PAGES` to your `conf.py`. This must be a list of error codes, like

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Oct 9, 2016

Member

Still uses old variable name here.

This comment has been minimized.

Copy link
@felixfontein

felixfontein Oct 9, 2016

Author Contributor

Thanks for noticing! Fixed it.

@Kwpolska
Copy link
Member

Kwpolska commented Oct 9, 2016

Great work! Merging. Will be downloadable in a minute or two.

@Kwpolska Kwpolska merged commit 15a4462 into getnikola:master Oct 9, 2016
1 check was pending
1 check was pending
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@felixfontein
Copy link
Contributor Author

felixfontein commented Oct 9, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.