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

65 lines
1.7 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) {
return {
theme: WIKI.config.theming.theme,
iconset: WIKI.config.theming.iconset,
darkMode: WIKI.config.theming.darkMode,
2022-12-10 22:03:40 +00:00
tocPosition: WIKI.config.theming.tocPosition || 'left',
injectCSS: new CleanCSS({ format: 'beautify' }).minify(WIKI.config.theming.injectCSS).styles,
injectHead: WIKI.config.theming.injectHead,
injectBody: WIKI.config.theming.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,
2022-12-10 22:03:40 +00:00
tocPosition: args.tocPosition || 'left',
2019-01-26 02:29:34 +00:00
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)
}
}
}
}