-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathBadges.scala
187 lines (175 loc) · 8.55 KB
/
Badges.scala
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package model
import conf.Static
import layout.FaciaContainer
import org.apache.commons.codec.digest.DigestUtils
trait BaseBadge {
def maybeThisBadge(tag: String): Option[Badge]
}
case class Badge(seriesTag: String, imageUrl: String, classModifier: Option[String] = None) extends BaseBadge {
def maybeThisBadge(tag: String): Option[Badge] = if (seriesTag == tag) Some(this) else None
}
// for salt use a random unique string - e.g. some string from running in terminal: pwgen -n -y 20
// it's fine to commit that, it just stops people using previously calculated tables to reverse the hash
case class SpecialBadge(salt: String, hashedTag: String, imageUrl: String) extends BaseBadge {
def maybeThisBadge(tag: String): Option[Badge] =
if (md5(salt + tag).contains(hashedTag)) {
Some(Badge(tag, imageUrl))
} else None
private def md5(input: String): Option[String] = {
Some(DigestUtils.md5Hex(input))
}
}
object Badges {
val newArrivals =
Badge("world/series/the-new-arrivals", Static("images/badges/new-arrivals.png"), Some("new-arrivals"))
val brexitGamble = Badge("uk-news/series/the-brexit-gamble", Static("images/badges/EUReferendumBadge.svg"))
val roadToTheVote = Badge("politics/series/road-to-the-vote", Static("images/badges/EUReferendumBadge.svg"))
val brexitFrontline = Badge("politics/series/brexit-frontline", Static("images/badges/EUReferendumBadge.svg"))
val brexitDividedGenerations =
Badge("politics/series/brexit-divided-generations", Static("images/badges/EUReferendumBadge.svg"))
val brexitHowItCameToThis =
Badge("politics/series/brexit-how-it-came-to-this", Static("images/badges/EUReferendumBadge.svg"))
val londonVersus = Badge("uk-news/series/london-versus", Static("images/badges/london-versus.svg"))
val beyondTheBlade = Badge("membership/series/beyond-the-blade", Static("images/badges/beyondthebladebadge.svg"))
val euElection = Badge("politics/2019-european-parliamentary-elections", Static("images/badges/eu_election.svg"))
val paradisePapers = Badge("news/series/paradise-papers", Static("images/badges/pp_web.svg"))
val cambridgeAnalytica = Badge("news/series/cambridge-analytica-files", Static("images/badges/calock.svg"))
val pegasusProject = Badge("news/series/pegasus-project", Static("images/badges/SpecialReportJul21.svg"))
val suisseSecretsProject = Badge("news/series/suisse-secrets", Static("images/badges/18_feb_2022_Badge.svg"))
val specialReport = SpecialBadge(
"06966783c5b5413394df723f2ca58030953",
"feb78187bd4de427603a164d0a69f19f",
Static("images/badges/56738_Badge.svg"),
)
val specialReport2 = SpecialBadge(
"a-public-salt3W#ywHav!p+?r+W2$E6=",
"0d18e8413ab7cdf377e1202d24452e63",
Static("images/badges/05_july_2022_Badge.svg"),
)
val pandoraPapers = Badge("news/series/pandora-papers", Static("images/badges/SpecialReportSep21.svg"))
val nhs70 = Badge("society/series/nhs-at-70", Static("images/badges/nhs-70.svg"))
val cricketWorldCup = Badge("sport/cricket-world-cup-2019", Static("images/badges/cricket-world-cup.svg"))
val womensWorldCup = Badge("football/womens-world-cup-2019", Static("images/badges/womens-world-cup.svg"))
val greenBlood = Badge("environment/series/green-blood", Static("images/badges/green-blood.svg"))
val ausElection =
Badge("australia-news/australian-election-2019", Static("images/badges/australian-election-2019.svg"))
val midterm = Badge("us-news/us-midterm-elections-2018", Static("images/badges/midterm.svg"))
val theNewPopulism = Badge("world/series/the-new-populism", Static("images/badges/the-new-populism.svg"))
val theImplantFiles = Badge("society/series/the-implant-files", Static("images/badges/the-implant-files.svg"))
val theRealBorisJohnson =
Badge("politics/series/the-real-boris-johnson ", Static("images/badges/the-real-boris-johnson.svg"))
val johnsonsPromises = Badge("uk-news/series/johnsons-promises", Static("images/badges/johnsons-promises.svg"))
val rugbyWorldCup = Badge("sport/rugby-world-cup-2019", Static("images/badges/rugby-world-cup.svg"))
val behindTheLines = Badge("uk-news/series/behind-the-lines", Static("images/badges/behind-the-lines.svg"))
val theEmptyDoorway = Badge("cities/series/the-empty-doorway", Static("images/badges/the-empty-doorway.svg"))
val yemenAtWar = Badge("world/series/yemen-at-war", Static("images/badges/yemen-at-war.svg"))
val thePolluters = Badge("environment/series/the-polluters", Static("images/badges/the-polluters.svg"))
val lostInPolitics = Badge("politics/series/lost-in-politics", Static("images/badges/lost-in-politics-badge.svg"))
val thisIsEurope = Badge("world/series/this-is-europe", Static("images/badges/this-is-europe.svg"))
val coronavirus =
Badge("world/series/coronavirus-100-days-that-changed-the-world", Static("images/badges/corona-badge.svg"))
val auGreenRecovery = Badge("australia-news/series/the-green-recovery", Static("images/badges/green-recovery.svg"))
val greenRecovery = Badge("environment/series/the-green-recovery", Static("images/badges/green-recovery.svg"))
val culturePeril = Badge("culture/series/culture-in-peril", Static("images/badges/culture-badge.svg"))
val oneHundredDays = Badge("us-news/series/climate-countdown", Static("images/badges/100days.svg"))
val futureofcities = Badge("society/futureofcities", Static("images/badges/futureofcities.svg"))
val theFightForHongKong = Badge("world/series/the-fight-for-hong-kong", Static("images/badges/eohk.svg"))
val spyCopsScandal = Badge("uk-news/series/spy-cops-scandal", Static("images/badges/spy-cops-scandal.svg"))
val theLastChance = Badge("environment/series/the-last-chance", Static("images/badges/the-last-chance.svg"))
val dreamsInterrupted =
Badge("australia-news/series/dreams-interrupted", Static("images/badges/dreams-interrupted.svg"))
val anniversary200 =
Badge("media/series/guardian-200", Static("images/badges/anniversary200.svg"))
val euro2020 =
Badge("football/euro-2020", Static("images/badges/euro-2020.svg"))
val tokyo2020 =
Badge("sport/olympic-games-2020", Static("images/badges/tokyo-2020.svg"))
val paralympics2020 =
Badge("sport/paralympic-games-2020", Static("images/badges/tokyo-2020.svg"))
val tokyoparalympics2020 =
Badge("sport/tokyo-paralympic-games-2020", Static("images/badges/tokyo-2020.svg"))
val cop26 =
Badge("environment/cop26-glasgow-climate-change-conference-2021", Static("images/badges/cop26-badge.svg"))
val winterOlympics2022 =
Badge("sport/winter-olympics-2022", Static("images/badges/winter-olympics-2022-badge.svg"))
val ausElection2022 =
Badge("australia-news/australian-election-2022", Static("images/badges/australian-election-2022.svg"))
val newsletters =
Badge("tone/newsletter-tone", Static("images/badges/newsletter-badge.svg"))
val womenseuros2022 =
Badge("football/women-s-euro-2022", Static("images/badges/womens_euros_2022_badge.svg"))
val usMidtermElections2022 =
Badge("us-news/us-midterm-elections-2022", Static("images/badges/us-midterm-elections-2022.svg"))
val worldCup2022 =
Badge("football/world-cup-2022", Static("images/badges/world-cup-2022.svg"))
val allBadges = Seq(
newArrivals,
brexitGamble,
roadToTheVote,
brexitFrontline,
brexitDividedGenerations,
brexitHowItCameToThis,
londonVersus,
beyondTheBlade,
euElection,
paradisePapers,
cambridgeAnalytica,
pegasusProject,
suisseSecretsProject,
specialReport,
pandoraPapers,
nhs70,
cricketWorldCup,
womensWorldCup,
greenBlood,
ausElection,
midterm,
theNewPopulism,
theImplantFiles,
theRealBorisJohnson,
johnsonsPromises,
rugbyWorldCup,
behindTheLines,
theEmptyDoorway,
yemenAtWar,
thePolluters,
lostInPolitics,
thisIsEurope,
coronavirus,
auGreenRecovery,
greenRecovery,
culturePeril,
oneHundredDays,
futureofcities,
theFightForHongKong,
spyCopsScandal,
theLastChance,
dreamsInterrupted,
anniversary200,
euro2020,
tokyo2020,
paralympics2020,
tokyoparalympics2020,
cop26,
winterOlympics2022,
specialReport2,
ausElection2022,
newsletters,
womenseuros2022,
usMidtermElections2022,
worldCup2022,
)
def badgeFor(c: ContentType): Option[Badge] = {
badgeForTags(c.tags.tags.map(_.id))
}
def badgeForTags(tags: Iterable[String]): Option[Badge] = {
val badgesForTags =
for {
tagId <- tags
baseBadge <- allBadges
maybeBadge <- baseBadge.maybeThisBadge(tagId)
} yield maybeBadge
badgesForTags.headOption
}
def badgeFor(fc: FaciaContainer): Option[Badge] = badgeForTags(fc.href)
}