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}}
{{#if model.publishedPage}}
<div class="published-page">
<div class="published-page-notice">
<div class="details">
{{i18n "topic.publish_page.topic_published"}}
<div>

View File

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

View File

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

View File

@ -15,6 +15,18 @@ class PublishedPagesController < ApplicationController
guardian.ensure_can_see!(pp.topic)
@topic = pp.topic
@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'
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>
<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">
<%= discourse_stylesheet_link_tag 'publish', theme_ids: nil %>
<%= render partial: "common/discourse_publish_stylesheet" %>
<%- if @canonical_url -%>
<link rel="canonical" href="<%= @canonical_url %>" />
<%- end -%>
</head>
<body>
<body class="<%= @body_classes.to_a.join(' ') %>">
<%= yield %>
</body>
</html>

View File

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

View File

@ -76,9 +76,21 @@ RSpec.describe PublishedPagesController do
expect(response.status).to eq(404)
end
it "returns 200 for a valid article" do
get published_page.path
expect(response.status).to eq(200)
context "the article is valid" do
before do
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