Skip to content

Commit b1a2903

Browse files
committed
add README, fix redirection problem for page root
1 parent 0d22267 commit b1a2903

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This plugin provides *Project Pages* feature for
2+
[GitBucket](https://github.com/gitbucket/gitbucket).
3+
4+
Notes:
5+
6+
- view static web page in `gh-pages` branch under
7+
`/<user>/<project>/pages/`
8+
- no site generator will run (you must build & commit all html with
9+
assets if you use jekyll and the like)
10+
- you kinda have to add links to pages in README or repository
11+
description, there's no way to provide handy link automatically for
12+
now
13+
- I only test it in standalone mode
14+
15+
Releases:
16+
17+
- 0.1: initial release
18+

src/main/scala/gitbucket/plugin/pages/pages.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import org.eclipse.jgit.treewalk.TreeWalk
1212
import scala.language.implicitConversions
1313

1414
class PagesController
15-
extends ControllerBase
15+
extends PagesControllerBase
1616
with AccountService
1717
with RepositoryService
1818
with ReferrerAuthenticator
1919

20-
trait PagesControllerBase {
21-
self: ControllerBase with AccountService with RepositoryService with ReferrerAuthenticator =>
20+
trait PagesControllerBase extends ControllerBase {
21+
self: AccountService with RepositoryService with ReferrerAuthenticator =>
2222

2323
val PAGES_BRANCH = "gh-pages"
2424

@@ -34,7 +34,7 @@ trait PagesControllerBase {
3434
objectId match {
3535
case Some((path0, objId)) =>
3636
// redirect [owner/repo/pages/path] -> [owner/repo/pages/path/]
37-
if (path0 != path && path0.startsWith(path) && !path.endsWith("/")) {
37+
if (shouldRedirect(path, path0)) {
3838
redirect(s"/${repository.owner}/${repository.name}/pages/$path/")
3939
} else {
4040
JGitUtil.getObjectLoaderFromId(git, objId) { loader =>
@@ -54,6 +54,9 @@ trait PagesControllerBase {
5454
redirect(s"/${repository.owner}/${repository.name}/pages/")
5555
})
5656

57+
def shouldRedirect(path: String, path0: String) =
58+
!isRoot(path) && path0 != path && path0.startsWith(path) && !path.endsWith("/")
59+
5760
def getPathIndexObjectId(git: Git, path: String, revCommit: RevCommit) = {
5861
getPathObjectId0(git, path, revCommit)
5962
.orElse(getPathObjectId0(git, appendPath(path, "index.html"), revCommit))
@@ -65,11 +68,13 @@ trait PagesControllerBase {
6568
}
6669

6770
def appendPath(base: String, suffix: String): String = {
68-
if (base == "") suffix
71+
if (isRoot(base)) suffix
6972
else if (base.endsWith("/")) base + suffix
7073
else base + "/" + suffix
7174
}
7275

76+
def isRoot(path: String) = path == ""
77+
7378
// copy&paste from RepositoryViewerControllerBase
7479
private def getPathObjectId(git: Git, path: String, revCommit: RevCommit): Option[ObjectId] = {
7580
@scala.annotation.tailrec

0 commit comments

Comments
 (0)