feat: sideloading + locales nav menu

This commit is contained in:
Nick
2019-06-21 20:54:09 -04:00
parent e4fc2b7b12
commit 28cf67cdaa
12 changed files with 151 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
const Model = require('objection').Model
/* global WIKI */
/**
* Locales model
*/
@@ -34,4 +36,27 @@ module.exports = class Locale extends Model {
this.createdAt = new Date().toISOString()
this.updatedAt = new Date().toISOString()
}
static async getNavLocales({ cache = false } = {}) {
if (!WIKI.config.lang.namespacing) {
return []
}
if (cache) {
const navLocalesCached = await WIKI.cache.get('nav:locales')
if (navLocalesCached) {
return navLocalesCached
}
}
const navLocales = await WIKI.models.locales.query().select('code', 'nativeName AS name').whereIn('code', WIKI.config.lang.namespaces).orderBy('code')
if (navLocales) {
if (cache) {
await WIKI.cache.set('nav:locales', navLocales, 300)
}
return navLocales
} else {
WIKI.logger.warn('Site Locales for navigation are missing or corrupted.')
return []
}
}
}