You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  1. const graphHelper = require('../../helpers/graph')
  2. const _ = require('lodash')
  3. const CleanCSS = require('clean-css')
  4. /* global WIKI */
  5. module.exports = {
  6. Query: {
  7. async theming() { return {} }
  8. },
  9. Mutation: {
  10. async theming() { return {} }
  11. },
  12. ThemingQuery: {
  13. async themes(obj, args, context, info) {
  14. return [{ // TODO
  15. key: 'default',
  16. title: 'Default',
  17. author: 'requarks.io'
  18. }]
  19. },
  20. async config(obj, args, context, info) {
  21. return _.pick(WIKI.config.theming, ['theme', 'iconset', 'darkMode', 'injectCSS', 'injectHead', 'injectBody'])
  22. }
  23. },
  24. ThemingMutation: {
  25. async setConfig(obj, args, context, info) {
  26. try {
  27. if (!_.isEmpty(args.injectCSS)) {
  28. args.injectCSS = new CleanCSS({
  29. inline: false
  30. }).minify(args.injectCSS).styles
  31. }
  32. WIKI.config.theming = {
  33. ...WIKI.config.theming,
  34. theme: args.theme,
  35. iconset: args.iconset,
  36. darkMode: args.darkMode,
  37. injectCSS: args.injectCSS || '',
  38. injectHead: args.injectHead || '',
  39. injectBody: args.injectBody || ''
  40. }
  41. await WIKI.configSvc.saveToDb(['theming'])
  42. return {
  43. responseResult: graphHelper.generateSuccess('Theme config updated')
  44. }
  45. } catch (err) {
  46. return graphHelper.generateError(err)
  47. }
  48. }
  49. }
  50. }