FEATURE: allows to to style published page with themes/plugins (#9570)

This commit is contained in:
Joffrey JAFFEUX 2020-04-28 18:24:24 +02:00 committed by GitHub
parent b19dcac272
commit a6f986b50f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 30 deletions

View File

@ -87,7 +87,7 @@
{{/topic-title}} {{/topic-title}}
{{#if model.publishedPage}} {{#if model.publishedPage}}
<div class="published-page"> <div class="published-page-notice">
<div class="details"> <div class="details">
{{i18n "topic.publish_page.topic_published"}} {{i18n "topic.publish_page.topic_published"}}
<div> <div>

View File

@ -296,7 +296,7 @@ a.topic-featured-link {
} }
} }
.published-page { .published-page-notice {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding-bottom: 1em; padding-bottom: 1em;

View File

@ -1,32 +1,32 @@
@import "common"; @import "common";
body { .published-page-wrapper {
margin: 2em auto;
max-width: 800px;
}
.published-page {
background-color: $secondary; background-color: $secondary;
color: $primary; color: $primary;
} }
.published-page { .published-page-title {
margin: 2em auto; color: $header_primary;
max-width: 800px; }
h1 { .published-page-author {
color: $header_primary; margin-top: 1em;
margin-bottom: 2em;
display: flex;
.avatar {
margin-right: 1em;
} }
.topic-created-at {
.published-page-author { color: $primary-medium;
margin-top: 1em;
margin-bottom: 2em;
display: flex;
.avatar {
margin-right: 1em;
}
.topic-created-at {
color: $primary-medium;
}
}
.published-page-body {
font-size: 1.25em;
} }
} }
.published-page-body {
font-size: 1.25em;
}

View File

@ -15,6 +15,18 @@ class PublishedPagesController < ApplicationController
guardian.ensure_can_see!(pp.topic) guardian.ensure_can_see!(pp.topic)
@topic = pp.topic @topic = pp.topic
@canonical_url = @topic.url @canonical_url = @topic.url
@body_classes = Set.new([
'published-page',
params[:slug],
"topic-#{@topic.id}",
@topic.tags.pluck(:name)
].flatten.compact)
if @topic.category
@body_classes << @topic.category.slug
end
render layout: 'publish' render layout: 'publish'
end end

View File

@ -0,0 +1,9 @@
<%= discourse_stylesheet_link_tag 'publish', theme_ids: nil %>
<%- Discourse.find_plugin_css_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, mobile_view: mobile_view?, desktop_view: !mobile_view?, request: request).each do |file| %>
<%= discourse_stylesheet_link_tag(file) %>
<%- end %>
<%- if theme_ids.present? %>
<%= discourse_stylesheet_link_tag(mobile_view? ? :mobile_theme : :desktop_theme) %>
<%- end %>

View File

@ -3,13 +3,14 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover">
<%= discourse_stylesheet_link_tag 'publish', theme_ids: nil %>
<%= render partial: "common/discourse_publish_stylesheet" %>
<%- if @canonical_url -%> <%- if @canonical_url -%>
<link rel="canonical" href="<%= @canonical_url %>" /> <link rel="canonical" href="<%= @canonical_url %>" />
<%- end -%> <%- end -%>
</head> </head>
<body> <body class="<%= @body_classes.to_a.join(' ') %>">
<%= yield %> <%= yield %>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
<div class="published-page"> <div class="published-page-wrapper">
<div class="published-page-header"> <div class="published-page-header">
<h1 class="published-page-title"><%= @topic.title %></h1> <h1 class="published-page-title"><%= @topic.title %></h1>

View File

@ -76,9 +76,21 @@ RSpec.describe PublishedPagesController do
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
it "returns 200 for a valid article" do context "the article is valid" do
get published_page.path before do
expect(response.status).to eq(200) SiteSetting.tagging_enabled = true
published_page.topic.tags = [Fabricate(:tag, name: "recipes")]
end
it "returns 200" do
get published_page.path
expect(response.status).to eq(200)
end
it "defines correct css classes on body" do
get published_page.path
expect(response.body).to include("<body class=\"published-page published-page-test topic-#{published_page.topic_id} recipes uncategorized\">")
end
end end
end end