SiteWebAstrolabe/.eleventy.js

157 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

import rssPlugin from '@11ty/eleventy-plugin-rss';
import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
import fs from 'fs';
import util from 'util';
2020-06-19 23:47:44 +02:00
// Import filters
import dateFilter from './src/filters/date-filter.js';
import markdownFilter from './src/filters/markdown-filter.js';
import w3DateFilter from './src/filters/w3-date-filter.js';
2020-06-19 23:47:44 +02:00
// Import transforms
import htmlMinTransform from './src/transforms/html-min-transform.js';
import parseTransform from './src/transforms/parse-transform.js';
2020-06-19 23:47:44 +02:00
// Import data files
import {createRequire} from 'node:module';
const require = createRequire(import.meta.url);
// need this because of issue when using ESM : https://github.com/11ty/eleventy-dependency-tree-esm/issues/2
// This will get soon resolved
2020-06-19 23:47:44 +02:00
const site = require('./src/_data/site.json');
export default function(config) {
2020-06-19 23:47:44 +02:00
// Filters
config.addFilter('dateFilter', dateFilter);
config.addFilter('markdownFilter', markdownFilter);
config.addFilter('w3DateFilter', w3DateFilter);
2021-11-18 18:24:29 +01:00
config.addFilter('dump', obj => {
return util.inspect(obj);
2021-11-18 18:24:29 +01:00
});
2020-06-19 23:47:44 +02:00
// Layout aliases
config.addLayoutAlias('home', 'layouts/home.njk');
// Transforms
config.addTransform('htmlmin', htmlMinTransform);
config.addTransform('parse', parseTransform);
// Passthrough copy
config.addPassthroughCopy('src/fonts');
config.addPassthroughCopy('src/images');
config.addPassthroughCopy('src/js');
config.addPassthroughCopy('src/admin/config.yml');
config.addPassthroughCopy('src/admin/previews.js');
config.addPassthroughCopy('node_modules/nunjucks/browser/nunjucks-slim.js');
config.addPassthroughCopy('src/robots.txt');
2020-07-18 02:22:53 +02:00
config.addPassthroughCopy('src/.htaccess');
2020-06-23 13:44:10 +02:00
config.addPassthroughCopy('src/form');
2020-06-19 23:47:44 +02:00
const now = new Date();
// Custom collections
const livePosts = post => post.date <= now && !post.data.draft;
2020-07-15 23:05:36 +02:00
const newsPosts = post => post.data.type === 'news';
const eventPosts = post => post.data.type === 'event';
2020-06-19 23:47:44 +02:00
config.addCollection('posts', collection => {
return [...collection.getFilteredByGlob('./src/posts/*.md')].reverse();
2020-06-19 23:47:44 +02:00
});
2020-07-15 23:05:36 +02:00
config.addCollection('news', collection => {
return [
...collection.getFilteredByGlob('./src/posts/*.md').filter(newsPosts)
].reverse();
});
config.addCollection('events', collection => {
return [
...collection.getFilteredByGlob('./src/posts/*.md').filter(eventPosts)
].reverse();
2020-06-19 23:47:44 +02:00
});
config.addCollection('newsFeed', collection => {
return [...collection.getFilteredByGlob('./src/posts/*.md').filter(livePosts)]
.reverse()
.slice(0, site.maxNewsPerPage);
});
2020-07-13 20:36:44 +02:00
config.addCollection('members', collection => {
return [...collection.getFilteredByGlob('./src/members/*.md')];
2020-07-13 20:36:44 +02:00
});
config.addCollection('profiles', collection => {
return [...collection.getFilteredByGlob('./src/members/*.md')]
.reverse()
.slice(0, site.maxProfilePreview);
2020-07-13 20:36:44 +02:00
});
config.addCollection('tagsList', function(collectionApi) {
2021-11-09 19:24:23 +01:00
const tagsList = new Set();
collectionApi.getAll().map(item => {
if (item.data.tags) {
// handle pages that don't have tags
item.data.tags.map(tag => tagsList.add(tag));
}
2021-11-18 18:24:29 +01:00
});
return tagsList;
2021-11-09 19:24:23 +01:00
});
config.addCollection('skillsList', function(collectionApi) {
2021-11-09 19:24:23 +01:00
const skillsList = new Set();
collectionApi.getFilteredByGlob('./src/members/*.md').map(item => {
if (item.data.tags) {
// handle pages that don't have skills
item.data.tags.map(skill => {
// exclude non related tags
if (['post', 'news', 'event'].indexOf(skill) == -1) {
skillsList.add(skill);
}
});
}
2021-11-18 18:24:29 +01:00
});
return skillsList;
});
config.addCollection('membersLocations', function(collectionApi) {
return collectionApi
.getFilteredByGlob('./src/members/*.md')
2021-11-18 18:24:29 +01:00
.filter(item => typeof item.data.location !== 'undefined')
.map(member => {
2021-11-18 18:24:29 +01:00
return {
name: member.data.name,
url: member.data.url,
location: member.data.location
2021-11-18 18:24:29 +01:00
};
});
2021-11-09 19:24:23 +01:00
});
2020-07-16 00:11:48 +02:00
config.addCollection('customers', collection => {
return [...collection.getFilteredByGlob('./src/customers/*.md')]
.reverse()
.slice(0, site.maxCustomerPerPage);
2020-07-16 00:11:48 +02:00
});
2020-07-17 23:58:03 +02:00
config.addCollection('partners', collection => {
return [...collection.getFilteredByGlob('./src/partners/*.md')]
.reverse()
.slice(0, site.maxPartnerPerPage);
2020-07-16 13:12:24 +02:00
});
2020-07-13 20:36:44 +02:00
2020-06-19 23:47:44 +02:00
// Plugins
config.addPlugin(rssPlugin);
config.addPlugin(syntaxHighlight);
// 404
config.setBrowserSyncConfig({
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: {
input: 'src',
output: 'dist'
},
passthroughFileCopy: true
2020-06-19 23:47:44 +02:00
};
}