Skip to content

Commit

Permalink
feat: generate URLs to submission files (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
greatislander authored Apr 30, 2024
1 parent 8da2d72 commit 6db5c15
Show file tree
Hide file tree
Showing 50 changed files with 463 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cache
.DS_Store
**/.DS_Store
node_modules
Expand Down
41 changes: 41 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ const fluidPlugin = require("eleventy-plugin-fluid");
const navigationPlugin = require("@11ty/eleventy-navigation");
const { EleventyI18nPlugin } = require("@11ty/eleventy");
const pluginPWA = require("eleventy-plugin-pwa-v2");
const brokenLinksPlugin = require("eleventy-plugin-broken-links");
const getYouTubeID = require("get-youtube-id");
const title = require("title");
const slugify = require("@sindresorhus/slugify");
const rosetta = require("rosetta");
const i18n = rosetta();
i18n.locale("en");
Expand Down Expand Up @@ -59,6 +61,15 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addFilter("youtubeId", function (value) {
return getYouTubeID(value);
});
eleventyConfig.addFilter("englishTitle", function (id) {
const collections = this.ctx?.collections || {};
const submissions = collections.submissions_en || [];
const submission = submissions.find(item => item.data.id === id);
if (submission) {
return submission.data.title;
}
throw new Error(`Unknown submission ID: "${id}"`);
});

// Shortcodes
eleventyConfig.addShortcode("localizedFormat", function (format, formatLocale, langOverride) {
Expand All @@ -67,6 +78,30 @@ module.exports = function (eleventyConfig) {
return i18n.t(`submission-formats.${format}`, {formatLocale: i18n.t(`languages.${formatLocale}`, {}, lang)}, lang);
});

eleventyConfig.addShortcode("formatUrl", function (submissionId, format, formatLocale) {
const collections = this.ctx?.collections || {};
const submissions = collections.submissions_en || [];
const submission = submissions.find(item => item.data.id === submissionId);
if (submission) {
let extension;
const slug = slugify(submission.data.title);
switch (format) {
case "slides":
extension = "pptx";
break;
default:
extension = "docx";
};

if (format === "pdf") {
return `https://idrc.cachefly.net/acaw-cama/${submissionId}/${slug}-text-${formatLocale}.pdf`;
}

return `https://idrc.cachefly.net/acaw-cama/${submissionId}/${slug}-${format}-${formatLocale}.${extension}`;
}
throw new Error(`Unknown submission ID: "${submissionId}"`);
});

// Transforms
eleventyConfig.addTransform("parse", parseTransform);

Expand All @@ -78,6 +113,12 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({"src/assets/uploads": "assets/uploads"});

// Plugins
eleventyConfig.addPlugin(brokenLinksPlugin, {
forbidden: "error",
broken: "error",
cacheDuration: "60s",
loggingLevel: 1
});
eleventyConfig.addPlugin(navigationPlugin);
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en"
Expand Down
Loading

0 comments on commit 6db5c15

Please sign in to comment.