From f1a0ee4d4d5133a492119812ddd16555223489c7 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 8 Jun 2016 13:42:51 +0200 Subject: [PATCH] remove wiki module --- app/Env.scala | 1 - app/controllers/Wiki.scala | 19 ---------- app/views/wiki/layout.scala.html | 18 --------- app/views/wiki/menu.scala.html | 9 ----- app/views/wiki/show.scala.html | 11 ------ conf/base.conf | 5 --- conf/routes | 4 -- modules/api/src/main/Cli.scala | 1 - modules/wiki/src/main/Api.scala | 25 ------------- modules/wiki/src/main/Env.scala | 35 ------------------ modules/wiki/src/main/Fetch.scala | 57 ----------------------------- modules/wiki/src/main/Page.scala | 49 ------------------------- modules/wiki/src/main/package.scala | 3 -- project/Build.scala | 7 +--- public/stylesheets/wiki.css | 42 --------------------- 15 files changed, 1 insertion(+), 285 deletions(-) delete mode 100644 app/controllers/Wiki.scala delete mode 100644 app/views/wiki/layout.scala.html delete mode 100644 app/views/wiki/menu.scala.html delete mode 100644 app/views/wiki/show.scala.html delete mode 100644 modules/wiki/src/main/Api.scala delete mode 100644 modules/wiki/src/main/Env.scala delete mode 100644 modules/wiki/src/main/Fetch.scala delete mode 100644 modules/wiki/src/main/Page.scala delete mode 100644 modules/wiki/src/main/package.scala delete mode 100644 public/stylesheets/wiki.css diff --git a/app/Env.scala b/app/Env.scala index a287dfa7d5..62de4d7645 100644 --- a/app/Env.scala +++ b/app/Env.scala @@ -103,7 +103,6 @@ object Env { def db = lila.db.Env.current def user = lila.user.Env.current def security = lila.security.Env.current - def wiki = lila.wiki.Env.current def hub = lila.hub.Env.current def socket = lila.socket.Env.current def message = lila.message.Env.current diff --git a/app/controllers/Wiki.scala b/app/controllers/Wiki.scala deleted file mode 100644 index ce47fadf19..0000000000 --- a/app/controllers/Wiki.scala +++ /dev/null @@ -1,19 +0,0 @@ -package controllers - -import lila.app._ -import views._ - -import play.api.mvc._, Results._ - -object Wiki extends LilaController { - - val home = Open { implicit ctx => - fuccess(Redirect(routes.Wiki.show("Lichess-Wiki"))) - } - - def show(slug: String) = Open { implicit ctx => - OptionOk(Env.wiki.api.show(slug, lang(ctx.req).language)) { - case (page, pages) => html.wiki.show(page, pages) - } - } -} diff --git a/app/views/wiki/layout.scala.html b/app/views/wiki/layout.scala.html deleted file mode 100644 index 22c4e45f85..0000000000 --- a/app/views/wiki/layout.scala.html +++ /dev/null @@ -1,18 +0,0 @@ -@(title: String, pages: List[lila.wiki.Page])(body: Html)(implicit ctx: Context) - -@moreCss = { -@cssTag("wiki.css") -} - -@side = { - -} - -@base.layout( -title = title, -moreCss = moreCss, -side = side.some) { -
@body
-} diff --git a/app/views/wiki/menu.scala.html b/app/views/wiki/menu.scala.html deleted file mode 100644 index 740f4db711..0000000000 --- a/app/views/wiki/menu.scala.html +++ /dev/null @@ -1,9 +0,0 @@ -@(pages: List[lila.wiki.Page])(implicit ctx: Context) - - diff --git a/app/views/wiki/show.scala.html b/app/views/wiki/show.scala.html deleted file mode 100644 index 1abe663b90..0000000000 --- a/app/views/wiki/show.scala.html +++ /dev/null @@ -1,11 +0,0 @@ -@(page: lila.wiki.Page, pages: List[lila.wiki.Page])(implicit ctx: Context) - -@wiki.layout(pages = pages, title = page.title) { - -
-

@page.title

-
- @Html(page.body) -
-
-} diff --git a/conf/base.conf b/conf/base.conf index 10e665f387..83be43f13d 100644 --- a/conf/base.conf +++ b/conf/base.conf @@ -564,11 +564,6 @@ fishnet { application { global="lila.app.Global" } -wiki { - collection.page = wiki - git.url = "git://github.com/ornicar/lichess.wiki.git" - markdown_path = "/usr/bin/markdown" -} importer { delay = 50 milliseconds } diff --git a/conf/routes b/conf/routes index cf9d438a2f..cb8a1065dd 100644 --- a/conf/routes +++ b/conf/routes @@ -315,10 +315,6 @@ GET /mod/leaderboard controllers.Mod.gamify GET /mod/leaderboard/:period controllers.Mod.gamifyPeriod(period: String) GET /mod/search controllers.Mod.search -# Wiki -GET /wiki controllers.Wiki.home -GET /wiki/:slug controllers.Wiki.show(slug: String) - # Bookmark POST /bookmark/$gameId<\w{8}> controllers.Bookmark.toggle(gameId: String) diff --git a/modules/api/src/main/Cli.scala b/modules/api/src/main/Cli.scala index 73cb518c25..c301aedfd8 100644 --- a/modules/api/src/main/Cli.scala +++ b/modules/api/src/main/Cli.scala @@ -36,7 +36,6 @@ private[api] final class Cli(bus: lila.common.Bus, renderer: ActorSelection) ext private def processors = lila.user.Env.current.cli.process orElse lila.security.Env.current.cli.process orElse - lila.wiki.Env.current.cli.process orElse lila.i18n.Env.current.cli.process orElse lila.game.Env.current.cli.process orElse lila.gameSearch.Env.current.cli.process orElse diff --git a/modules/wiki/src/main/Api.scala b/modules/wiki/src/main/Api.scala deleted file mode 100644 index 09ae21ab8c..0000000000 --- a/modules/wiki/src/main/Api.scala +++ /dev/null @@ -1,25 +0,0 @@ -package lila.wiki - -import Page.DefaultLang - -import lila.db.dsl._ - -private[wiki] final class Api(coll: Coll) { - - import Page.PageBSONHandler - - def show(slug: String, lang: String): Fu[Option[(Page, List[Page])]] = for { - page ← coll.uno[Page]($doc("slug" -> slug, "lang" -> lang)) orElse - coll.uno[Page]($doc("slug" -> slug, "lang" -> DefaultLang)) - pages ← coll.find($doc( - "lang" $in (lang, DefaultLang) - )).sort($sort asc "number").cursor[Page]().gather[List]() - } yield page map { _ -> makeMenu(pages) } - - private def makeMenu(pages: List[Page]): List[Page] = { - val (defaultPages, langPages) = pages partition (_.isDefaultLang) - defaultPages map { dPage => - langPages.find(_.number == dPage.number) | dPage - } - } -} diff --git a/modules/wiki/src/main/Env.scala b/modules/wiki/src/main/Env.scala deleted file mode 100644 index dabe44df9d..0000000000 --- a/modules/wiki/src/main/Env.scala +++ /dev/null @@ -1,35 +0,0 @@ -package lila.wiki - -import com.typesafe.config.Config - -import lila.db.dsl._ - -final class Env(config: Config, db: lila.db.Env) { - - private val CollectionPage = config getString "collection.page" - private val GitUrl = config getString "git.url" - private val MarkdownPath = config getString "markdown_path" - - private lazy val pageColl = db(CollectionPage) - - lazy val api = new Api(pageColl) - - private lazy val fetcher = new Fetch( - coll = pageColl, - gitUrl = GitUrl, - markdownPath = MarkdownPath) - - def cli = new lila.common.Cli { - def process = { - case "wiki" :: "fetch" :: Nil => - fetcher.apply inject "Fetched wiki from github" - } - } -} - -object Env { - - lazy val current = "wiki" boot new Env( - config = lila.common.PlayApp loadConfig "wiki", - db = lila.db.Env.current) -} diff --git a/modules/wiki/src/main/Fetch.scala b/modules/wiki/src/main/Fetch.scala deleted file mode 100644 index 9199a629ed..0000000000 --- a/modules/wiki/src/main/Fetch.scala +++ /dev/null @@ -1,57 +0,0 @@ -package lila.wiki - -import java.io.File -import scala.collection.JavaConversions._ -import scala.concurrent.Future - -import com.google.common.io.Files -import org.eclipse.jgit.api.Git -import org.eclipse.jgit.lib.Repository -import Page.DefaultLang - -import lila.db.dsl._ - -private[wiki] final class Fetch( - coll: Coll, - gitUrl: String, - markdownPath: String) { - - import Page.PageBSONHandler - - def apply: Funit = getFiles flatMap { files => - val (defaultPages, langPages) = files.map(filePage).flatten partition (_.isDefaultLang) - val newLangPages = (langPages map { page => - defaultPages find (_.number == page.number) map { default => - page.copy(slug = default.slug) - } - }).flatten - coll.remove($empty) >> (newLangPages ::: defaultPages).map { page => - coll.insert[Page](page) - }.sequenceFu.void - } - - private def filePage(file: File): Option[Page] = { - val name = """^(.+)\.md$""".r.replaceAllIn(file.getName, _ group 1) - if (name == "Home") None - else Page.make(name, toHtml(file)) - } - - private def getFiles: Fu[List[File]] = Future { - val dir = Files.createTempDir - dir.deleteOnExit - Git.cloneRepository - .setURI(gitUrl) - .setDirectory(dir) - .setBare(false) - .call - dir.listFiles.toList filter (_.isFile) sortBy (_.getName) - } - - private def toHtml(file: File): String = { - val command = s"""$markdownPath ${file.getAbsolutePath}""" - val output = new java.io.ByteArrayOutputStream - import scala.sys.process._ - (command #> output).! - new String(output.toByteArray, "UTF-8") - } -} diff --git a/modules/wiki/src/main/Page.scala b/modules/wiki/src/main/Page.scala deleted file mode 100644 index a4852db959..0000000000 --- a/modules/wiki/src/main/Page.scala +++ /dev/null @@ -1,49 +0,0 @@ -package lila.wiki - -import java.text.Normalizer -import java.util.regex.Matcher.quoteReplacement - -case class Page( - id: String, - slug: String, - number: Int, - lang: String, - title: String, - body: String) { - - def isDefaultLang = lang == Page.DefaultLang -} - -object Page { - - val DefaultLang = "en" - val NameRegex = """^(\w{2,3})_(\d+)_(.+)$""".r - - // name = en_1_Some Title - def make(name: String, body: String): Option[Page] = name match { - case NameRegex(lang, numberStr, title) => - parseIntOption(numberStr) map { number => - Page( - id = name, - number = number, - slug = slugify(title), - lang = lang, - title = title.replace("-", " "), - body = body) - } - case _ => none - } - - // does not lowercase - private def slugify(input: String) = { - val nowhitespace = input.replace(" ", "_") - val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD) - """[^\w-]""".r.replaceAllIn(normalized, "") - } - - private def dropNumber(input: String) = - """^\d+_(.+)$""".r.replaceAllIn(input, m => quoteReplacement(m group 1)) - - import lila.db.dsl.BSONJodaDateTimeHandler - implicit val PageBSONHandler = reactivemongo.bson.Macros.handler[Page] -} diff --git a/modules/wiki/src/main/package.scala b/modules/wiki/src/main/package.scala deleted file mode 100644 index 6f41d410b8..0000000000 --- a/modules/wiki/src/main/package.scala +++ /dev/null @@ -1,3 +0,0 @@ -package lila - -package object wiki extends PackageObject with WithPlay diff --git a/project/Build.scala b/project/Build.scala index 6dcb1aaad1..ce31bd37c1 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -52,7 +52,7 @@ object ApplicationBuild extends Build { )) lazy val modules = Seq( - chess, common, db, rating, user, security, wiki, hub, socket, + chess, common, db, rating, user, security, hub, socket, message, notifyModule, i18n, game, bookmark, search, gameSearch, timeline, forum, forumSearch, team, teamSearch, analyse, mod, site, round, lobby, setup, @@ -302,11 +302,6 @@ object ApplicationBuild extends Build { play.api, play.test, RM) ) - lazy val wiki = project("wiki", Seq(common, db)).settings( - libraryDependencies ++= provided( - play.api, RM, jgit, guava) - ) - lazy val report = project("report", Seq(common, db, user)).settings( libraryDependencies ++= provided( play.api, RM) diff --git a/public/stylesheets/wiki.css b/public/stylesheets/wiki.css deleted file mode 100644 index 1adcda7d47..0000000000 --- a/public/stylesheets/wiki.css +++ /dev/null @@ -1,42 +0,0 @@ -#wiki .body { - margin-top: 2em; - text-align: left; - min-height: 400px; -} -#wiki div.wiki_box { - text-align: center; - font-size: 1.1em; -} -#wiki div.wiki_box em { - font-style: italic; -} -#wiki div.wiki_box strong em { - font-weight: bold; -} - -#wiki div.wiki_box li { - list-style: disc inside; - margin-left: 1em; -} - -#wiki div.wiki_box p { - margin: 1em; -} - -#wiki div.wiki_box img { - max-width: 510px; -} - -#wiki h2 { - font-size: 1.5em; - line-height: 2em; -} - -div.sidebar { - margin-top: 30px; -} -div.sidebar a { - display: block; - font-size: 1.2em; - padding: 0.5em 0 0.5em 0; -}