Skip to content
Extraits de code Groupes Projets
Valider 1b77258d rédigé par Steffen van Bergerem's avatar Steffen van Bergerem Validation de Jonne Haß
Parcourir les fichiers

Set default for post title truncation to 70 characters

closes #6022
parent d2e0b3ce
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -24,6 +24,7 @@
* 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)
* 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
* Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846)
......
......@@ -8,13 +8,23 @@ module NotificationsHelper
if note.instance_of?(Notifications::Mentioned)
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
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end
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
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
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end
......
class Services::Wordpress < Service
MAX_CHARACTERS = 1000
module Services
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
"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'
def provider
"wordpress"
end
JSON.parse res.env[:body]
end
def post(post, _url="")
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
{
title: post.message.title(length: 40),
content: post.message.markdownified(disable_hovercards: true)
}
end
JSON.parse res.env[:body]
end
def post_body(post)
{
title: post.message.title,
content: post.message.markdownified(disable_hovercards: true)
}
end
end
end
......@@ -128,7 +128,7 @@ class StatusMessage < Post
end
def comment_email_subject
message.title length: 70
message.title
end
def first_photo_url(*args)
......
......@@ -30,7 +30,7 @@ atom_feed({'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
feed.entry post, :url => "#{@user.url}p/#{post.id}",
: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.tag! 'activity:verb', 'http://activitystrea.ms/schema/1.0/post'
entry.tag! 'activity:object-type', 'http://activitystrea.ms/schema/1.0/note'
......
......@@ -213,9 +213,8 @@ module Diaspora
# Get a short summary of the message
# @param [Hash] opts Additional options
# @option opts [Integer] :length (20 | first heading) Truncate the title to
# this length. If not given defaults to 20 and to not truncate
# if a heading is found.
# @option opts [Integer] :length (70) Truncate the title to
# this length. If not given defaults to 70.
def title opts={}
# Setext-style header
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
if heading && opts[:length]
heading.truncate opts[:length]
elsif heading
heading
if heading
heading.truncate opts.fetch(:length, 70)
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
......
......@@ -30,9 +30,10 @@ describe Diaspora::MessageRenderer do
end
end
context 'without a Markdown header of less than 200 characters on first line ' do
it 'truncates posts to the 20 first characters' do
expect(message("Very, very, very long post").title).to eq "Very, very, very ..."
context "without a Markdown header of less than 200 characters on first line" do
it "truncates posts to the 70 first characters" do
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
......
require 'spec_helper'
require "spec_helper"
describe Services::Wordpress, :type => :model do
describe Services::Wordpress, type: :model do
before do
@user = alice
@post = @user.post(:status_message,
:text => "Hello there. This is a **Wordpress** post that we hope to turn into something else.",
:to => @user.aspects.first.id)
@service = Services::Wordpress.new(:nickname => "andrew",
:access_token => "abc123",
:uid => "123")
@post = @user.post(:status_message,
text: "Hello there. This is a **Wordpress** post that we hope to turn into something else.",
to: @user.aspects.first.id)
@service = Services::Wordpress.new(nickname: "andrew",
access_token: "abc123",
uid: "123")
@user.services << @service
end
describe "#post" 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 => {})
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: {}
)
@service.post(@post)
end
end
describe "#post_body" 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
it "converts markdown tags" do
expect(@service.post_body(@post)[:content]).to match("<strong>Wordpress</strong>")
end
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter