discourse/app/controllers/metadata_controller.rb

64 lines
1.7 KiB
Ruby
Raw Normal View History

2019-05-02 02:57:12 -04:00
# frozen_string_literal: true
class MetadataController < ApplicationController
layout false
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
def manifest
render json: default_manifest.to_json, content_type: 'application/manifest+json'
end
def opensearch
render file: "#{Rails.root}/app/views/metadata/opensearch.xml"
end
private
def default_manifest
display = Regexp.new(SiteSetting.pwa_display_browser_regex).match(request.user_agent) ? 'browser' : 'standalone'
manifest = {
name: SiteSetting.title,
display: display,
start_url: Discourse.base_uri.present? ? "#{Discourse.base_uri}/" : '.',
background_color: "##{ColorScheme.hex_for_name('secondary', view_context.scheme_id)}",
theme_color: "##{ColorScheme.hex_for_name('header_background', view_context.scheme_id)}",
icons: [
],
share_target: {
action: "/new-topic",
method: "GET",
enctype: "application/x-www-form-urlencoded",
params: {
title: "title",
text: "body"
}
}
}
FEATURE: Automatically generate optimized site metadata icons (#7372) This change automatically resizes icons for various purposes. Admins can now upload `logo` and `logo_small`, and everything else will be auto-generated. Specific icons can still be uploaded separately if required. ## Core - Adds an SiteIconManager module which manages automatic resizing and fallback - Icons are looked up in the OptimizedImage table at runtime, and then cached in Redis. If the resized version is missing for some reason, then most icons will fall back to the original files. Some icons (e.g. PWA Manifest) will return `nil` (because an incorrectly sized icon is worse than a missing icon). - `SiteSetting.site_large_icon_url` will return the optimized version, including any fallback. `SiteSetting.large_icon` continues to return the upload object. This means that (almost) no changes are required in core/plugins to support this new system. - Icons are resized whenever a relevant site setting is changed, and during post-deploy migrations ## Wizard - Allows `requiresRefresh` wizard steps to reload data via AJAX instead of a full page reload - Add placeholders to the **icons** step of the wizard, which automatically update from the "Square Logo" - Various copy updates to support the changes - Remove the "upload-time" resizing for `large_icon`. This is no longer required. ## Site Settings UX - Move logo/icon settings under a new "Branding" tab - Various copy changes to support the changes - Adds placeholder support to the `image-uploader` component - Automatically reloads site settings after saving. This allows setting placeholders to change based on changes to other settings - Upload site settings will be assigned a placeholder if SiteIconManager `responds_to?` an icon of the same name ## Dashboard Warnings - Remove PWA icon and PWA title warnings. Both are now handled automatically. ## Bonus - Updated the sketch logos to use @awesomerobot's new high-res designs
2019-05-01 09:44:45 -04:00
logo = SiteSetting.site_manifest_icon_url
manifest[:icons] << {
src: UrlHelper.absolute(logo),
sizes: "512x512",
type: MiniMime.lookup_by_filename(logo)&.content_type || "image/png"
} if logo
manifest[:short_name] = SiteSetting.short_title if SiteSetting.short_title.present?
if current_user && current_user.trust_level >= 1 && SiteSetting.native_app_install_banner_android
2017-07-27 21:20:09 -04:00
manifest = manifest.merge(
prefer_related_applications: true,
related_applications: [
{
platform: "play",
id: SiteSetting.android_app_id
}
]
2017-07-27 21:20:09 -04:00
)
end
manifest
end
end