Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Milan
diaspora
Commits
1b77258d
Commit
1b77258d
authored
May 31, 2015
by
Steffen van Bergerem
Committed by
Jonne Haß
Jun 02, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set default for post title truncation to 70 characters
closes #6022
parent
d2e0b3ce
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
53 deletions
+67
-53
Changelog.md
Changelog.md
+1
-0
app/helpers/notifications_helper.rb
app/helpers/notifications_helper.rb
+12
-2
app/models/services/wordpress.rb
app/models/services/wordpress.rb
+23
-22
app/models/status_message.rb
app/models/status_message.rb
+1
-1
app/views/users/public.atom.builder
app/views/users/public.atom.builder
+1
-1
lib/diaspora/message_renderer.rb
lib/diaspora/message_renderer.rb
+5
-8
spec/lib/diaspora/message_renderer_spec.rb
spec/lib/diaspora/message_renderer_spec.rb
+4
-3
spec/models/services/wordpress_spec.rb
spec/models/services/wordpress_spec.rb
+20
-16
No files found.
Changelog.md
View file @
1b77258d
...
...
@@ -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
)
...
...
app/helpers/notifications_helper.rb
View file @
1b77258d
...
...
@@ -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
...
...
app/models/services/wordpress.rb
View file @
1b77258d
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
app/models/status_message.rb
View file @
1b77258d
...
...
@@ -128,7 +128,7 @@ class StatusMessage < Post
end
def
comment_email_subject
message
.
title
length:
70
message
.
title
end
def
first_photo_url
(
*
args
)
...
...
app/views/users/public.atom.builder
View file @
1b77258d
...
...
@@ -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'
...
...
lib/diaspora/message_renderer.rb
View file @
1b77258d
...
...
@@ -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
,
2
0
)
plain_text_without_markdown
squish:
true
,
truncate:
opts
.
fetch
(
:length
,
7
0
)
end
end
...
...
spec/lib/diaspora/message_renderer_spec.rb
View file @
1b77258d
...
...
@@ -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
...
...
spec/models/services/wordpress_spec.rb
View file @
1b77258d
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment