Skip to content

Commit c22059b

Browse files
committed
Include the Mastodon URL in a link element on user page (#2046)
We add a `<link rel="me" href="https://mastodon.example/@me">` URL in the `<head>` when the user configures their Mastodon URL. We only accept URLs (not `@[email protected]`-style identifiers) for the sake of simplicity, because it's both the most universal format and the one required for the "verification" feature. A placeholder is used to convey that fact. For the record, at this time Mastodon requires a `<a>` or `<link>` element with `rel="me"` and an `href` attribute pointing to the `https://` URL of the Mastodon account. I opted for the `<link>` element because it didn't involve modifying the web interface any further. See https://docs.joinmastodon.org/user/profile/#verification for details. https://linuxfr.org/suivi/faire-valider-sa-page-perso-linuxfr-org-sur-mastodon
1 parent 14f9a30 commit c22059b

File tree

8 files changed

+26
-2
lines changed

8 files changed

+26
-2
lines changed

app/controllers/application_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def seo_filter
3737
@keywords = %w(Linux Logiciel Libre GNU Free Software Actualité Forum Communauté)
3838
@description = "L’actualité du logiciel libre et des sujets voisins (DIY, Open Hardware, Open Data, les Communs, etc.), sur un site francophone contributif géré par une équipe bénévole par et pour des libristes enthousiastes"
3939
@feeds = {}
40+
@links = {}
4041
@last_comments = Comment.footer
4142
@popular_tags = Tag.footer
4243
@friend_sites = FriendSite.select([:url, :title])
@@ -56,7 +57,7 @@ def configure_permitted_parameters
5657
:sort_by_date_on_home, :hide_signature, :show_negative_nodes,
5758
:totoz_style, :totoz_source,
5859
:board_in_sidebar,
59-
user_attributes: [:id, :name, :homesite, :jabber_id, :signature, :avatar, :custom_avatar_url]
60+
user_attributes: [:id, :name, :homesite, :jabber_id, :mastodon_url, :signature, :avatar, :custom_avatar_url]
6061
])
6162
end
6263

app/helpers/application_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def feed(title, link=nil)
1616
@feeds[link] = title
1717
end
1818

19+
def link(rel, link)
20+
@links[link] = rel
21+
end
22+
1923
def meta_for(content)
2024
@author = content.node.user.try(:name)
2125
@keywords = content.node.popular_tags.map &:name

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# name :string(40)
88
# homesite :string(100)
99
# jabber_id :string(32)
10+
# mastodon_url :string(100)
1011
# cached_slug :string(32) not null
1112
# created_at :datetime
1213
# updated_at :datetime
@@ -33,6 +34,8 @@ class User < ActiveRecord::Base
3334
validates :homesite, length: { maximum: 100, message: "L’adresse du site Web personnel est trop longue" }
3435
validates :name, length: { maximum: 40, message: "Le nom affiché est trop long" }
3536
validates :jabber_id, length: { maximum: 32, message: "L’adresse XMPP est trop longue" }
37+
validates_format_of :mastodon_url, message: "L’adresse du comte Mastodon n’est pas une URL valide", with: URI::regexp(%w(http https)), allow_blank: true
38+
validates :mastodon_url, length: { maximum: 255, message: "L’adresse du compte Mastodon est trop longue" }
3639
validates :signature, length: { maximum: 255, message: "La signature est trop longue" }
3740
validates :custom_avatar_url, length: { maximum: 255, message: "L’adresse de l’avatar est trop longue" }
3841

app/views/devise/registrations/_preferences.html.haml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
= u.label :jabber_id, 'Adresse XMPP'
1212
%span.prefix xmpp:
1313
= u.text_field :jabber_id, placeholder: "[email protected]", maxlength: 32
14+
%p
15+
= u.label :mastodon_url, 'Adresse du compte Mastodon'
16+
= u.text_field :mastodon_url, placeholder: "https://mastodon.example/@me", maxlength: 255
17+
%span.help
18+
Après avoir enregistré l'adresse de votre compte Mastodon, vous pourrez utiliser le lien <kbd>https://linuxfr.org/users/#{current_user.login}</kbd> pour
19+
<a href="https://docs.joinmastodon.org/user/profile/#verification">prouver que le compte Mastodon et le compte LinuxFr.org appartiennent à la même personne.</a>
1420
%p
1521
= u.label :signature, "Signature"
1622
= u.text_field :signature, maxlength: 250, size: 100

app/views/layouts/_head.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
%meta(name="robots" content="noindex, nofollow")
1919
- @feeds.each do |link,title|
2020
= auto_discovery_link_tag :atom, link, { title: title }
21+
- @links.each do |link,rel|
22+
%link(rel=rel href=link)

app/views/users/show.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
=h1 "#{@user.name} a écrit #{pluralize @nodes.total_count, "contenu"} de type dépêche ou journal"
66
- feed "Flux Atom de #{@user.name}", "/users/#{@user.to_param}.atom"
7+
- if @user.mastodon_url
8+
- link "me", @user.mastodon_url
79
- filter_pagination_params ['id', 'order', 'page']
810
= paginated_nodes @nodes
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddMastodonUrlToUsers < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :users, :mastodon_url, :string
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2021_01_31_231806) do
13+
ActiveRecord::Schema.define(version: 2022_12_19_214058) do
1414

1515
create_table "accounts", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
1616
t.integer "user_id"
@@ -373,6 +373,7 @@
373373
t.string "avatar"
374374
t.string "signature"
375375
t.string "custom_avatar_url"
376+
t.string "mastodon_url"
376377
t.index ["cached_slug"], name: "index_users_on_cached_slug"
377378
end
378379

0 commit comments

Comments
 (0)