Article.rank: sort articles by category/tag w.r.t. rank
--- a/base/src/sqwl/cms/datamodel.scala Tue Jan 08 12:28:53 2019 +0100
+++ b/base/src/sqwl/cms/datamodel.scala Tue Jan 15 12:25:19 2019 +0100
@@ -20,6 +20,7 @@
def category: Option[iCategory]
def tags: Seq[iTag]
def assets: Path
+ def rank: Int
}
trait iContent {
--- a/example/src/sqwl/cms/Articles.scala Tue Jan 08 12:28:53 2019 +0100
+++ b/example/src/sqwl/cms/Articles.scala Tue Jan 15 12:25:19 2019 +0100
@@ -11,7 +11,8 @@
title: String,
category: Option[iCategory],
tags: Seq[iTag] = Seq(),
- htmlContent: String
+ htmlContent: String,
+ rank: Int = 0
) extends iArticle {
override def assets: Path = Paths.get(s"example/content/${id.v}")
override def pathSegment: String = id.v
@@ -20,10 +21,10 @@
def values: Seq[iArticle] = all.toIndexedSeq
- def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq())(
- body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = {
+ def article(title: String, cat: iCategory, tags: Seq[iTag] = Seq(),
+ rank: Int = 0)(body: Frag*)(implicit articleId: Id): SeqFrag[Frag] = {
- all += Article(articleId, title, Option(cat), tags, body.render)
+ all += Article(articleId, title, Option(cat), tags, body.render, rank)
body
}
}
--- a/example/src/sqwl/cms/Content.scala Tue Jan 08 12:28:53 2019 +0100
+++ b/example/src/sqwl/cms/Content.scala Tue Jan 15 12:25:19 2019 +0100
@@ -54,10 +54,10 @@
("site.css", Paths.get("example/content/public/css/site.css"))
def articlesByTag(t: iTag): Seq[iArticle] =
- Articles.values.filter(_.tags contains t)
+ Articles.values filter(_.tags contains t) sortBy(_.rank)
def articlesByCategory(c: iCategory): Seq[iArticle] =
- Articles.values.filter(_.category contains c)
+ Articles.values filter(_.category contains c) sortBy(_.rank)
def tags: Seq[iTag] = Tag.values