feat: locales availability + IE display mode
This commit is contained in:
@@ -195,7 +195,15 @@ router.get('/*', async (req, res, next) => {
|
||||
head: WIKI.config.theming.injectHead,
|
||||
body: WIKI.config.theming.injectBody
|
||||
}
|
||||
res.render('page', { page, sidebar, injectCode })
|
||||
|
||||
if (req.query.legacy || req.get('user-agent').indexOf('Trident') >= 0) {
|
||||
if (_.isString(page.toc)) {
|
||||
page.toc = JSON.parse(page.toc)
|
||||
}
|
||||
res.render('legacy', { page, sidebar, injectCode })
|
||||
} else {
|
||||
res.render('page', { page, sidebar, injectCode })
|
||||
}
|
||||
} else if (pageArgs.path === 'home') {
|
||||
_.set(res.locals, 'pageMeta.title', 'Welcome')
|
||||
res.render('welcome')
|
||||
|
13
server/db/migrations-sqlite/2.0.0-beta.217.js
Normal file
13
server/db/migrations-sqlite/2.0.0-beta.217.js
Normal file
@@ -0,0 +1,13 @@
|
||||
exports.up = knex => {
|
||||
return knex.schema
|
||||
.table('locales', table => {
|
||||
table.integer('availability').notNullable().defaultTo(0)
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => {
|
||||
return knex.schema
|
||||
.table('locales', table => {
|
||||
table.dropColumn('availability')
|
||||
})
|
||||
}
|
13
server/db/migrations/2.0.0-beta.217.js
Normal file
13
server/db/migrations/2.0.0-beta.217.js
Normal file
@@ -0,0 +1,13 @@
|
||||
exports.up = knex => {
|
||||
return knex.schema
|
||||
.table('locales', table => {
|
||||
table.integer('availability').notNullable().defaultTo(0)
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => {
|
||||
return knex.schema
|
||||
.table('locales', table => {
|
||||
table.dropColumn('availability')
|
||||
})
|
||||
}
|
@@ -13,7 +13,7 @@ module.exports = {
|
||||
LocalizationQuery: {
|
||||
async locales(obj, args, context, info) {
|
||||
let remoteLocales = await WIKI.cache.get('locales')
|
||||
let localLocales = await WIKI.models.locales.query().select('code', 'isRTL', 'name', 'nativeName', 'createdAt', 'updatedAt')
|
||||
let localLocales = await WIKI.models.locales.query().select('code', 'isRTL', 'name', 'nativeName', 'createdAt', 'updatedAt', 'availability')
|
||||
remoteLocales = remoteLocales || localLocales
|
||||
return _.map(remoteLocales, rl => {
|
||||
let isInstalled = _.some(localLocales, ['code', rl.code])
|
||||
|
@@ -95,6 +95,16 @@ module.exports = {
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
},
|
||||
async migrateToLocale(obj, args, context) {
|
||||
try {
|
||||
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Migrated all content to target locale successfully.')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
Page: {
|
||||
|
@@ -42,6 +42,7 @@ type LocalizationMutation {
|
||||
# -----------------------------------------------
|
||||
|
||||
type LocalizationLocale {
|
||||
availability: Int!
|
||||
code: String!
|
||||
createdAt: Date!
|
||||
installDate: Date
|
||||
|
@@ -73,6 +73,8 @@ type PageMutation {
|
||||
): DefaultResponse @auth(requires: ["delete:pages", "manage:system"])
|
||||
|
||||
flushCache: DefaultResponse @auth(requires: ["manage:system"])
|
||||
|
||||
migrateToLocale: DefaultResponse @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
|
@@ -28,21 +28,30 @@ module.exports = async (localeCode) => {
|
||||
let lcObj = {}
|
||||
_.forEach(strings, row => {
|
||||
if (_.includes(row.key, '::')) { return }
|
||||
if (_.isEmpty(row.value)) { row.value = row.key }
|
||||
if (_.isEmpty(row.value)) {
|
||||
row.value = row.key
|
||||
}
|
||||
_.set(lcObj, row.key.replace(':', '.'), row.value)
|
||||
})
|
||||
|
||||
const locales = await WIKI.cache.get('locales')
|
||||
if (locales) {
|
||||
const currentLocale = _.find(locales, ['code', localeCode]) || {}
|
||||
await WIKI.models.locales.query().delete().where('code', localeCode)
|
||||
await WIKI.models.locales.query().insert({
|
||||
code: localeCode,
|
||||
strings: lcObj,
|
||||
isRTL: currentLocale.isRTL,
|
||||
name: currentLocale.name,
|
||||
nativeName: currentLocale.nativeName
|
||||
})
|
||||
const existingLocale = await WIKI.models.locales.query().where('code', localeCode)
|
||||
if (existingLocale) {
|
||||
await WIKI.models.locales.query().patch({
|
||||
strings: lcObj
|
||||
}).where('code', localeCode)
|
||||
} else {
|
||||
await WIKI.models.locales.query().insert({
|
||||
code: localeCode,
|
||||
strings: lcObj,
|
||||
isRTL: currentLocale.isRTL,
|
||||
name: currentLocale.name,
|
||||
nativeName: currentLocale.nativeName,
|
||||
availability: currentLocale.availability
|
||||
})
|
||||
}
|
||||
} else {
|
||||
throw new Error('Failed to fetch cached locales list! Restart server to resolve this issue.')
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ module.exports = async () => {
|
||||
query: `{
|
||||
localization {
|
||||
locales {
|
||||
availability
|
||||
code
|
||||
name
|
||||
nativeName
|
||||
@@ -54,7 +55,9 @@ module.exports = async () => {
|
||||
let lcObj = {}
|
||||
_.forEach(strings, row => {
|
||||
if (_.includes(row.key, '::')) { return }
|
||||
if (_.isEmpty(row.value)) { row.value = row.key }
|
||||
if (_.isEmpty(row.value)) {
|
||||
row.value = row.key
|
||||
}
|
||||
_.set(lcObj, row.key.replace(':', '.'), row.value)
|
||||
})
|
||||
|
||||
@@ -63,7 +66,8 @@ module.exports = async () => {
|
||||
strings: lcObj,
|
||||
isRTL: localeInfo.isRTL,
|
||||
name: localeInfo.name,
|
||||
nativeName: localeInfo.nativeName
|
||||
nativeName: localeInfo.nativeName,
|
||||
availability: localeInfo.availability
|
||||
}).where('code', currentLocale)
|
||||
|
||||
WIKI.logger.info(`Pulled latest locale updates for ${localeInfo.name} from Graph endpoint: [ COMPLETED ]`)
|
||||
|
@@ -20,7 +20,8 @@ module.exports = class Locale extends Model {
|
||||
name: {type: 'string'},
|
||||
nativeName: {type: 'string'},
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
updatedAt: {type: 'string'},
|
||||
availability: {type: 'integer'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user