module J1App def self.config_file File.join(Dir.pwd, '_config.yml') # File.join(Dir.pwd, "_config.develop.yml") end def self.jekyll_config @config ||= YAML.safe_load_file(config_file) rescue StandardError {} end def self.destination jekyll_config.fetch('destination', File.expand_path('_site', Dir.pwd)) end def self.auth_config jekyll_config.fetch('j1_auth', {}) end def self.auth? !!auth_config['enabled'] end def self.ssl? !!auth_config['ssl'] end def self.whitelist whitelist = auth_config['whitelist'] Regexp.new(whitelist.join("|")) unless whitelist.nil? end def self.public_content public_content = auth_config['content']['public'] Regexp.new(public_content.join("|")) unless public_content.nil? end def self.active_providers auth_config['providers']['activated'] end def self.default_provider auth_config['providers']['activated'][0] end def self.permissions permission_profile = { :private => [], :premium => [] } active_providers = auth_config['providers']['activated'] for p in active_providers do provider_permissions = auth_config['providers']["#{p}"]['permissions'] provider_permissions.each do |perm| permission_profile[:"#{perm}"] << "#{p}" end end permission_profile end def self.get_condition(arg) auth_config['provider']['condition']["#{arg}"] end def self.conditions (arg) condition_profile = {} provider = arg provider_conditions = auth_config['providers']["#{provider}"]['conditions'] provider_conditions.each do |key, value| condition_profile[key] = value end condition_profile end class ConfigError < RuntimeError def message "J1App is refusing to serve your site because your OAuth credentials are not properly configured" end end # def self.provider_url(arg) # provider_url = { # 'patreon' => auth_config['provider']['home_url']['patreon'], # 'disqus' => auth_config['provider']['home_url']['disqus'], # 'facebook' => auth_config['provider']['home_url']['facebook'], # 'github' => auth_config['provider']['home_url']['github'], # 'twitter' => auth_config['provider']['home_url']['twitter'] # } # provider_url[arg] # end # def self.provider_scope(arg) # provider_scope = { # 'patreon' => auth_config['provider']['scope']['patreon'], # 'disqus' => auth_config['provider']['scope']['disqus'], # 'facebook' => auth_config['provider']['scope']['facebook'], # 'github' => auth_config['provider']['scope']['github'], # 'twitter' => auth_config['provider']['scope']['twitter'] # } # provider_scope[arg].join(',') # end # def self.provider_data(arg) # provider_data = { # 'patreon' => auth_config['provider']['data']['patreon'], # 'disqus' => auth_config['provider']['data']['disqus'], # 'facebook' => auth_config['provider']['data']['facebook'], # 'github' => auth_config['provider']['data']['github'], # 'twitter' => auth_config['provider']['data']['twitter'] # } # provider_data[arg].join(',') # end # def self.provider_condition(arg) # provider_condition = { # 'patreon' => auth_config['provider']['condition']['patreon'], # 'disqus' => auth_config['provider']['condition']['disqus'], # 'facebook' => auth_config['provider']['condition']['facebook'], # 'github' => auth_config['provider']['condition']['github'], # 'twitter' => auth_config['provider']['condition']['twitter'] # } # provider_condition[arg] # end # def self.permissions_old # permission_profile = { # :private => [], # :premium => [] # } # # provider_permissions = auth_config['provider']['permission'] # provider_permissions.each do |key, value| # my_key = key # value.each { |perm| permission_profile[:"#{perm}"] << key } # end # permission_profile # end # def self.get_provider_permissions (arg) # auth_config['provider']['permission']["#{arg}"].join(',') # end # def self.users # user_profile = {} # # provider_users = auth_config['provider']['user'] # provider_users.each do |key, value| # user_profile[key] = value # end # user_profile # end # def self.strategies # strategy_profile = {} # # provider_strategies = auth_config['provider']['strategy'] # provider_strategies.each do |key, value| # strategy_profile[key] = :"#{value}" # end # strategy_profile # end end