diff --git a/.eleventy.js b/.eleventy.js index 95ccb7f..5f136f8 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,27 +1,31 @@ -const rssPlugin = require('@11ty/eleventy-plugin-rss'); -const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight'); -const fs = require('fs'); -const util = require('util') +import rssPlugin from '@11ty/eleventy-plugin-rss'; +import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight'; +import fs from 'fs'; +import util from 'util'; // Import filters -const dateFilter = require('./src/filters/date-filter.js'); -const markdownFilter = require('./src/filters/markdown-filter.js'); -const w3DateFilter = require('./src/filters/w3-date-filter.js'); +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'; // Import transforms -const htmlMinTransform = require('./src/transforms/html-min-transform.js'); -const parseTransform = require('./src/transforms/parse-transform.js'); +import htmlMinTransform from './src/transforms/html-min-transform.js'; +import parseTransform from './src/transforms/parse-transform.js'; // 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 const site = require('./src/_data/site.json'); -module.exports = function(config) { +export default function(config) { // Filters config.addFilter('dateFilter', dateFilter); config.addFilter('markdownFilter', markdownFilter); config.addFilter('w3DateFilter', w3DateFilter); config.addFilter('dump', obj => { - return util.inspect(obj) + return util.inspect(obj); }); // Layout aliases @@ -48,11 +52,9 @@ module.exports = function(config) { const livePosts = post => post.date <= now && !post.data.draft; const newsPosts = post => post.data.type === 'news'; const eventPosts = post => post.data.type === 'event'; - + config.addCollection('posts', collection => { - return [ - ...collection.getFilteredByGlob('./src/posts/*.md') - ].reverse(); + return [...collection.getFilteredByGlob('./src/posts/*.md')].reverse(); }); config.addCollection('news', collection => { return [ @@ -70,56 +72,59 @@ module.exports = function(config) { .slice(0, site.maxNewsPerPage); }); config.addCollection('members', collection => { - return [...collection.getFilteredByGlob("./src/members/*.md")]; + return [...collection.getFilteredByGlob('./src/members/*.md')]; }); config.addCollection('profiles', collection => { - return [...collection.getFilteredByGlob("./src/members/*.md")] - .reverse() - .slice(0, site.maxProfilePreview) - ; + return [...collection.getFilteredByGlob('./src/members/*.md')] + .reverse() + .slice(0, site.maxProfilePreview); }); - config.addCollection("tagsList", function(collectionApi) { + config.addCollection('tagsList', function(collectionApi) { 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)) - } + collectionApi.getAll().map(item => { + if (item.data.tags) { + // handle pages that don't have tags + item.data.tags.map(tag => tagsList.add(tag)); + } }); return tagsList; }); - config.addCollection("skillsList", function(collectionApi) { + config.addCollection('skillsList', function(collectionApi) { 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) - } - }) - } + 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); + } + }); + } }); return skillsList; }); - config.addCollection("membersLocations", function(collectionApi) { - return collectionApi.getFilteredByGlob("./src/members/*.md") + config.addCollection('membersLocations', function(collectionApi) { + return collectionApi + .getFilteredByGlob('./src/members/*.md') .filter(item => typeof item.data.location !== 'undefined') - .map( member => { + .map(member => { return { name: member.data.name, url: member.data.url, - location: member.data.location, + location: member.data.location }; - }); + }); }); config.addCollection('customers', collection => { - return [...collection.getFilteredByGlob("./src/customers/*.md")] - .reverse() - .slice(0, site.maxCustomerPerPage); + return [...collection.getFilteredByGlob('./src/customers/*.md')] + .reverse() + .slice(0, site.maxCustomerPerPage); }); config.addCollection('partners', collection => { - return [...collection.getFilteredByGlob("./src/partners/*.md")] - .reverse() - .slice(0, site.maxPartnerPerPage); + return [...collection.getFilteredByGlob('./src/partners/*.md')] + .reverse() + .slice(0, site.maxPartnerPerPage); }); // Plugins @@ -146,6 +151,6 @@ module.exports = function(config) { input: 'src', output: 'dist' }, - passthroughFileCopy: true, + passthroughFileCopy: true }; -}; +} diff --git a/package.json b/package.json index 75bbcd1..6259c7d 100755 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "description": "Site web de la coopérative Astrolabe CAE", "main": "index.js", + "type": "module", "dependencies": { "@11ty/eleventy": "^3.0.0", "@11ty/eleventy-plugin-rss": "^2.0.2", diff --git a/src/_data/global.js b/src/_data/global.js index 683a0a3..5852884 100644 --- a/src/_data/global.js +++ b/src/_data/global.js @@ -1,4 +1,4 @@ -module.exports = { +export default { random() { const segment = () => { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); diff --git a/src/_data/helpers.js b/src/_data/helpers.js index 9ae9b78..c1a8429 100644 --- a/src/_data/helpers.js +++ b/src/_data/helpers.js @@ -1,4 +1,4 @@ -module.exports = { +export default { getNextHeadingLevel(currentLevel) { return parseInt(currentLevel, 10) + 1; }, diff --git a/src/_data/styleguide.js b/src/_data/styleguide.js index 4969bec..baa36b3 100644 --- a/src/_data/styleguide.js +++ b/src/_data/styleguide.js @@ -1,6 +1,11 @@ +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 + const tokens = require('./tokens.json'); -module.exports = { +export default { colors() { let response = []; diff --git a/src/_includes/partials/global/meta-info.njk b/src/_includes/partials/global/meta-info.njk index 1742f0a..b0e172c 100644 --- a/src/_includes/partials/global/meta-info.njk +++ b/src/_includes/partials/global/meta-info.njk @@ -7,8 +7,8 @@ {% set pageTitle = metaTitle %} {% endif %} -{% if metaDesc %} - {% set pageDesc = metaDesc %} +{% if description %} + {% set pageDesc = description %} {% endif %}