diff --git a/gulpfile.esm.js/plugins/autoindex.js b/gulpfile.esm.js/plugins/autoindex.js index 28587735c9abc04b0c6503a8f8b0156ec3d42a07..6c705d93e28efa4343d71dd35ae1ccda559a02a8 100644 --- a/gulpfile.esm.js/plugins/autoindex.js +++ b/gulpfile.esm.js/plugins/autoindex.js @@ -76,7 +76,58 @@ function getPrezFilename(input) { return prez.relative; } +function renderInput(input) { + return `- [${input.titleBlock.title}](${getPrezFilename(input)})` + + `[<img class="plain icon" src="file_pdf.png"/>](${getPDFOutput(input).relative})`; +} + +function renderByTitleSlide(initials, inputs) { + const groupTitle = initials.length === 1 ? initials[0] : `${initials[0]}-${initials[initials.length-1]}`; + return `## ${groupTitle}\n\n` + inputs.map(renderInput).join("\n"); +} + +function groupByTitleInitial(inputs) { + const byInitials = {}; + inputs.forEach((input) => { + const title = input.titleBlock.title.toUpperCase(); + const letter = title[title.search(/[A-Z]/)]; + if (!byInitials[letter]) { + byInitials[letter] = [input]; + } else { + byInitials[letter].push(input); + } + }); + return byInitials; +} + +function groupByTitle(inputs) { + const byInitials = groupByTitleInitial(inputs); + const initials = Object.keys(byInitials).sort(); + + const groups = []; + let group = ''; + let groupSlides = []; + initials.forEach((initial) => { + const slides = byInitials[initial]; + if (groupSlides.length + slides.length > 10) { + groups.push([group, groupSlides]); + group = ''; + groupSlides = []; + } + group += initial; + groupSlides.push(...slides); + }); + if (groupSlides.length > 0) { + groups.push([group, groupSlides]); + } + + return groups; +} + function renderIndex(inputs) { + const groups = groupByTitle(inputs); + const slides = groups.map(([group, slides]) => renderByTitleSlide(group, slides)).join("\n\n"); + return `% Présentations % Dev@Science % ${new Date().toLocaleDateString("fr-FR", { @@ -85,23 +136,12 @@ function renderIndex(inputs) { day: "2-digit", })} -# Présentations - -<style> -.reveal section img.icon {vertical-align:top;margin:0;height:1em} -.reveal ul {display:flex;width:100%;max-height:50vh;flex-flow:column wrap;list-style-type:none;justify-content:center} -.reveal ul li {display:inline;width:auto} -</style> - -${inputs - .map( - (input) => - `- [${input.titleBlock.title}](${getPrezFilename(input)})` + - `[<img class="plain icon" src="file_pdf.png"/>](${ - getPDFOutput(input).relative - })` - ) - .join("\n")}`; +# Par titre + <style> + .reveal section img.icon {vertical-align:top;margin:0;height:1em} + </style> + +${slides}`; } export default function autoindex() {