lbry-desktop/web/src/getHomepageJSON.js
infinite-persistence 45bb9ad0fa Homepage API v2: includes meme
Ticket: 1318

Had to create v2 as there is no backward-compatible location in the v1 json to place it.

v2 allows any future expansion beyond 'categories' and 'meme'.

One-meme-per-homepage is also supported, but not enabled for now.
2022-04-15 09:25:08 -04:00

39 lines
819 B
JavaScript

const memo = {};
// this didn't seem to help.
if (!memo.homepageData) {
try {
memo.homepageData = require('../../custom/homepages/v2');
memo.meme = require('../../custom/homepages/meme');
} catch (err) {
console.log('getHomepageJSON:', err);
}
}
const getHomepageJsonV1 = () => {
return memo.homepageData || {};
};
const getHomepageJsonV2 = () => {
if (!memo.homepageData) {
return {};
}
const v2 = {};
const homepageKeys = Object.keys(memo.homepageData);
homepageKeys.forEach((hp) => {
v2[hp] = {
categories: memo.homepageData[hp],
};
});
if (memo.meme && v2['en']) {
// Only supporting English memes for now, but one-per-homepage is possible.
v2['en'].meme = memo.meme;
}
return v2;
};
module.exports = { getHomepageJsonV1, getHomepageJsonV2 };