Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jeff
pleroma
Commits
d903e34c
Commit
d903e34c
authored
6 years ago
by
raeno
Browse files
Options
Downloads
Patches
Plain Diff
Add opengraph/twitter_card:summary support. Add config to toggle on/off specific metadata
parent
89029421
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config/config.exs
+4
-0
4 additions, 0 deletions
config/config.exs
lib/pleroma/web/ostatus/ostatus.ex
+52
-6
52 additions, 6 deletions
lib/pleroma/web/ostatus/ostatus.ex
lib/pleroma/web/ostatus/ostatus_controller.ex
+3
-3
3 additions, 3 deletions
lib/pleroma/web/ostatus/ostatus_controller.ex
with
59 additions
and
9 deletions
config/config.exs
+
4
−
0
View file @
d903e34c
...
...
@@ -171,6 +171,10 @@ config :pleroma, :gopher,
ip:
{
0
,
0
,
0
,
0
},
port:
9999
config
:pleroma
,
:metadata
,
oembed:
false
,
opengraph:
true
config
:pleroma
,
:suggestions
,
enabled:
false
,
third_party_engine:
...
...
This diff is collapsed.
Click to expand it.
lib/pleroma/web/ostatus/ostatus.ex
+
52
−
6
View file @
d903e34c
...
...
@@ -5,11 +5,12 @@ defmodule Pleroma.Web.OStatus do
import
Pleroma
.
Web
.
XML
require
Logger
alias
Pleroma
.
{
Repo
,
User
,
Web
,
Object
,
Activity
}
alias
Pleroma
.
{
Repo
,
User
,
Web
,
Object
,
Activity
,
Formatter
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
{
WebFinger
,
Websub
}
alias
Pleroma
.
Web
.
{
WebFinger
,
Websub
,
MediaProxy
}
alias
Pleroma
.
Web
.
OStatus
.
{
FollowHandler
,
UnfollowHandler
,
NoteHandler
,
DeleteHandler
}
alias
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
alias
Phoenix
.
HTML
def
is_representable?
(%
Activity
{
data:
data
})
do
object
=
Object
.
normalize
(
data
[
"object"
])
...
...
@@ -26,14 +27,59 @@ defmodule Pleroma.Web.OStatus do
end
end
def
metadata
(
url
),
do
:
oembed_links
(
url
)
def
metadata
(
activity
,
user
,
url
)
do
Enum
.
concat
([
if
(
meta_enabled?
(
:opengraph
),
do
:
opengraph_tags
(
activity
,
user
),
else
:
[]),
if
(
meta_enabled?
(
:oembed
),
do
:
oembed_links
(
url
),
else
:
[])
])
|>
Enum
.
map
(
&
to_tag
/
1
)
|>
Enum
.
map
(
&
HTML
.
safe_to_string
/
1
)
|>
Enum
.
join
(
"
\n
"
)
end
def
meta_enabled?
(
type
)
do
config
=
Pleroma
.
Config
.
get
(
:metadata
,
[])
Keyword
.
get
(
config
,
type
,
false
)
end
def
to_tag
(
data
)
do
with
{
name
,
attrs
,
_content
=
[]}
<-
data
do
HTML
.
Tag
.
tag
(
name
,
attrs
)
else
{
name
,
attrs
,
content
}
->
HTML
.
Tag
.
content_tag
(
name
,
content
,
attrs
)
_
->
raise
ArgumentError
,
message:
"make_tag invalid args"
end
end
def
oembed_links
(
url
)
do
Enum
.
map
([
"xml"
,
"json"
],
fn
format
->
href
=
oembed_path
(
url
,
format
)
"<
link
rel=
\"
alternate
\"
type
=
\
"
application/
#{
format
}
+oembed
\
"
href
=
\"
#{
href
}
\"
>"
href
=
HTML
.
raw
(
oembed_path
(
url
,
format
)
)
{
:
link
,
[
type
:
[
"application/
#{
format
}
+oembed"
],
href
:
href
,
rel:
'alternate'
],
[]
}
end
)
|>
Enum
.
join
(
"
\r\n
"
)
end
def
opengraph_tags
(
activity
,
user
)
do
with
image
=
User
.
avatar_url
(
user
)
|>
MediaProxy
.
url
(),
truncated_content
=
Formatter
.
truncate
(
activity
.
data
[
"object"
][
"content"
]),
domain
=
Pleroma
.
Config
.
get
([
:instance
,
:domain
],
"UNKNOWN_DOMAIN"
)
do
[
{
:meta
,
[
property:
"og:title"
,
content:
"
#{
user
.
name
}
(@
#{
user
.
nickname
}
@
#{
domain
}
) post #
#{
activity
.
id
}
"
],
[]},
{
:meta
,
[
property:
"og:url"
,
content:
activity
.
data
[
"id"
]],
[]},
{
:meta
,
[
property:
"og:description"
,
content:
truncated_content
],
[]},
{
:meta
,
[
property:
"og:image"
,
content:
image
],
[]},
{
:meta
,
[
property:
"og:image:width"
,
content:
120
],
[]},
{
:meta
,
[
property:
"og:image:height"
,
content:
120
],
[]},
{
:meta
,
[
property:
"twitter:card"
,
content:
"summary"
],
[]}
]
end
end
def
feed_path
(
user
)
do
...
...
This diff is collapsed.
Click to expand it.
lib/pleroma/web/ostatus/ostatus_controller.ex
+
3
−
3
View file @
d903e34c
...
...
@@ -134,7 +134,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
%
User
{}
=
user
<-
User
.
get_cached_by_ap_id
(
activity
.
data
[
"actor"
])
do
case
format
=
get_format
(
conn
)
do
"html"
->
serve_static_with_meta
(
conn
,
activity
)
serve_static_with_meta
(
conn
,
activity
,
user
)
_
->
represent_activity
(
conn
,
format
,
activity
,
user
)
...
...
@@ -151,9 +151,9 @@ defmodule Pleroma.Web.OStatus.OStatusController do
end
end
defp
serve_static_with_meta
(
conn
,
activity
)
do
defp
serve_static_with_meta
(
conn
,
activity
,
user
)
do
{
:ok
,
index_content
}
=
File
.
read
(
Application
.
app_dir
(
:pleroma
,
"priv/static/index.html"
))
links
=
OStatus
.
metadata
(
request_url
(
conn
))
links
=
OStatus
.
metadata
(
activity
,
user
,
request_url
(
conn
))
response
=
String
.
replace
(
index_content
,
"<!--server-generated-meta-->"
,
links
)
conn
|>
put_resp_content_type
(
"text/html"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment