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.

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