aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/theme-utils.ts
blob: 066339e65e32065a50d8285960b6e566188f7227 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { DEFAULT_THEME } from '../../initializers/constants'
import { PluginManager } from './plugin-manager'
import { CONFIG } from '../../initializers/config'

function getThemeOrDefault (name: string) {
  if (isThemeRegistered(name)) return name

  // Fallback to admin default theme
  if (name !== CONFIG.THEME.DEFAULT) return getThemeOrDefault(CONFIG.THEME.DEFAULT)

  return DEFAULT_THEME
}

function isThemeRegistered (name: string) {
  if (name === DEFAULT_THEME) return true

  return !!PluginManager.Instance.getRegisteredThemes()
                        .find(r => r.name === name)
}

export {
  getThemeOrDefault,
  isThemeRegistered
}