discourse/app/controllers/site_controller.rb
Vinoth Kannan b3238bfc34
FEATURE: call hub API to update Discourse discover enrollment. (#25634)
Now forums can enroll their sites to be showcased in the Discourse [Discover](https://discourse.org/discover) directory. Once they enable the site setting `include_in_discourse_discover` to enroll their forum the `CallDiscourseHub` job will ping the `api.discourse.org/api/discover/enroll` endpoint. Then the Discourse Hub will fetch the basic details from the forum and add it to the review queue. If the site is approved then the forum details will be displayed in the `/discover` page.
2024-02-23 11:42:28 +05:30

58 lines
1.7 KiB
Ruby

# frozen_string_literal: true
class SiteController < ApplicationController
layout false
skip_before_action :preload_json, :check_xhr
skip_before_action :redirect_to_login_if_required, only: %w[basic_info statistics]
def site
render json: Site.json_for(guardian)
end
def settings
render json: SiteSetting.client_settings_json
end
def custom_html
render json: custom_html_json
end
def banner
render json: banner_json
end
def emoji
render json: custom_emoji
end
def basic_info
results = {
logo_url: UrlHelper.absolute(SiteSetting.site_logo_url),
logo_small_url: UrlHelper.absolute(SiteSetting.site_logo_small_url),
apple_touch_icon_url: UrlHelper.absolute(SiteSetting.site_apple_touch_icon_url),
favicon_url: UrlHelper.absolute(SiteSetting.site_favicon_url),
title: SiteSetting.title,
description: SiteSetting.site_description,
header_primary_color: ColorScheme.hex_for_name("header_primary") || "333333",
header_background_color: ColorScheme.hex_for_name("header_background") || "ffffff",
login_required: SiteSetting.login_required,
}
if mobile_logo_url = SiteSetting.site_mobile_logo_url.presence
results[:mobile_logo_url] = UrlHelper.absolute(mobile_logo_url)
end
results[:discourse_discover_enrolled] = true if SiteSetting.include_in_discourse_discover?
DiscourseHub.stats_fetched_at = Time.zone.now if request.user_agent == "Discourse Hub"
# this info is always available cause it can be scraped from a 404 page
render json: results
end
def statistics
return redirect_to path("/") unless SiteSetting.share_anonymized_statistics?
render json: About.fetch_cached_stats
end
end