Remove duplicate code

This commit is contained in:
vjrj 2018-01-22 13:32:36 +01:00
parent 6c8fa91f64
commit af4a92cd2a

View file

@ -1,35 +1,15 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import i18n from 'i18next';
import fs from 'fs';
import { getFileNameOfLang } from '/imports/api/Utility/server/files.js';
import getPrivateFile from '../../../modules/server/get-private-file';
import parseMarkdown from '../../../modules/parse-markdown';
const as = f => `assets/app/${f}`;
const getFallback = (lang) => {
if (lang === 'ast' || lang === 'gl' || lang === 'eu' || lang === 'ca') {
return 'es';
}
return 'en';
};
Meteor.methods({
'utility.getPage': function utilityGetPage(fileName, lang) {
check(fileName, String);
check(lang, String);
const base = `pages/${fileName}`;
const fallback = getFallback(lang);
let file = `${base}-${lang}.md`;
if (!fs.existsSync(as(file))) {
console.log(`Page '${fileName}' not found for '${lang}' lang`);
file = `${base}-${fallback}.md`;
if (!fs.existsSync(as(file))) {
console.log(`Page '${fileName}' not found for '${fallback}' lang`);
file = `${base}.md`;
}
}
return parseMarkdown(getPrivateFile(file));
return parseMarkdown(getPrivateFile(getFileNameOfLang('pages', fileName, 'md', lang)));
},
'utility.saveMissingI18n': function saveMissing(key, value) {
check(key, String);