mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
FIX: Offer site_logo_dark_url as an option for dark mode themes (#14361)
This commit is contained in:
parent
ae09b46098
commit
da88cad648
|
@ -341,6 +341,18 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def application_logo_dark_url
|
||||||
|
@application_logo_dark_url ||= begin
|
||||||
|
if dark_scheme_id != -1
|
||||||
|
if mobile_view? && SiteSetting.site_mobile_logo_dark_url != application_logo_url
|
||||||
|
SiteSetting.site_mobile_logo_dark_url
|
||||||
|
elsif !mobile_view? && SiteSetting.site_logo_dark_url != application_logo_url
|
||||||
|
SiteSetting.site_logo_dark_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def login_path
|
def login_path
|
||||||
"#{Discourse.base_path}/login"
|
"#{Discourse.base_path}/login"
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,12 @@
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<a href="<%= path "/" %>">
|
<a href="<%= path "/" %>">
|
||||||
<%- if application_logo_url.present? %>
|
<%- if application_logo_url.present? %>
|
||||||
<img src="<%= application_logo_url %>" alt="<%= SiteSetting.title %>" id="site-logo">
|
<picture>
|
||||||
|
<%- if application_logo_dark_url.present? %>
|
||||||
|
<source srcset="<%= application_logo_dark_url %>" media="(prefers-color-scheme: dark)" />
|
||||||
|
<%- end %>
|
||||||
|
<img src="<%= application_logo_url %>" alt="<%= SiteSetting.title %>" id="site-logo" />
|
||||||
|
</picture>
|
||||||
<%- else %>
|
<%- else %>
|
||||||
<h2 id='site-text-logo'><%= SiteSetting.title %></h2>
|
<h2 id='site-text-logo'><%= SiteSetting.title %></h2>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
|
@ -136,6 +136,59 @@ describe ApplicationHelper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "application_logo_dark_url" do
|
||||||
|
context "when dark theme is not present" do
|
||||||
|
context "when dark logo is not present" do
|
||||||
|
it "should return nothing" do
|
||||||
|
expect(helper.application_logo_dark_url.present?).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when dark theme is present" do
|
||||||
|
before do
|
||||||
|
dark_theme = Theme.create(
|
||||||
|
name: "Dark",
|
||||||
|
user_id: -1,
|
||||||
|
color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when dark logo is not present" do
|
||||||
|
it "should return nothing" do
|
||||||
|
expect(helper.application_logo_dark_url.present?).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when dark logo is present" do
|
||||||
|
before do
|
||||||
|
SiteSetting.logo_dark = Fabricate(:upload, url: '/images/logo-dark.png')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return correct url" do
|
||||||
|
expect(helper.application_logo_dark_url).to eq(SiteSetting.site_logo_dark_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when dark theme is present and selected" do
|
||||||
|
before do
|
||||||
|
dark_theme = Theme.create(
|
||||||
|
name: "Dark",
|
||||||
|
user_id: -1,
|
||||||
|
color_scheme_id: ColorScheme.find_by(base_scheme_id: "Dark").id
|
||||||
|
)
|
||||||
|
helper.request.env[:resolved_theme_id] = dark_theme.id
|
||||||
|
SiteSetting.logo_dark = Fabricate(:upload, url: '/images/logo-dark.png')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return nothing" do
|
||||||
|
expect(helper.application_logo_url).to eq(SiteSetting.site_logo_dark_url)
|
||||||
|
expect(helper.application_logo_dark_url.present?).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "mobile_view?" do
|
describe "mobile_view?" do
|
||||||
context "enable_mobile_theme is true" do
|
context "enable_mobile_theme is true" do
|
||||||
before do
|
before do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user