Commit 8b562ca6 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Groupe les présentations par initial de leur titre dans l'index.

parent 40005e9e
......@@ -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() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment