FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/article/app/model/structuredData/BlogPosting.scala at master · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
article
/
app
/
model
/
structuredData
/
BlogPosting.scala
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (45 loc) · 1.7 KB
Breadcrumbs
frontend
/
article
/
app
/
model
/
structuredData
/
BlogPosting.scala
Copy path
File metadata and controls
59 lines (45 loc) · 1.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package
model
.
structuredData
import
common
.
LinkTo
import
model
.
Article
import
model
.
liveblog
.
BodyBlock
import
org
.
joda
.
time
.
DateTime
import
play
.
api
.
libs
.
json
.{
JsValue
,
Json
}
import
play
.
api
.
mvc
.
RequestHeader
import
views
.
support
.
Format
object
BlogPosting
{
def
zulu
(
date
:
DateTime
)(
implicit
request
:
RequestHeader
)
:
String
=
Format
(date,
"
yyyy-MM-dd'T'HH:mm:ssZ
"
)
def
apply
(
blog
:
Article
,
block
:
BodyBlock
)(
implicit
request
:
RequestHeader
)
:
JsValue
=
{
def
blockDate
(
block
:
BodyBlock
)
=
block.publishedDate
match
{
case
Some
(date)
=>
zulu(date)
case
None
=>
zulu(blog.trail.webPublicationDate)
}
def
blockBody
(
block
:
BodyBlock
)
:
String
=
{
if
(block.bodyTextSummary.length
<
1000
){
block.bodyTextSummary
}
else
{
block.bodyTextSummary.substring(
0
,
1000
)
}
}
def
blockAuthor
(
blog
:
Article
,
block
:
BodyBlock
)
:
JsValue
=
{
val
name
=
block.contributors.headOption
match
{
case
Some
(id)
=>
blog.tags.tags.find(_.id
==
s
"
profile/
$id
"
).map{ contributorTag
=>
contributorTag.name
}
case
None
=>
None
}
name
match
{
case
Some
(thing)
=>
Json
.obj(
"
@type
"
->
"
Person
"
,
"
name
"
->
thing)
case
None
=>
Json
.obj(
"
@id
"
->
"
https://www.theguardian.com#publisher
"
)
}
}
Json
.obj(
"
@type
"
->
"
BlogPosting
"
,
"
headline
"
->
block.title.getOrElse[
String
](blog.trail.headline),
"
author
"
->
blockAuthor(blog, block),
"
publisher
"
->
Json
.obj(
"
@id
"
->
"
https://www.theguardian.com#publisher
"
),
"
url
"
->
LinkTo
{blog.metadata.url
+
"
?page=with:block-
"
+
block.id
+
"
#block-
"
+
block.id},
"
datePublished
"
->
blockDate(block),
"
articleBody
"
->
blockBody(block)
)
}
}
Back
|
FazBrowse Home
|
New Git URL