forked from up-for-grabs/up-for-grabs.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectLoader.js
34 lines (28 loc) · 881 Bytes
/
projectLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* eslint block-scoped-var: "off" */
/// <reference types="node" />
// required for loading into a NodeJS context
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}
define(['showdown', 'whatwg-fetch', 'promise-polyfill'], (
/** @type {import('showdown')} */ showdown
) => {
const { fetch } = window;
function loadProjects() {
return fetch('/javascripts/projects.json')
.then((response) => response.json())
.then((files) => {
const converter = new showdown.Converter();
return Object.keys(files).map((key) => ({
...files[key],
desc: converter.makeHtml(files[key].desc),
}));
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error('Unable to load project files', error);
return [];
});
}
return loadProjects;
});