customize.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const logger = require('@alias/logger')('growi:service:CustomizeService'); // eslint-disable-line no-unused-vars
  2. /**
  3. * the service class of CustomizeService
  4. */
  5. class CustomizeService {
  6. constructor(configManager, appService, xssService, Config) {
  7. this.configManager = configManager;
  8. this.appService = appService;
  9. this.xssService = xssService;
  10. // === TODO remove after GC-2004
  11. this.Config = Config;
  12. }
  13. /**
  14. * initialize custom css strings
  15. */
  16. initCustomCss() {
  17. const uglifycss = require('uglifycss');
  18. const rawCss = this.configManager.getConfig('crowi', 'customize:css') || '';
  19. // uglify and store
  20. this.customCss = uglifycss.processString(rawCss);
  21. }
  22. getCustomCss() {
  23. return this.customCss;
  24. }
  25. getCustomScript() {
  26. return this.configManager.getConfig('crowi', 'customize:script') || '';
  27. }
  28. initCustomTitle() {
  29. let configValue = this.configManager.getConfig('crowi', 'customize:title');
  30. if (configValue == null || configValue.trim().length === 0) {
  31. configValue = '{{page}} - {{sitename}}';
  32. }
  33. this.customTitleTemplate = configValue;
  34. }
  35. generateCustomTitle(page) {
  36. // replace
  37. const customTitle = this.customTitleTemplate
  38. .replace('{{sitename}}', this.Config.appTitle())
  39. // === TODO fix after refactoring AppService (GC-2004)
  40. // .replace('{{sitename}}', this.appService.getAppTitle())
  41. .replace('{{page}}', page);
  42. return this.xssService.process(customTitle);
  43. }
  44. }
  45. module.exports = CustomizeService;