mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Content API Cache improvements (#12020)
* content api improvements * add content cache to build step * add tests
This commit is contained in:
21
website/server/libs/content.js
Normal file
21
website/server/libs/content.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import _ from 'lodash';
|
||||
import path from 'path';
|
||||
import common from '../../common';
|
||||
|
||||
export const CONTENT_CACHE_PATH = path.join(__dirname, '/../../../content_cache/');
|
||||
|
||||
function walkContent (obj, lang) {
|
||||
_.each(obj, (item, key, source) => {
|
||||
if (_.isPlainObject(item) || _.isArray(item)) {
|
||||
walkContent(item, lang);
|
||||
} else if (_.isFunction(item) && item.i18nLangFunc) {
|
||||
source[key] = item(lang);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function getLocalizedContent (langCode) {
|
||||
const contentClone = _.cloneDeep(common.content);
|
||||
walkContent(contentClone, langCode);
|
||||
return `{"success": true, "data": ${JSON.stringify(contentClone)}}`;
|
||||
}
|
||||
Reference in New Issue
Block a user