Skip to content

Commit

Permalink
minor #149 [Docs] Add cookbook for exposing a 404 page (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 0.x-dev branch.

Discussion
----------

[Docs] Add cookbook for exposing a 404 page

Fixes #112

Commits
-------

098cb94 Add note about Github Pages
04d53fa [Docs] Add cookbook for exposing a 404 page
  • Loading branch information
ogizanagi committed Sep 12, 2022
2 parents 9b1d612 + 098cb94 commit 07ff876
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ indent_style = space
indent_size = 4

[*.md]
max_line_length = 80
max_line_length = 120
trim_trailing_whitespace = false

[*.js]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ Stenope is not a ready-to-use bloging system: but you could quickly _write your
<!-- TODO - [Adding custom files to the build]() -->
<!-- TODO - [Data source: writing a custom Provider]() -->
<!-- TODO - [Data format: writing a custom Decoder]() -->
- [Data manipulation: writing a custom Processor](doc/processors.md)
- [Data manipulation: writing a custom Processor](doc/cookbooks/processors.md)
- [Exposing a not found page](doc/cookbooks/not-found-page.md)
<!-- TODO - [How to automatically deploy and host a static site]() -->
2 changes: 1 addition & 1 deletion doc/app/src/Controller/DocController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function index()
return $this->render('doc/index.html.twig', ['page' => $page]);
}

#[Route('/{page}', name: 'page')]
#[Route('/{page<.+>}', name: 'page')]
public function page(Page $page)
{
return $this->render('doc/page.html.twig', ['page' => $page]);
Expand Down
61 changes: 61 additions & 0 deletions doc/cookbooks/not-found-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Exposing a not found page

Since Stenope is a static site generator, it does not handle 404 errors for missing pages.
Instead, your web server should handle them.

However, you can let Stenope generate a 404.html page for you, and let your web server serve it.

For instance, add in your `config/routes.yaml`:

```yaml
errors_404:
path: 404.html
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: errors/404.html.twig
options:
stenope:
sitemap: false
```
and create the `templates/errors/404.html.twig` template:

```twig
{% extends 'base.html.twig' %}
{% block title %}Page not found{% endblock %}
{% block content %}
<h1>404 Not Found</h1>
<p>The page you are looking for does not exist.</p>
{% endblock %}
```

Then, configure your web server to serve this page when a 404 error occurs.

Nginx:

```nginx
server {
# […]
location / {
try_files $uri $uri/index.html =404;
}
location ~ \.html {
internal;
}
error_page 404 /404.html;
```

Apache:

```apacheconf
ErrorDocument 404 /404.html
```

!!! note "404 page on Github Pages"
If you're deploying on Github Pages, you're already set!
The `404.html` file at the root of your `gh-pages` branch is automatically picked by Github for this purpose.
File renamed without changes.

0 comments on commit 07ff876

Please sign in to comment.