0
0
Fork 0

Add bio fields (#6645)

* Add bio fields

- Fix #3211
- Fix #232
- Fix #121

* Display bio fields in web UI

* Fix output of links and missing fields

* Federate bio fields over ActivityPub as PropertyValue

* Improve how the fields are stored, add to Edit profile form

* Add rel=me to links in fields

Fix #121
This commit is contained in:
Eugen Rochko 2018-04-14 12:41:08 +02:00 committed by GitHub
parent 85ab30abf7
commit 78ed4ab75f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 274 additions and 7 deletions

View file

@ -19,6 +19,9 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
'Emoji' => 'toot:Emoji',
'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' },
'featured' => 'toot:featured',
'schema' => 'http://schema.org#',
'PropertyValue' => 'schema:PropertyValue',
'value' => 'schema:value',
},
],
}.freeze

View file

@ -71,6 +71,11 @@ class Formatter
html.html_safe # rubocop:disable Rails/OutputSafety
end
def format_field(account, str)
return reformat(str).html_safe unless account.local? # rubocop:disable Rails/OutputSafety
encode_and_link_urls(str, me: true).html_safe # rubocop:disable Rails/OutputSafety
end
def linkify(text)
html = encode_and_link_urls(text)
html = simple_format(html, {}, sanitize: false)
@ -85,12 +90,17 @@ class Formatter
HTMLEntities.new.encode(html)
end
def encode_and_link_urls(html, accounts = nil)
def encode_and_link_urls(html, accounts = nil, options = {})
entities = Extractor.extract_entities_with_indices(html, extract_url_without_protocol: false)
if accounts.is_a?(Hash)
options = accounts
accounts = nil
end
rewrite(html.dup, entities) do |entity|
if entity[:url]
link_to_url(entity)
link_to_url(entity, options)
elsif entity[:hashtag]
link_to_hashtag(entity)
elsif entity[:screen_name]
@ -177,10 +187,12 @@ class Formatter
result.flatten.join
end
def link_to_url(entity)
def link_to_url(entity, options = {})
url = Addressable::URI.parse(entity[:url])
html_attrs = { target: '_blank', rel: 'nofollow noopener' }
html_attrs[:rel] = "me #{html_attrs[:rel]}" if options[:me]
Twitter::Autolink.send(:link_to_text, entity, link_html(entity[:url]), url, html_attrs)
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
encode(entity[:url])