remove wiki module

This commit is contained in:
Thibault Duplessis 2016-06-08 13:42:51 +02:00
parent 946c6923fb
commit f1a0ee4d4d
15 changed files with 1 additions and 285 deletions

View file

@ -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

View file

@ -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)
}
}
}

View file

@ -1,18 +0,0 @@
@(title: String, pages: List[lila.wiki.Page])(body: Html)(implicit ctx: Context)
@moreCss = {
@cssTag("wiki.css")
}
@side = {
<div class="sidebar">
@wiki.menu(pages)
</div>
}
@base.layout(
title = title,
moreCss = moreCss,
side = side.some) {
<div id="wiki">@body</div>
}

View file

@ -1,9 +0,0 @@
@(pages: List[lila.wiki.Page])(implicit ctx: Context)
<ul>
@pages.map { page =>
<li>
<a href="@routes.Wiki.show(page.slug)">@page.title</a>
</li>
}
</ul>

View file

@ -1,11 +0,0 @@
@(page: lila.wiki.Page, pages: List[lila.wiki.Page])(implicit ctx: Context)
@wiki.layout(pages = pages, title = page.title) {
<div class="content_box small_box wiki_box">
<h1 class="lichess_title">@page.title</h1>
<div class="body">
@Html(page.body)
</div>
</div>
}

View file

@ -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
}

View file

@ -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)

View file

@ -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

View file

@ -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
}
}
}

View file

@ -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)
}

View file

@ -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")
}
}

View file

@ -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]
}

View file

@ -1,3 +0,0 @@
package lila
package object wiki extends PackageObject with WithPlay

View file

@ -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)

View file

@ -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;
}