theming.js 1.9 KB

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