wikijs-fork/server/graph/resolvers/theming.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-06-11 03:23:09 +00:00
const graphHelper = require('../../helpers/graph')
2019-01-26 02:29:34 +00:00
const _ = require('lodash')
const CleanCSS = require('clean-css')
2018-06-11 03:23:09 +00:00
/* global WIKI */
module.exports = {
Query: {
async theming() { return {} }
},
Mutation: {
async theming() { return {} }
},
ThemingQuery: {
async themes(obj, args, context, info) {
return [{ // TODO
key: 'default',
title: 'Default',
author: 'requarks.io'
}]
},
async config(obj, args, context, info) {
2019-07-13 05:45:03 +00:00
return _.pick(WIKI.config.theming, ['theme', 'iconset', 'darkMode', 'injectCSS', 'injectHead', 'injectBody'])
2018-06-11 03:23:09 +00:00
}
},
ThemingMutation: {
async setConfig(obj, args, context, info) {
try {
2019-01-26 02:29:34 +00:00
if (!_.isEmpty(args.injectCSS)) {
args.injectCSS = new CleanCSS({
inline: false
}).minify(args.injectCSS).styles
}
WIKI.config.theming = {
...WIKI.config.theming,
theme: args.theme,
2019-07-13 05:45:03 +00:00
iconset: args.iconset,
2019-01-26 02:29:34 +00:00
darkMode: args.darkMode,
injectCSS: args.injectCSS || '',
injectHead: args.injectHead || '',
injectBody: args.injectBody || ''
}
2018-06-11 03:23:09 +00:00
await WIKI.configSvc.saveToDb(['theming'])
return {
responseResult: graphHelper.generateSuccess('Theme config updated')
}
} catch (err) {
return graphHelper.generateError(err)
}
}
}
}