Mercurial > rsstweet
annotate app/helpers/application_helper.rb @ 229:12287b32fbda
Show link to parent tweet for replies
author | nanaya <me@nanaya.pro> |
---|---|
date | Wed, 13 Apr 2022 01:49:51 +0900 |
parents | 70e90ea4b870 |
children | 7a773720d81f |
rev | line source |
---|---|
0 | 1 module ApplicationHelper |
150
950849c40d42
Update all the things, including rails 5.2
nanaya <me@nanaya.pro>
parents:
103
diff
changeset
|
2 include Twitter::TwitterText::Autolink |
80 | 3 |
94 | 4 def atom_id(id) |
175
52252ae4b580
Static tag because it's supposed to be the same across rsstweet installs
nanaya <me@nanaya.pro>
parents:
172
diff
changeset
|
5 "tag:rsstweet@nanaya.pro,2014:#{id}" |
94 | 6 end |
98 | 7 |
103
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
8 def expand_url(text, *urls) |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
9 urls.flatten! |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
10 |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
11 urls = urls.reduce({}) do |result, u| |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
12 if u.try(:[], :url) |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
13 result[u[:url]] = u[:expanded_url] |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
14 end |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
15 |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
16 result |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
17 end |
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
18 |
98 | 19 text.gsub /https?:\/\/t\.co\/[A-Za-z0-9]+/ do |url| |
103
1251b3d6ec5d
Use included url data instead of expanding using embiggen
nanaya <me@myconan.net>
parents:
98
diff
changeset
|
20 urls[url] || url |
98 | 21 end |
22 end | |
204 | 23 |
24 def status_url(tweet) | |
229
12287b32fbda
Show link to parent tweet for replies
nanaya <me@nanaya.pro>
parents:
204
diff
changeset
|
25 status_url_base tweet.user.screen_name, tweet.id |
12287b32fbda
Show link to parent tweet for replies
nanaya <me@nanaya.pro>
parents:
204
diff
changeset
|
26 end |
12287b32fbda
Show link to parent tweet for replies
nanaya <me@nanaya.pro>
parents:
204
diff
changeset
|
27 |
12287b32fbda
Show link to parent tweet for replies
nanaya <me@nanaya.pro>
parents:
204
diff
changeset
|
28 def status_url_base(screen_name, tweet_id) |
12287b32fbda
Show link to parent tweet for replies
nanaya <me@nanaya.pro>
parents:
204
diff
changeset
|
29 "https://twitter.com/#{screen_name.presence || '_'}/status/#{tweet_id}" |
204 | 30 end |
0 | 31 end |