user blogging tweaks

pull/9711/head
Thibault Duplessis 2021-09-02 20:06:06 +02:00
parent f3d848725d
commit b77ce737e2
11 changed files with 61 additions and 23 deletions

View File

@ -39,10 +39,12 @@ final class Ublog(env: Env) extends LilaController(env) {
OptionFuResult(env.user.repo named username) { user =>
(env.ublog.api.findByAuthor(UblogPost.Id(id), user)) flatMap {
_.filter(canViewPost(user)).fold(notFound) { post =>
if (slug != post.slug) Redirect(urlOf(post)).fuccess
else {
val markup = scalatags.Text.all.raw(env.ublog.markup(post))
Ok(html.ublog.post(user, post, markup)).fuccess
env.ublog.api.otherPosts(user, post) map { others =>
if (slug != post.slug) Redirect(urlOf(post))
else {
val markup = scalatags.Text.all.raw(env.ublog.markup(post))
Ok(html.ublog.post(user, post, markup, others))
}
}
}
}
@ -141,7 +143,7 @@ final class Ublog(env: Env) extends LilaController(env) {
}
private def canViewBlogOf(user: UserModel)(implicit ctx: Context) =
ctx.is(user) || isGranted(_.ModerateBlog) || !user.marks.troll
ctx.is(user) || isGranted(_.ModerateBlog) || (user.enabled && !user.marks.troll)
private def canViewPost(user: UserModel)(post: UblogPost)(implicit ctx: Context) =
canViewBlogOf(user) && (ctx.is(user) || post.live)

View File

@ -243,7 +243,7 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
private def userUrl(username: String, params: String = ""): Option[String] =
(username != "Ghost" && username != "ghost") option s"""${routes.User.show(username)}$params"""
protected def userClass(
def userClass(
userId: String,
cssClass: Option[String],
withOnline: Boolean,

View File

@ -19,7 +19,7 @@ object form {
moreCss = cssTag("ublog"),
title = s"${trans.ublog.xBlog.txt(user.username)}${trans.ublog.newPost()}"
) {
main(cls := "box box-pad page ublog-post-form")(
main(cls := "box box-pad page page-small ublog-post-form")(
h1(trans.ublog.newPost()),
inner(user, f, none)
)
@ -31,7 +31,7 @@ object form {
moreJs = jsModule("ublog"),
title = s"${trans.ublog.xBlog.txt(user.username)} blog • ${post.title}"
) {
main(cls := "box box-pad page ublog-post-form")(
main(cls := "box box-pad page page-small ublog-post-form")(
h1(trans.ublog.editYourBlogPost()),
imageForm(user, post),
inner(user, f, post.some),
@ -64,7 +64,7 @@ object form {
)
)
def formImage(post: UblogPost) = postView.imageOf(post, height = 300)
def formImage(post: UblogPost) = postView.imageOf(post, height = 200)
private def inner(user: User, form: Form[UblogPostData], post: Option[UblogPost])(implicit
ctx: Context

View File

@ -15,7 +15,8 @@ object index {
def apply(user: User, posts: Paginator[UblogPost])(implicit ctx: Context) =
views.html.base.layout(
moreCss = frag(cssTag("ublog")),
moreCss = cssTag("ublog"),
moreJs = ctx.is(user) option jsModule("ublog"),
title = trans.ublog.xBlog.txt(user.username)
) {
main(cls := "box box-pad page page-small ublog-index")(

View File

@ -12,10 +12,10 @@ import lila.user.User
object post {
def apply(user: User, post: UblogPost, markup: Frag)(implicit ctx: Context) =
def apply(user: User, post: UblogPost, markup: Frag, others: List[UblogPost])(implicit ctx: Context) =
views.html.base.layout(
moreCss = frag(cssTag("ublog")),
moreJs = jsModule("expandText"),
moreJs = frag(jsModule("expandText"), ctx.is(user) option jsModule("ublog")),
title = s"${trans.ublog.xBlog.txt(user.username)}${post.title}",
openGraph = lila.app.ui
.OpenGraph(
@ -28,13 +28,18 @@ object post {
.some
) {
main(cls := "box box-pad page page-small ublog-post")(
header(cls := "ublog-post__header")(
a(href := routes.Ublog.index(user.username))(trans.ublog.xBlog(user.username))
),
ctx.is(user) option standardFlash(),
h1(cls := "ublog-post__title")(post.title),
div(cls := "ublog-post__meta")(
span(cls := "ublog-post__meta__author")(trans.by(userLink(user))),
span(cls := "ublog-post__meta__author")(
trans.by(
a(
href := routes.Ublog.index(user.username),
cls := userClass(user.id, none, withOnline = true),
dataHref := routes.User.show(user.username)
)(lineIcon(user), titleTag(user.title), user.username)
)
),
post.liveAt map { date =>
span(cls := "ublog-post__meta__date")(semanticDate(date))
},
@ -63,7 +68,8 @@ object post {
strong(cls := "ublog-post__intro")(post.intro),
div(cls := "ublog-post__markup expand-text")(markup),
div(cls := "ublog-post__footer")(
a(href := routes.Ublog.index(user.username))(trans.ublog.moreBlogPostsBy(user.username))
h2(a(href := routes.Ublog.index(user.username))(trans.ublog.moreBlogPostsBy(user.username))),
others.size > 0 option div(cls := "ublog-post-cards")(others map { card(_) })
)
)
}

View File

@ -44,6 +44,13 @@ final class UblogApi(coll: Coll, picfitApi: PicfitApi, timeline: lila.hub.actors
def findByAuthor(id: UblogPost.Id, author: User): Fu[Option[UblogPost]] =
coll.one[UblogPost]($id(id) ++ $doc("user" -> author.id))
def otherPosts(author: User, post: UblogPost): Fu[List[UblogPost]] =
coll
.find($doc("user" -> author.id, "live" -> true, "_id" $ne post.id))
.sort($doc("liveAt" -> -1, "createdAt" -> -1))
.cursor[UblogPost]()
.list(4)
def countLiveByUser(user: User): Fu[Int] = coll.countSel($doc("user" -> user.id, "live" -> true))
def liveByUser(user: User, page: Int): Fu[Paginator[UblogPost]] =

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -17,7 +17,7 @@
<string name="xPublishedY">%1$s published %2$s</string>
<string name="thisPostIsPublished">This post is published</string>
<string name="thisIsADraft">This is a draft</string>
<string name="moreBlogPostsBy">View more blog posts by %s</string>
<string name="moreBlogPostsBy">More blog posts by %s</string>
<string name="noPostsInThisBlogYet">No posts in this blog, yet.</string>
<string name="noDrafts">No drafts to show.</string>
</resources>

View File

@ -8,4 +8,12 @@
&__etiquette {
margin-right: 3em;
}
&__image {
.form-group {
text-align: center;
@extend %flex-column;
justify-content: center;
align-items: center;
}
}
}

View File

@ -20,10 +20,6 @@
}
}
&-post {
@include fluid-size('--box-padding', 25px, 100px);
&__header {
@extend %flex-between;
}
&__title {
text-align: center;
margin: 6vh 0 2vh;
@ -49,8 +45,25 @@
display: block;
}
&__footer {
text-align: center;
margin: 5vh 0 0 0;
h2 {
margin-bottom: 1em;
}
}
}
}
main.page {
position: relative;
.flash {
position: absolute;
top: 0;
right: 0;
margin: 0;
&.fade {
opacity: 0;
transition: 3s;
transition-delay: 2s;
}
}
}

View File

@ -16,4 +16,5 @@ lichess.load.then(() => {
);
});
});
$('.flash').addClass('fade');
});