Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
fix 404 functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Robinson committed Jan 10, 2021
1 parent f065c79 commit ebe092e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
44 changes: 22 additions & 22 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,29 +170,29 @@ module.exports = function (eleventyConfig) {
* This so we can have and test a 404 during local dev.
* @link https://www.11ty.dev/docs/config/#override-browsersync-server-options
*/
eleventyConfig.setBrowserSyncConfig({
notify: true,
snippetOptions: {
rule: {
match: /<\/head>/i,
fn: function (snippet, match) {
return snippet + match
},
},
},
// eleventyConfig.setBrowserSyncConfig({
// notify: true,
// snippetOptions: {
// rule: {
// match: /<\/head>/i,
// fn: function (snippet, match) {
// return snippet + match
// },
// },
// },
// Set local server 404 fallback
callbacks: {
ready: function (err, browserSync) {
const content_404 = fs.readFileSync('dist/404/index.html')

browserSync.addMiddleware('*', (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404)
res.end()
})
},
},
})
// callbacks: {
// ready: function (err, browserSync) {
// const content_404 = fs.readFileSync('dist/404.html')

// browserSync.addMiddleware('*', (req, res) => {
// // Provides the 404 content without redirect.
// res.write(content_404)
// res.end()
// })
// },
// },
// })

return {
dir: {
Expand Down
10 changes: 3 additions & 7 deletions src/404.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
---
title: 404
layout: page
permalink: 404.html
eleventyExcludeFromCollections: true
seo:
title: Oooooops...
pagination: # pagination settings so we can control how many posts are returned below
data: collections.post
size: 10
reverse: true
alias: posts
title: 'Oooooops...'
---

The page you're looking for doesn't currently exist on this website. Perhaps you followed an old or bad link?

Here are 10 recent posts. Perhaps one of these will help you along your way?

<ol class="pt-4">
{%- for post in posts -%}
{%- for post in collections.post | limit(10) -%}
<li><a class="underline" href="{{ post.url }}">{{ post.data.title }}</a></li>
{%- endfor -%}
</ol>
12 changes: 11 additions & 1 deletion utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ module.exports = {
replacement: '-',
remove: /[*+~.·,()'"`´%!?¿:@]/g,
})
},
},

/**
* Pass ` | limit(x)` to a Collection loop to limit the number returned
* Alt = ` | reverse | limit(x)` to return X most recent
* Took the following filters from
* @link https://www.youtube.com/watch?v=wV77GwOY22w&feature=share
*/
limit: (arr, count = 5) => {
return arr.slice(0, count)
},

/**
* Get Authors from _data/authors.json to use in Post Lists and Detail
Expand Down

0 comments on commit ebe092e

Please sign in to comment.