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.

62 lines
1.6 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 {
  22. theme: WIKI.config.theming.theme,
  23. iconset: WIKI.config.theming.iconset,
  24. darkMode: WIKI.config.theming.darkMode,
  25. injectCSS: new CleanCSS({ format: 'beautify' }).minify(WIKI.config.theming.injectCSS).styles,
  26. injectHead: WIKI.config.theming.injectHead,
  27. injectBody: WIKI.config.theming.injectBody
  28. }
  29. }
  30. },
  31. ThemingMutation: {
  32. async setConfig(obj, args, context, info) {
  33. try {
  34. if (!_.isEmpty(args.injectCSS)) {
  35. args.injectCSS = new CleanCSS({
  36. inline: false
  37. }).minify(args.injectCSS).styles
  38. }
  39. WIKI.config.theming = {
  40. ...WIKI.config.theming,
  41. theme: args.theme,
  42. iconset: args.iconset,
  43. darkMode: args.darkMode,
  44. injectCSS: args.injectCSS || '',
  45. injectHead: args.injectHead || '',
  46. injectBody: args.injectBody || ''
  47. }
  48. await WIKI.configSvc.saveToDb(['theming'])
  49. return {
  50. responseResult: graphHelper.generateSuccess('Theme config updated')
  51. }
  52. } catch (err) {
  53. return graphHelper.generateError(err)
  54. }
  55. }
  56. }
  57. }