[deploy] Add query-friendly article additions (Initial step) (#7794)
* Add query-friendly article additions * Fiddle with font size * Change from query_friendly_ to search_optimized_
This commit is contained in:
parent
371a71a3be
commit
a288acf88f
8 changed files with 83 additions and 2 deletions
|
|
@ -153,6 +153,17 @@ article {
|
|||
font-size: 57px;
|
||||
}
|
||||
|
||||
.article-title-preamble {
|
||||
display: block;
|
||||
color: var(--base-60);
|
||||
font-size: calc(16px + 0.2vw);
|
||||
margin-bottom: -1.25vw;
|
||||
@media screen and (min-width: 1600px) {
|
||||
font-size: 18px;
|
||||
margin-bottom: -18px;
|
||||
}
|
||||
}
|
||||
|
||||
.title-block {
|
||||
display: inline-block;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class ArticleDashboard < Administrate::BaseDashboard
|
|||
organization: Field::BelongsTo,
|
||||
id: Field::Number,
|
||||
title: Field::String,
|
||||
search_optimized_title_preamble: Field::String,
|
||||
search_optimized_description_replacement: Field::String,
|
||||
body_html: Field::Text,
|
||||
body_markdown: Field::Text,
|
||||
slug: Field::String,
|
||||
|
|
@ -67,6 +69,8 @@ class ArticleDashboard < Administrate::BaseDashboard
|
|||
third_user_id
|
||||
organization
|
||||
title
|
||||
search_optimized_title_preamble
|
||||
search_optimized_description_replacement
|
||||
body_markdown
|
||||
slug
|
||||
social_image
|
||||
|
|
|
|||
|
|
@ -53,7 +53,17 @@ class ArticleDecorator < ApplicationDecorator
|
|||
published_at.to_i
|
||||
end
|
||||
|
||||
def title_with_query_preamble(user_signed_in)
|
||||
if search_optimized_title_preamble.present? && !user_signed_in
|
||||
"#{search_optimized_title_preamble}: #{title}"
|
||||
else
|
||||
title
|
||||
end
|
||||
end
|
||||
|
||||
def description_and_tags
|
||||
return search_optimized_description_replacement if search_optimized_description_replacement.present?
|
||||
|
||||
modified_description = description.strip
|
||||
modified_description += "." unless description.end_with?(".")
|
||||
return modified_description if cached_tag_list.blank?
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% title @article.title %>
|
||||
<% title @article.title_with_query_preamble(user_signed_in?) %>
|
||||
|
||||
<%= render "shared/webcomponents_loader_script" %>
|
||||
<%= javascript_packs_with_chunks_tag "clipboardCopy", "webShare", "articlePage", defer: true %>
|
||||
|
|
@ -115,6 +115,9 @@
|
|||
</a>
|
||||
<% end %>
|
||||
<h1 class="<%= @article.title_length_classification %>">
|
||||
<% if @article.search_optimized_title_preamble.present? && !user_signed_in? %>
|
||||
<span class="article-title-preamble"><%= @article.search_optimized_title_preamble %></span>
|
||||
<% end %>
|
||||
<%= @article.title %>
|
||||
</h1>
|
||||
<h3>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class AddQueryFriendlyAdminFieldsToArticles < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :articles, :search_optimized_title_preamble, :string
|
||||
add_column :articles, :search_optimized_description_replacement, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_05_04_075409) do
|
||||
ActiveRecord::Schema.define(version: 2020_05_11_224704) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
@ -98,6 +98,8 @@ ActiveRecord::Schema.define(version: 2020_05_04_075409) do
|
|||
t.boolean "published", default: false
|
||||
t.datetime "published_at"
|
||||
t.boolean "published_from_feed", default: false
|
||||
t.string "search_optimized_description_replacement"
|
||||
t.string "search_optimized_title_preamble"
|
||||
t.integer "rating_votes_count", default: 0, null: false
|
||||
t.integer "reactions_count", default: 0, null: false
|
||||
t.integer "reading_time", default: 0
|
||||
|
|
|
|||
|
|
@ -174,5 +174,12 @@ RSpec.describe ArticleDecorator, type: :decorator do
|
|||
parsed_post_by_string += "." unless created_article.user.name.end_with?(".")
|
||||
expect(created_article.description_and_tags).to eq("#{parsed_post_by_string} Tagged with heytag.")
|
||||
end
|
||||
|
||||
it "returns search_optimized_description_replacement if it is present" do
|
||||
body_markdown = "---\ntitle: Title\npublished: false\ndescription:\ntags: heytag\n---\n\nHey this is the article"
|
||||
search_optimized_description_replacement = "Hey this is the expected result"
|
||||
expect(create_article(body_markdown: body_markdown, search_optimized_description_replacement: search_optimized_description_replacement).
|
||||
description_and_tags).to eq(search_optimized_description_replacement)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,6 +31,44 @@ RSpec.describe "StoriesShow", type: :request do
|
|||
expect(response.body).to include "<title>#{CGI.escapeHTML(article.title)} - #{community_name}</title>"
|
||||
end
|
||||
|
||||
# search_optimized_title_preamble
|
||||
|
||||
it "renders title tag with search_optimized_title_preamble if set and not signed in" do
|
||||
article.update_column(:search_optimized_title_preamble, "Hey this is a test")
|
||||
get article.reload.path
|
||||
expect(response.body).to include "<title>Hey this is a test: #{CGI.escapeHTML(article.title)} - #{community_name}</title>"
|
||||
end
|
||||
|
||||
it "does not render title tag with search_optimized_title_preamble if set and not signed in" do
|
||||
sign_in user
|
||||
article.update_column(:search_optimized_title_preamble, "Hey this is a test")
|
||||
get article.path
|
||||
expect(response.body).to include "<title>#{CGI.escapeHTML(article.title)} - #{community_qualified_name} 👩💻👨💻</title>"
|
||||
end
|
||||
|
||||
it "does not render preamble with search_optimized_title_preamble not signed in but search_optimized_title_preamble not set" do
|
||||
get article.path
|
||||
expect(response.body).to include "#{CGI.escapeHTML(article.title)} - #{community_name}</title>"
|
||||
end
|
||||
|
||||
it "renders title preamble with search_optimized_title_preamble if set and not signed in" do
|
||||
article.update_column(:search_optimized_title_preamble, "Hey this is a test")
|
||||
get article.reload.path
|
||||
expect(response.body).to include "<span class=\"article-title-preamble\">Hey this is a test</span>"
|
||||
end
|
||||
|
||||
it "does not render preamble with search_optimized_title_preamble if set and signed in" do
|
||||
sign_in user
|
||||
article.update_column(:search_optimized_title_preamble, "Hey this is a test")
|
||||
get article.path
|
||||
expect(response.body).not_to include "<span class=\"article-title-preamble\">Hey this is a test</span>"
|
||||
end
|
||||
|
||||
it "does not render title tag with search_optimized_title_preamble not signed in but search_optimized_title_preamble not set" do
|
||||
get article.path
|
||||
expect(response.body).not_to include "<span class=\"article-title-preamble\">Hey this is a test</span>"
|
||||
end
|
||||
|
||||
it "renders second and third users if present" do
|
||||
# 3rd user doesn't seem to get rendered for some reason
|
||||
user2 = create(:user)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue