mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
FIX: Add helpers for title and content for application.html.erb
and crawler.html.erb
(#32290)
Previously, there was only those helpers in `crawler.html.erb` as we added it in https://github.com/discourse/discourse/pull/32259 However, to keep it consistent, we need to add it in `application.html.erb` as well.
This commit is contained in:
@ -270,7 +270,7 @@ module ApplicationHelper
|
|||||||
(request ? I18n.locale.to_s : SiteSetting.default_locale).sub("_", "-")
|
(request ? I18n.locale.to_s : SiteSetting.default_locale).sub("_", "-")
|
||||||
end
|
end
|
||||||
|
|
||||||
def crawlable_title_content
|
def title_content
|
||||||
DiscoursePluginRegistry.apply_modifier(
|
DiscoursePluginRegistry.apply_modifier(
|
||||||
:meta_data_content,
|
:meta_data_content,
|
||||||
content_for(:title) || SiteSetting.title,
|
content_for(:title) || SiteSetting.title,
|
||||||
@ -279,7 +279,7 @@ module ApplicationHelper
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def crawlable_description_content
|
def description_content
|
||||||
DiscoursePluginRegistry.apply_modifier(
|
DiscoursePluginRegistry.apply_modifier(
|
||||||
:meta_data_content,
|
:meta_data_content,
|
||||||
@description_meta || SiteSetting.site_description,
|
@description_meta || SiteSetting.site_description,
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<html lang="<%= html_lang %>" class="<%= html_classes %>">
|
<html lang="<%= html_lang %>" class="<%= html_classes %>">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title><%= content_for?(:title) ? yield(:title) : SiteSetting.title %></title>
|
<title><%= title_content %></title>
|
||||||
<meta name="description" content="<%= @description_meta || SiteSetting.site_description %>">
|
<meta name="description" content="<%= description_content %>">
|
||||||
<meta name="discourse_theme_id" content="<%= theme_id %>">
|
<meta name="discourse_theme_id" content="<%= theme_id %>">
|
||||||
<meta name="discourse_current_homepage" content="<%= current_homepage %>">
|
<meta name="discourse_current_homepage" content="<%= current_homepage %>">
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<html lang="<%= html_lang %>">
|
<html lang="<%= html_lang %>">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title><%= crawlable_title_content %></title>
|
<title><%= title_content %></title>
|
||||||
<meta name="description" content="<%= crawlable_description_content %>">
|
<meta name="description" content="<%= description_content %>">
|
||||||
<%= render partial: "layouts/head" %>
|
<%= render partial: "layouts/head" %>
|
||||||
<%= render partial: "common/discourse_stylesheet" %>
|
<%= render partial: "common/discourse_stylesheet" %>
|
||||||
<%= theme_lookup("head_tag") %>
|
<%= theme_lookup("head_tag") %>
|
||||||
|
@ -745,10 +745,10 @@ RSpec.describe ApplicationHelper do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#crawlable_title_content" do
|
describe "#title_content" do
|
||||||
it "returns the correct title" do
|
it "returns the correct title" do
|
||||||
SiteSetting.title = "Test Title"
|
SiteSetting.title = "Test Title"
|
||||||
result = helper.crawlable_title_content
|
result = helper.title_content
|
||||||
|
|
||||||
expect(result).to include("Test Title")
|
expect(result).to include("Test Title")
|
||||||
end
|
end
|
||||||
@ -757,16 +757,16 @@ RSpec.describe ApplicationHelper do
|
|||||||
helper.stubs(:content_for?).with(:title).returns(true)
|
helper.stubs(:content_for?).with(:title).returns(true)
|
||||||
helper.stubs(:content_for).with(:title).returns("Custom Title")
|
helper.stubs(:content_for).with(:title).returns("Custom Title")
|
||||||
|
|
||||||
result = helper.crawlable_title_content
|
result = helper.title_content
|
||||||
|
|
||||||
expect(result).to include("Custom Title")
|
expect(result).to include("Custom Title")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#crawlable_description_content" do
|
describe "#description_content" do
|
||||||
it "returns the correct description" do
|
it "returns the correct description" do
|
||||||
SiteSetting.site_description = "Test Description"
|
SiteSetting.site_description = "Test Description"
|
||||||
result = helper.crawlable_description_content
|
result = helper.description_content
|
||||||
|
|
||||||
expect(result).to include("Test Description")
|
expect(result).to include("Test Description")
|
||||||
end
|
end
|
||||||
@ -774,7 +774,7 @@ RSpec.describe ApplicationHelper do
|
|||||||
it "accepts a content argument" do
|
it "accepts a content argument" do
|
||||||
@description_meta = "Custom Description"
|
@description_meta = "Custom Description"
|
||||||
|
|
||||||
result = helper.crawlable_description_content
|
result = helper.description_content
|
||||||
|
|
||||||
expect(result).to include("Custom Description")
|
expect(result).to include("Custom Description")
|
||||||
end
|
end
|
||||||
@ -810,7 +810,7 @@ RSpec.describe ApplicationHelper do
|
|||||||
it "modifies the title tag" do
|
it "modifies the title tag" do
|
||||||
plugin.register_modifier(:meta_data_content, &block)
|
plugin.register_modifier(:meta_data_content, &block)
|
||||||
|
|
||||||
title = helper.crawlable_title_content
|
title = helper.title_content
|
||||||
|
|
||||||
expect(title).to include("BIG TITLE")
|
expect(title).to include("BIG TITLE")
|
||||||
end
|
end
|
||||||
@ -818,7 +818,7 @@ RSpec.describe ApplicationHelper do
|
|||||||
it "modifies the description tag" do
|
it "modifies the description tag" do
|
||||||
plugin.register_modifier(:meta_data_content, &block)
|
plugin.register_modifier(:meta_data_content, &block)
|
||||||
|
|
||||||
description = helper.crawlable_description_content
|
description = helper.description_content
|
||||||
|
|
||||||
expect(description).to include(" - modified by plugin")
|
expect(description).to include(" - modified by plugin")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user