compose ublog markup processing functions with andThen
This commit is contained in:
parent
136631f425
commit
5225485c7b
|
@ -22,21 +22,20 @@ final class UblogMarkup(baseUrl: config.BaseUrl, assetBaseUrl: config.AssetBaseU
|
||||||
type Text = String
|
type Text = String
|
||||||
type Html = String
|
type Html = String
|
||||||
|
|
||||||
def apply(post: UblogPost): String =
|
def apply(post: UblogPost): String = cache.get(post.markdown, process(post))
|
||||||
cache.get(post.markdown, str => postProcess(renderer(s"ublog:${post.id}")(preProcess(str))))
|
|
||||||
|
|
||||||
private def preProcess(markdown: Text) = unescapeAtUsername(replaceGameGifs(markdown))
|
private val cache = lila.memo.CacheApi.scaffeineNoScheduler.maximumSize(2048).build[Text, Html]()
|
||||||
|
|
||||||
private def postProcess(html: String) = unescapeUnderscoreInLinks(imageParagraph(html))
|
private def process(post: UblogPost): Text => Html = replaceGameGifs.apply andThen
|
||||||
|
unescapeAtUsername.apply andThen
|
||||||
private val cache = lila.memo.CacheApi.scaffeineNoScheduler
|
renderer(s"ublog:${post.id}") andThen
|
||||||
.maximumSize(2048)
|
imageParagraph andThen
|
||||||
.build[Text, Html]()
|
unescapeAtUsername.apply
|
||||||
|
|
||||||
// replace game GIFs URLs with actual game URLs that can be embedded
|
// replace game GIFs URLs with actual game URLs that can be embedded
|
||||||
private object replaceGameGifs {
|
private object replaceGameGifs {
|
||||||
private val regex = (assetBaseUrl.value + """/game/export/gif(/white|/black|)/(\w{8})\.gif""").r
|
private val regex = (assetBaseUrl.value + """/game/export/gif(/white|/black|)/(\w{8})\.gif""").r
|
||||||
def apply(markdown: Text) = regex.replaceAllIn(markdown, baseUrl.value + "/$2$1")
|
val apply = (markdown: Text) => regex.replaceAllIn(markdown, baseUrl.value + "/$2$1")
|
||||||
}
|
}
|
||||||
|
|
||||||
// put images into a container for styling
|
// put images into a container for styling
|
||||||
|
|
Loading…
Reference in a new issue