mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Implementing Wiki part.
This commit is contained in:
@@ -8,7 +8,9 @@ class WikiController extends ControllerBase {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
html.wiki(WikiUtil.getPage(owner, repository, "Home"), JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||
html.wiki("Home",
|
||||
WikiUtil.getPage(owner, repository, "Home"),
|
||||
JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,8 +13,10 @@ object WikiUtil {
|
||||
*
|
||||
* @param name the page name
|
||||
* @param content the page content
|
||||
* @param committer the last committer
|
||||
* @param time the last modified time
|
||||
*/
|
||||
case class WikiPageInfo(name: String, content: String)
|
||||
case class WikiPageInfo(name: String, content: String, committer: String, time: Date)
|
||||
|
||||
/**
|
||||
* The model for wiki page history.
|
||||
@@ -44,6 +46,7 @@ object WikiUtil {
|
||||
if(!dir.exists){
|
||||
val repo = new RepositoryBuilder().setGitDir(dir).setBare.build
|
||||
repo.create
|
||||
savePage(owner, repository, "Home", "Welcome to the %s wiki!!".format(repository), owner, "Initial Commit")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +57,8 @@ object WikiUtil {
|
||||
createWikiRepository(owner, repository)
|
||||
val git = Git.open(getWikiRepositoryDir(owner, repository))
|
||||
try {
|
||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName).map { file =>
|
||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"))
|
||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"), file.committer, file.time)
|
||||
}
|
||||
} catch {
|
||||
// TODO no commit, but it should not judge by exception.
|
||||
|
||||
@@ -18,6 +18,12 @@ object helpers {
|
||||
def format(value: String): twirl.api.Html = twirl.api.Html(
|
||||
value.replaceAll(" ", " ").replaceAll("\t", " ").replaceAll("\n", "<br>"))
|
||||
|
||||
def markdown(value: String): twirl.api.Html = {
|
||||
import org.pegdown._
|
||||
val html = new PegDownProcessor().markdownToHtml(value)
|
||||
twirl.api.Html(html)
|
||||
}
|
||||
|
||||
/**
|
||||
* Cut the given string by specified length.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user