use real dates from prismic
This commit is contained in:
parent
5639161c68
commit
5e5a94dabe
|
@ -46,6 +46,9 @@ trait DateHelper { self: I18nHelper =>
|
|||
def showDate(date: DateTime)(implicit ctx: Context): String =
|
||||
dateFormatter(ctx) print date
|
||||
|
||||
def semanticDate(date: DateTime)(implicit ctx: Context): String =
|
||||
s"""<time datetime="${isoFormatter print date}">${showDate(date)}</time>"""
|
||||
|
||||
def showPeriod(period: Period)(implicit ctx: Context): String =
|
||||
periodFormatter(ctx) print period.normalizedStandard(periodType)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@(doc: io.prismic.Document)(implicit ctx: Context, prismic: lila.blog.BlogApi.Context)
|
||||
<div class="meta">
|
||||
@doc.getText("blog.date").map { date =>
|
||||
<span data-icon="p"> @date</span>
|
||||
@doc.getDate("blog.date").map { date =>
|
||||
<span data-icon="p"> @semanticDate(date.value)</span>
|
||||
}
|
||||
@doc.getText("blog.author").map { author =>
|
||||
<span data-icon="r"> @author</span>
|
||||
|
|
|
@ -181,7 +181,7 @@ openGraph = Map(
|
|||
<img src="@post.image" />
|
||||
</a>
|
||||
<div class="text">
|
||||
<span class="date">@post.date</span>
|
||||
@semanticDate(post.date)
|
||||
<a class="title revert-underline" href="@url">@post.title</a>
|
||||
<p class="shortlede">@post.shortlede</p>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,9 @@ import play.api.mvc.RequestHeader
|
|||
final class BlogApi(prismicUrl: String, collection: String) {
|
||||
|
||||
def recent(api: Api, ref: Option[String], nb: Int) =
|
||||
api.forms(collection).ref(ref | api.master.ref).pageSize(nb).page(1).submit()
|
||||
api.forms(collection).ref(ref | api.master.ref)
|
||||
.orderings(s"[my.$collection.date desc]")
|
||||
.pageSize(nb).page(1).submit()
|
||||
|
||||
def one(api: Api, ref: Option[String], id: String) =
|
||||
api.forms(collection)
|
||||
|
|
|
@ -20,7 +20,7 @@ final class Env(
|
|||
prismicUrl = PrismicApiUrl,
|
||||
collection = PrismicCollection)
|
||||
|
||||
lazy val lastPostCache = new LastPostCache(api, LastPostCacheTtl)
|
||||
lazy val lastPostCache = new LastPostCache(api, LastPostCacheTtl, PrismicCollection)
|
||||
|
||||
private implicit lazy val notifier = new Notifier(
|
||||
blogApi = api,
|
||||
|
|
|
@ -2,11 +2,11 @@ package lila.blog
|
|||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
final class LastPostCache(api: BlogApi, ttl: Duration) {
|
||||
final class LastPostCache(api: BlogApi, ttl: Duration, collection: String) {
|
||||
|
||||
private val cache = lila.memo.MixedCache.single[List[MiniPost]](
|
||||
api.prismicApi flatMap { prismic =>
|
||||
api.recent(prismic, none, 3) map (_.results flatMap MiniPost.fromDocument)
|
||||
api.recent(prismic, none, 3) map (_.results flatMap MiniPost.fromDocument(collection))
|
||||
},
|
||||
timeToLive = ttl,
|
||||
default = Nil,
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
package lila.blog
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
case class MiniPost(
|
||||
id: String,
|
||||
slug: String,
|
||||
title: String,
|
||||
shortlede: String,
|
||||
date: String,
|
||||
date: DateTime,
|
||||
image: String)
|
||||
|
||||
object MiniPost {
|
||||
|
||||
def fromDocument(doc: io.prismic.Document): Option[MiniPost] = for {
|
||||
title <- doc getText "blog.title"
|
||||
shortlede <- doc getText "blog.shortlede"
|
||||
date <- doc getText "blog.date"
|
||||
image <- doc.getImage("blog.image", "column").map(_.url)
|
||||
def fromDocument(coll: String)(doc: io.prismic.Document): Option[MiniPost] = for {
|
||||
title <- doc getText s"$coll.title"
|
||||
shortlede = ~(doc getText s"$coll.shortlede")
|
||||
date <- doc getDate s"$coll.date" map (_.value)
|
||||
image = ~doc.getImage(s"$coll.image", "column").map(_.url)
|
||||
} yield MiniPost(doc.id, doc.slug, title, shortlede, date, image)
|
||||
}
|
||||
|
|
|
@ -2027,7 +2027,7 @@ div.blog.undertable div.post .title {
|
|||
font-weight: bold;
|
||||
line-height: 2;
|
||||
}
|
||||
div.blog.undertable div.post .date {
|
||||
div.blog.undertable div.post time {
|
||||
float: right;
|
||||
font-weight: 100;
|
||||
line-height: 2;
|
||||
|
|
Loading…
Reference in a new issue