mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 03:11:51 +01:00
wiki: finish pages
This commit is contained in:
parent
e42fcb033d
commit
5d1f5f32d0
4 changed files with 86 additions and 9 deletions
|
@ -548,6 +548,8 @@ wiki.last_commit_info = %s edited this page %s
|
|||
wiki.edit_page_button = Edit
|
||||
wiki.new_page_button = New Page
|
||||
wiki.page_already_exists = Wiki page with same name already exists.
|
||||
wiki.pages = Pages
|
||||
wiki.last_updated = Last updated %s
|
||||
|
||||
settings = Settings
|
||||
settings.options = Options
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,6 +7,7 @@ package repo
|
|||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogits/git-shell"
|
||||
|
||||
|
@ -20,11 +21,13 @@ const (
|
|||
WIKI_START base.TplName = "repo/wiki/start"
|
||||
WIKI_VIEW base.TplName = "repo/wiki/view"
|
||||
WIKI_NEW base.TplName = "repo/wiki/new"
|
||||
WIKI_PAGES base.TplName = "repo/wiki/pages"
|
||||
)
|
||||
|
||||
type PageMeta struct {
|
||||
Name string
|
||||
URL string
|
||||
Name string
|
||||
URL string
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
func renderWikiPage(ctx *middleware.Context, isViewPage bool) (*git.Repository, string) {
|
||||
|
@ -46,12 +49,14 @@ func renderWikiPage(ctx *middleware.Context, isViewPage bool) (*git.Repository,
|
|||
ctx.Handle(500, "ListEntries", err)
|
||||
return nil, ""
|
||||
}
|
||||
pages := make([]PageMeta, len(entries))
|
||||
pages := make([]PageMeta, 0, len(entries))
|
||||
for i := range entries {
|
||||
name := strings.TrimSuffix(entries[i].Name(), ".md")
|
||||
pages[i] = PageMeta{
|
||||
Name: name,
|
||||
URL: models.ToWikiPageURL(name),
|
||||
if entries[i].Type == git.OBJECT_BLOB {
|
||||
name := strings.TrimSuffix(entries[i].Name(), ".md")
|
||||
pages = append(pages, PageMeta{
|
||||
Name: name,
|
||||
URL: models.ToWikiPageURL(name),
|
||||
})
|
||||
}
|
||||
}
|
||||
ctx.Data["Pages"] = pages
|
||||
|
@ -123,7 +128,49 @@ func Wiki(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
func WikiPages(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.pages")
|
||||
ctx.Data["PageIsWiki"] = true
|
||||
|
||||
if !ctx.Repo.Repository.HasWiki() {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
||||
return
|
||||
}
|
||||
|
||||
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
|
||||
if err != nil {
|
||||
ctx.Handle(500, "OpenRepository", err)
|
||||
return
|
||||
}
|
||||
commit, err := wikiRepo.GetCommitOfBranch("master")
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
entries, err := commit.ListEntries()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "ListEntries", err)
|
||||
return
|
||||
}
|
||||
pages := make([]PageMeta, 0, len(entries))
|
||||
for i := range entries {
|
||||
if entries[i].Type == git.OBJECT_BLOB {
|
||||
c, err := wikiRepo.GetCommitByPath(entries[i].Name())
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
name := strings.TrimSuffix(entries[i].Name(), ".md")
|
||||
pages = append(pages, PageMeta{
|
||||
Name: name,
|
||||
URL: models.ToWikiPageURL(name),
|
||||
Updated: c.Author.When,
|
||||
})
|
||||
}
|
||||
}
|
||||
ctx.Data["Pages"] = pages
|
||||
|
||||
ctx.HTML(200, WIKI_PAGES)
|
||||
}
|
||||
|
||||
func NewWiki(ctx *middleware.Context) {
|
||||
|
|
28
templates/repo/wiki/pages.tmpl
Normal file
28
templates/repo/wiki/pages.tmpl
Normal file
|
@ -0,0 +1,28 @@
|
|||
{{template "base/head" .}}
|
||||
<div class="repository wiki pages">
|
||||
{{template "repo/header" .}}
|
||||
<div class="ui container">
|
||||
{{template "repo/sidebar" .}}
|
||||
<div class="ui header">
|
||||
{{.i18n.Tr "repo.wiki.pages"}}
|
||||
<div class="ui right">
|
||||
<a class="ui green small button" href="{{.RepoLink}}/wiki/_new">{{.i18n.Tr "repo.wiki.new_page_button"}}</a>
|
||||
</div>
|
||||
</div>
|
||||
<table class="ui table">
|
||||
<tbody>
|
||||
{{range .Pages}}
|
||||
<tr>
|
||||
<td>
|
||||
<i class="icon octicon octicon-file-text"></i>
|
||||
<a href="{{$.RepoLink}}/wiki/{{.URL}}">{{.Name}}</a>
|
||||
</td>
|
||||
{{$timeSince := TimeSince .Updated $.Lang}}
|
||||
<td class="text right grey">{{$.i18n.Tr "repo.wiki.last_updated" $timeSince | Safe}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
Loading…
Reference in a new issue