Set default for post title truncation to 70 characters

closes #6022
This commit is contained in:
Steffen van Bergerem 2015-05-31 21:55:26 +02:00 committed by Jonne Haß
parent d2e0b3ceae
commit 1b77258d0e
8 changed files with 67 additions and 53 deletions

View file

@ -24,6 +24,7 @@
* Improve styling of horizontal ruler in posts [#6016](https://github.com/diaspora/diaspora/pull/6016) * Improve styling of horizontal ruler in posts [#6016](https://github.com/diaspora/diaspora/pull/6016)
* Increase post titles length to 50 and use configured pod name as title in the atom feed [#6020](https://github.com/diaspora/diaspora/pull/6020) * Increase post titles length to 50 and use configured pod name as title in the atom feed [#6020](https://github.com/diaspora/diaspora/pull/6020)
* Remove deprecated Facebook permissions [#6019](https://github.com/diaspora/diaspora/pull/6019) * Remove deprecated Facebook permissions [#6019](https://github.com/diaspora/diaspora/pull/6019)
* Make used post title lengths more consistent [#6022](https://github.com/diaspora/diaspora/pull/6022)
## Bug fixes ## Bug fixes
* Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846) * Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846)

View file

@ -8,13 +8,23 @@ module NotificationsHelper
if note.instance_of?(Notifications::Mentioned) if note.instance_of?(Notifications::Mentioned)
if post = note.linked_object if post = note.linked_object
translation(target_type, :actors => actors, :count => actors_count, :post_link => link_to(post_page_title(post), post_path(post)).html_safe) translation(target_type,
actors: actors,
count: actors_count,
post_link: link_to(post_page_title(post), post_path(post)).html_safe)
else else
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end end
elsif note.instance_of?(Notifications::CommentOnPost) || note.instance_of?(Notifications::AlsoCommented) || note.instance_of?(Notifications::Reshared) || note.instance_of?(Notifications::Liked) elsif note.instance_of?(Notifications::CommentOnPost) || note.instance_of?(Notifications::AlsoCommented) || note.instance_of?(Notifications::Reshared) || note.instance_of?(Notifications::Liked)
if post = note.linked_object if post = note.linked_object
translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author_name), :post_link => link_to(post_page_title(post), post_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe) translation(target_type,
actors: actors,
count: actors_count,
post_author: h(post.author_name),
post_link: link_to(post_page_title(post),
post_path(post),
data: {ref: post.id},
class: "hard_object_link").html_safe)
else else
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end end

View file

@ -1,30 +1,31 @@
class Services::Wordpress < Service module Services
MAX_CHARACTERS = 1000 class Wordpress < Service
MAX_CHARACTERS = 1000
attr_accessor :username, :password, :host, :path attr_accessor :username, :password, :host, :path
# uid = blog_id # uid = blog_id
def provider def provider
"wordpress" "wordpress"
end
def post post, url=''
res = Faraday.new(url: "https://public-api.wordpress.com").post do |req|
req.url "/rest/v1/sites/#{self.uid}/posts/new"
req.body = post_body(post).to_json
req.headers['Authorization'] = "Bearer #{self.access_token}"
req.headers['Content-Type'] = 'application/json'
end end
JSON.parse res.env[:body] def post(post, _url="")
end res = Faraday.new(url: "https://public-api.wordpress.com").post do |req|
req.url "/rest/v1/sites/#{uid}/posts/new"
req.body = post_body(post).to_json
req.headers["Authorization"] = "Bearer #{access_token}"
req.headers["Content-Type"] = "application/json"
end
def post_body post JSON.parse res.env[:body]
{ end
title: post.message.title(length: 40),
content: post.message.markdownified(disable_hovercards: true)
}
end
def post_body(post)
{
title: post.message.title,
content: post.message.markdownified(disable_hovercards: true)
}
end
end
end end

View file

@ -128,7 +128,7 @@ class StatusMessage < Post
end end
def comment_email_subject def comment_email_subject
message.title length: 70 message.title
end end
def first_photo_url(*args) def first_photo_url(*args)

View file

@ -30,7 +30,7 @@ atom_feed({'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
feed.entry post, :url => "#{@user.url}p/#{post.id}", feed.entry post, :url => "#{@user.url}p/#{post.id}",
:id => "#{@user.url}p/#{post.id}" do |entry| :id => "#{@user.url}p/#{post.id}" do |entry|
entry.title post.message.title(length: 50) entry.title post.message.title
entry.content post.message.markdownified(disable_hovercards: true), :type => 'html' entry.content post.message.markdownified(disable_hovercards: true), :type => 'html'
entry.tag! 'activity:verb', 'http://activitystrea.ms/schema/1.0/post' entry.tag! 'activity:verb', 'http://activitystrea.ms/schema/1.0/post'
entry.tag! 'activity:object-type', 'http://activitystrea.ms/schema/1.0/note' entry.tag! 'activity:object-type', 'http://activitystrea.ms/schema/1.0/note'

View file

@ -213,9 +213,8 @@ module Diaspora
# Get a short summary of the message # Get a short summary of the message
# @param [Hash] opts Additional options # @param [Hash] opts Additional options
# @option opts [Integer] :length (20 | first heading) Truncate the title to # @option opts [Integer] :length (70) Truncate the title to
# this length. If not given defaults to 20 and to not truncate # this length. If not given defaults to 70.
# if a heading is found.
def title opts={} def title opts={}
# Setext-style header # Setext-style header
heading = if /\A(?<setext_content>.{1,200})\n(?:={1,200}|-{1,200})(?:\r?\n|$)/ =~ @raw_message.lstrip heading = if /\A(?<setext_content>.{1,200})\n(?:={1,200}|-{1,200})(?:\r?\n|$)/ =~ @raw_message.lstrip
@ -227,12 +226,10 @@ module Diaspora
heading &&= self.class.new(heading).plain_text_without_markdown heading &&= self.class.new(heading).plain_text_without_markdown
if heading && opts[:length] if heading
heading.truncate opts[:length] heading.truncate opts.fetch(:length, 70)
elsif heading
heading
else else
plain_text_without_markdown squish: true, truncate: opts.fetch(:length, 20) plain_text_without_markdown squish: true, truncate: opts.fetch(:length, 70)
end end
end end

View file

@ -30,9 +30,10 @@ describe Diaspora::MessageRenderer do
end end
end end
context 'without a Markdown header of less than 200 characters on first line ' do context "without a Markdown header of less than 200 characters on first line" do
it 'truncates posts to the 20 first characters' do it "truncates posts to the 70 first characters" do
expect(message("Very, very, very long post").title).to eq "Very, very, very ..." text = "Chillwave heirloom small batch semiotics, brunch cliche yr gluten-free whatever bitters selfies."
expect(message(text).title).to eq "Chillwave heirloom small batch semiotics, brunch cliche yr gluten-f..."
end end
end end
end end

View file

@ -1,33 +1,37 @@
require 'spec_helper' require "spec_helper"
describe Services::Wordpress, :type => :model do
describe Services::Wordpress, type: :model do
before do before do
@user = alice @user = alice
@post = @user.post(:status_message, @post = @user.post(:status_message,
:text => "Hello there. This is a **Wordpress** post that we hope to turn into something else.", text: "Hello there. This is a **Wordpress** post that we hope to turn into something else.",
:to => @user.aspects.first.id) to: @user.aspects.first.id)
@service = Services::Wordpress.new(:nickname => "andrew", @service = Services::Wordpress.new(nickname: "andrew",
:access_token => "abc123", access_token: "abc123",
:uid => "123") uid: "123")
@user.services << @service @user.services << @service
end end
describe "#post" do describe "#post" do
it 'posts a status message to wordpress' do it "posts a status message to wordpress" do
stub_request(:post, "https://public-api.wordpress.com/rest/v1/sites/123/posts/new").to_return(:status => 200, :body => {:ID => 68}.to_json, :headers => {}) stub_request(:post, "https://public-api.wordpress.com/rest/v1/sites/123/posts/new").to_return(
status: 200,
body: {ID: 68}.to_json,
headers: {}
)
@service.post(@post) @service.post(@post)
end end
end end
describe "#post_body" do describe "#post_body" do
it "truncates content for use in title" do it "truncates content for use in title" do
expect(@service.post_body(@post)[:title]).to eq("Hello there. This is a Wordpress post...") expect(@service.post_body(@post)[:title]).to eq(
"Hello there. This is a Wordpress post that we hope to turn into som..."
)
end end
it "converts markdown tags" do it "converts markdown tags" do
expect(@service.post_body(@post)[:content]).to match("<strong>Wordpress</strong>") expect(@service.post_body(@post)[:content]).to match("<strong>Wordpress</strong>")
end end
end end
end end