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.

No related merge requests found
Showing with 57 additions and 17 deletions
+57 -17
...@@ -76,7 +76,58 @@ function getPrezFilename(input) { ...@@ -76,7 +76,58 @@ function getPrezFilename(input) {
return prez.relative; 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) { function renderIndex(inputs) {
const groups = groupByTitle(inputs);
const slides = groups.map(([group, slides]) => renderByTitleSlide(group, slides)).join("\n\n");
return `% Présentations return `% Présentations
% Dev@Science % Dev@Science
% ${new Date().toLocaleDateString("fr-FR", { % ${new Date().toLocaleDateString("fr-FR", {
...@@ -85,23 +136,12 @@ function renderIndex(inputs) { ...@@ -85,23 +136,12 @@ function renderIndex(inputs) {
day: "2-digit", day: "2-digit",
})} })}
# Présentations # Par titre
<style>
<style> .reveal section img.icon {vertical-align:top;margin:0;height:1em}
.reveal section img.icon {vertical-align:top;margin:0;height:1em} </style>
.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} ${slides}`;
</style>
${inputs
.map(
(input) =>
`- [${input.titleBlock.title}](${getPrezFilename(input)})` +
`[<img class="plain icon" src="file_pdf.png"/>](${
getPDFOutput(input).relative
})`
)
.join("\n")}`;
} }
export default function autoindex() { export default function autoindex() {
......
Supports Markdown
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