Skip to content

Commit

Permalink
Update eleventy
Browse files Browse the repository at this point in the history
  • Loading branch information
supertanuki committed Dec 20, 2024
1 parent 9189912 commit 5f1d45d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 87 deletions.
180 changes: 97 additions & 83 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,139 @@
const { DateTime } = require("luxon");
const fs = require("fs");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginNavigation = require("@11ty/eleventy-navigation");
const markdownIt = require("markdown-it");

module.exports = function(eleventyConfig) {
const { DateTime } = require('luxon')
const fs = require('fs')
const pluginRss = require('@11ty/eleventy-plugin-rss')
const pluginSyntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const pluginNavigation = require('@11ty/eleventy-navigation')
const markdownIt = require('markdown-it')

module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({
'extra/take-a-break': 'extra/take-a-break',
'img': 'img',
'css': 'css',
'js': 'js',
'CNAME': 'CNAME',
'favicon.ico' : 'favicon.ico',
'site.webmanifest': 'site.webmanifest'
});
img: 'img',
css: 'css',
js: 'js',
CNAME: 'CNAME',
'favicon.ico': 'favicon.ico',
'site.webmanifest': 'site.webmanifest',
})

// Add plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(pluginRss)
eleventyConfig.addPlugin(pluginSyntaxHighlight)
eleventyConfig.addPlugin(pluginNavigation)

// Alias `layout: post` to `layout: layouts/post.njk`
eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
eleventyConfig.addLayoutAlias('post', 'layouts/post.njk')

eleventyConfig.addFilter("year", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("yyyy");
});
eleventyConfig.addFilter('year', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy')
})

eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy");
});
eleventyConfig.addFilter('readableDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('dd LLL yyyy')
})

eleventyConfig.addFilter("toFrenchDate", date => {
eleventyConfig.addFilter('toFrenchDate', (date) => {
return new Intl.DateTimeFormat('fr').format(date)
});
})

eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});

eleventyConfig.addCollection('episodesAndNewsletters', function(collectionApi) {
return [...collectionApi.getFilteredByTag('newsletter'), ...collectionApi.getFilteredByTag('episode')].sort(function(a, b){
return new Date(b.date) - new Date(a.date);
});
});
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd')
})

/*
eleventyConfig.addCollection(
'episodesAndNewsletters',
function (collectionApi) {
const items = [
...collectionApi.getFilteredByTag('newsletter'),
...collectionApi.getFilteredByTag('episode'),
]
items.forEach((item) => {
if (!item.templateContent) {
console.warn(`templateContent not ready for ${item.inputPath}`)
}
})
return items.sort((a, b) => {
const dateA = a.data.date || new Date()
const dateB = b.data.date || new Date()
return new Date(dateB) - new Date(dateA)
})
}
)
*/

// Get the first `n` elements of a collection.
eleventyConfig.addFilter("head", (array, n) => {
if(!Array.isArray(array) || array.length === 0) {
return [];
eleventyConfig.addFilter('head', (array, n) => {
if (!Array.isArray(array) || array.length === 0) {
return []
}
if( n < 0 ) {
return array.slice(n);
if (n < 0) {
return array.slice(n)
}

return array.slice(0, n);
});
return array.slice(0, n)
})

// Return the smallest number argument
eleventyConfig.addFilter("min", (...numbers) => {
return Math.min.apply(null, numbers);
});
eleventyConfig.addFilter('min', (...numbers) => {
return Math.min.apply(null, numbers)
})

function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
return (tags || []).filter(
(tag) => ['all', 'nav', 'post', 'posts'].indexOf(tag) === -1
)
}

eleventyConfig.addFilter("filterTagList", filterTagList)
eleventyConfig.addFilter('filterTagList', filterTagList)

// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set();
collection.getAll().forEach(item => {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
});
eleventyConfig.addCollection('tagList', function (collection) {
let tagSet = new Set()
collection.getAll().forEach((item) => {
;(item.data.tags || []).forEach((tag) => tagSet.add(tag))
})

return filterTagList([...tagSet]);
});
return filterTagList([...tagSet])
})

// Customize Markdown library and settings:
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true
});
eleventyConfig.setLibrary("md", markdownLibrary);
linkify: true,
})
eleventyConfig.setLibrary('md', markdownLibrary)

// Override Browsersync defaults (used only with --serve)
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, browserSync) {
const content_404 = fs.readFileSync('_site/404.html');
ready: function (err, browserSync) {
const content_404 = fs.readFileSync('_site/404.html')

browserSync.addMiddleware("*", (req, res) => {
browserSync.addMiddleware('*', (req, res) => {
// Provides the 404 content without redirect.
res.writeHead(404, {"Content-Type": "text/html; charset=UTF-8"});
res.write(content_404);
res.end();
});
res.writeHead(404, { 'Content-Type': 'text/html; charset=UTF-8' })
res.write(content_404)
res.end()
})
},
},
ui: false,
ghostMode: false
});
ghostMode: false,
})

return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: [
"md",
"njk",
"html",
"liquid"
],
templateFormats: ['md', 'njk', 'html', 'liquid'],

// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: "njk",
markdownTemplateEngine: 'njk',

// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",
htmlTemplateEngine: 'njk',

// -----------------------------------------------------------------
// If your site deploys to a subdirectory, change `pathPrefix`.
Expand All @@ -132,15 +146,15 @@ module.exports = function(eleventyConfig) {
// You can also pass this in on the command line using `--pathprefix`

// Optional (default is shown)
pathPrefix: "/",
pathPrefix: '/',
// -----------------------------------------------------------------

// These are all optional (defaults are shown):
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site"
}
};
};
input: '.',
includes: '_includes',
data: '_data',
output: '_site',
},
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eleventy-base-blog",
"version": "6.0.0",
"description": "A starter repository for a blog web site using the Eleventy static site generator.",
"name": "techologie",
"version": "2.0.0",
"description": "Website of Techologie podcast. Based on eleventy-base-blog",
"scripts": {
"build": "eleventy",
"watch": "eleventy --watch",
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"devDependencies": {
"@11ty/eleventy": "^1.0.0",
"@11ty/eleventy": "^3.0.0",
"@11ty/eleventy-navigation": "^0.3.2",
"@11ty/eleventy-plugin-rss": "^1.1.2",
"@11ty/eleventy-plugin-syntaxhighlight": "^3.1.3",
Expand Down

0 comments on commit 5f1d45d

Please sign in to comment.