customize.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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) {
  7. this.configManager = configManager;
  8. this.appService = appService;
  9. this.xssService = xssService;
  10. }
  11. /**
  12. * initialize custom css strings
  13. */
  14. initCustomCss() {
  15. const uglifycss = require('uglifycss');
  16. const rawCss = this.configManager.getConfig('crowi', 'customize:css') || '';
  17. // uglify and store
  18. this.customCss = uglifycss.processString(rawCss);
  19. }
  20. getCustomCss() {
  21. return this.customCss;
  22. }
  23. getCustomScript() {
  24. return this.configManager.getConfig('crowi', 'customize:script') || '';
  25. }
  26. initCustomTitle() {
  27. let configValue = this.configManager.getConfig('crowi', 'customize:title');
  28. if (configValue == null || configValue.trim().length === 0) {
  29. configValue = '{{page}} - {{sitename}}';
  30. }
  31. this.customTitleTemplate = configValue;
  32. }
  33. generateCustomTitle(page) {
  34. // replace
  35. const customTitle = this.customTitleTemplate
  36. .replace('{{sitename}}', this.appService.getAppTitle())
  37. .replace('{{page}}', page);
  38. return this.xssService.process(customTitle);
  39. }
  40. }
  41. module.exports = CustomizeService;