add: pairwise elo voting workflow
This commit is contained in:
@@ -24,6 +24,20 @@ function escapeHtml(value) {
|
||||
.replace(/"/g, """);
|
||||
}
|
||||
|
||||
function serializeJsonForHtml(value) {
|
||||
return JSON.stringify(value, null, 2)
|
||||
.replace(/</g, "\\u003c")
|
||||
.replace(/\u2028/g, "\\u2028")
|
||||
.replace(/\u2029/g, "\\u2029");
|
||||
}
|
||||
|
||||
function indentBlock(text, indent) {
|
||||
return text
|
||||
.split("\n")
|
||||
.map((line) => `${indent}${line}`)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function renderGalleryItem(meal, eol) {
|
||||
const attrs = [`class="thumbnail"`, `href="images/fulls/${meal.id}.jpg"`];
|
||||
|
||||
@@ -53,7 +67,7 @@ function renderRankingSummary(meals, eloData) {
|
||||
|
||||
return `\t\t\t\t<p class="ranking-summary">${meals.length} ${mealLabel} seeded at Elo ${formatRating(
|
||||
eloData.defaultRating
|
||||
)} until head-to-head voting starts.</p>`;
|
||||
)}. Enable JavaScript to vote and reorder them.</p>`;
|
||||
}
|
||||
|
||||
function renderRankingMeta(rankedMeal) {
|
||||
@@ -91,6 +105,16 @@ function renderRankings(rankedMeals, eol) {
|
||||
.join(eol);
|
||||
}
|
||||
|
||||
function renderRankingsSeedData(meals, eloData) {
|
||||
return indentBlock(
|
||||
serializeJsonForHtml({
|
||||
meals,
|
||||
elo: eloData,
|
||||
}),
|
||||
"\t\t\t"
|
||||
);
|
||||
}
|
||||
|
||||
function replaceBlock(template, token, replacement) {
|
||||
const pattern = new RegExp(`^[\\t ]*\\{\\{${token}\\}\\}$`, "m");
|
||||
|
||||
@@ -120,8 +144,13 @@ function buildRankings(
|
||||
"ranking_summary",
|
||||
renderRankingSummary(meals, eloData)
|
||||
);
|
||||
const withSeedData = replaceBlock(
|
||||
withSummary,
|
||||
"rankings_seed_data",
|
||||
renderRankingsSeedData(meals, eloData)
|
||||
);
|
||||
|
||||
return replaceBlock(withSummary, "ranking_items", renderRankings(rankedMeals, eol));
|
||||
return replaceBlock(withSeedData, "ranking_items", renderRankings(rankedMeals, eol));
|
||||
}
|
||||
|
||||
function writeFile(filePath, contents) {
|
||||
|
||||
Reference in New Issue
Block a user