create and link forum topic for each blog post
parent
2ef08ee0a2
commit
7efe667198
|
@ -44,6 +44,31 @@ object Blog extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
def discuss(id: String) = Open { implicit ctx =>
|
||||
val categSlug = "general-chess-discussion"
|
||||
val topicSlug = s"blog-$id"
|
||||
val redirect = Redirect(routes.ForumTopic.show(categSlug, topicSlug))
|
||||
lila.forum.TopicRepo.existsByTree(categSlug, id) flatMap {
|
||||
case true => fuccess(redirect)
|
||||
case _ => blogApi context none flatMap { implicit prismic =>
|
||||
blogApi.one(prismic.api, none, id) flatMap {
|
||||
_ ?? { doc =>
|
||||
lila.forum.CategRepo.bySlug(categSlug) flatMap {
|
||||
_ ?? { categ =>
|
||||
Env.forum.topicApi.makeBlogDiscuss(
|
||||
categ = categ,
|
||||
slug = topicSlug,
|
||||
name = doc.getText("blog.title") | "New blog post",
|
||||
url = s"${Env.api.Net.BaseUrl}${routes.Blog.show(doc.id, doc.slug)}"
|
||||
)
|
||||
}
|
||||
} inject redirect
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -- Helper: Check if the slug is valid and redirect to the most recent version id needed
|
||||
private def checkSlug(document: Option[Document], slug: String)(callback: Either[String, Document] => Result)(implicit ctx: lila.api.Context) =
|
||||
document.collect {
|
||||
|
|
|
@ -29,5 +29,14 @@ description = ~doc.getText("blog.shortlede")).some) {
|
|||
<div class="body embed_analyse">
|
||||
@doc.getHtml("blog.body", prismic.linkResolver).map(lila.blog.Youtube.fixStartTimes).map(lila.blog.ProtocolFix.remove).map(Html.apply)
|
||||
</div>
|
||||
@NotForKids {
|
||||
<div class="footer">
|
||||
@if(prismic.maybeRef.isEmpty) {
|
||||
<a href="@routes.Blog.discuss(doc.id)" class="button text discuss" data-icon="d">Discuss this blog post in the forum</a>
|
||||
} else {
|
||||
<p>This is a preview.</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ GET /socket controllers.Main.websocket
|
|||
|
||||
# Blog
|
||||
GET /blog controllers.Blog.index(ref: Option[String] ?= None)
|
||||
GET /blog/discuss/:id controllers.Blog.discuss(id: String)
|
||||
GET /blog/:id/:slug controllers.Blog.show(id: String, slug: String, ref: Option[String] ?= None)
|
||||
GET /blog.atom controllers.Blog.atom(ref: Option[String] ?= None)
|
||||
|
||||
|
|
|
@ -87,6 +87,35 @@ private[forum] final class TopicApi(
|
|||
} inject topic
|
||||
}
|
||||
|
||||
def makeBlogDiscuss(categ: Categ, slug: String, name: String, url: String): Funit = {
|
||||
val topic = Topic.make(
|
||||
categId = categ.slug,
|
||||
slug = slug,
|
||||
name = name,
|
||||
troll = false,
|
||||
hidden = false
|
||||
)
|
||||
val post = Post.make(
|
||||
topicId = topic.id,
|
||||
author = none,
|
||||
userId = "lichess".some,
|
||||
ip = none,
|
||||
troll = false,
|
||||
hidden = false,
|
||||
text = s"Comments on $url",
|
||||
lang = none,
|
||||
number = 1,
|
||||
categId = categ.id,
|
||||
modIcon = true.some
|
||||
)
|
||||
env.postColl.insert(post) >>
|
||||
env.topicColl.insert(topic withPost post) >>
|
||||
env.categColl.update($id(categ.id), categ withTopic post) >>-
|
||||
(indexer ! InsertPost(post)) >>-
|
||||
env.recent.invalidate >>-
|
||||
bus.publish(actorApi.CreatePost(post, topic), 'forumPost) void
|
||||
}
|
||||
|
||||
def paginator(categ: Categ, page: Int, troll: Boolean): Fu[Paginator[TopicView]] = {
|
||||
val adapter = new Adapter[Topic](
|
||||
collection = env.topicColl,
|
||||
|
|
|
@ -38,6 +38,9 @@ sealed abstract class TopicRepo(troll: Boolean) {
|
|||
def byTree(categSlug: String, slug: String): Fu[Option[Topic]] =
|
||||
coll.uno[Topic]($doc("categId" -> categSlug, "slug" -> slug) ++ trollFilter)
|
||||
|
||||
def existsByTree(categSlug: String, slug: String): Fu[Boolean] =
|
||||
coll.exists($doc("categId" -> categSlug, "slug" -> slug))
|
||||
|
||||
def stickyByCateg(categ: Categ): Fu[List[Topic]] =
|
||||
coll.list[Topic](byCategQuery(categ) ++ stickyQuery)
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#lichess_blog .body {
|
||||
font-size: 1.4em;
|
||||
line-height: 1.6;
|
||||
margin: 20px 0 80px 0;
|
||||
margin: 20px 0 60px 0;
|
||||
cursor: initial;
|
||||
}
|
||||
#lichess_blog .body p {
|
||||
|
@ -103,3 +103,8 @@
|
|||
#lichess_blog .list .more {
|
||||
text-align: center;
|
||||
}
|
||||
#lichess_blog .footer {
|
||||
text-align: center;
|
||||
font-size: 1.3em;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue