diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-15 19:07:14 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-15 19:07:14 +0200 |
commit | ce5185f551b707fe8dd8db8b5cbffd46e96cacc0 (patch) | |
tree | b4b83a117a7c479589cfce022011e725e24529e8 /pkg/handler | |
parent | b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5 (diff) | |
download | cerrado-ce5185f551b707fe8dd8db8b5cbffd46e96cacc0.tar.gz cerrado-ce5185f551b707fe8dd8db8b5cbffd46e96cacc0.tar.bz2 cerrado-ce5185f551b707fe8dd8db8b5cbffd46e96cacc0.zip |
feat: Add per repository about page
Diffstat (limited to 'pkg/handler')
-rw-r--r-- | pkg/handler/git/handler.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index 899f61e..25505ba 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -33,6 +33,7 @@ type ( GetHead(name string) (*plumbing.Reference, error) GetTree(name, ref, path string) (*object.Tree, error) GetFileContent(name, ref, path string) (string, error) + GetAbout(name string) (string, error) ListTags(name string) ([]*plumbing.Reference, error) ListBranches(name string) ([]*plumbing.Reference, error) } @@ -126,10 +127,28 @@ func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) error { if err != nil { return err } + + file, err := g.gitService.GetAbout(name) + if err != nil { + return err + } + + extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock + p := parser.NewWithExtensions(extensions) + doc := p.Parse([]byte(file)) + + htmlFlag := markdownhtml.CommonFlags | markdownhtml.HrefTargetBlank + opts := markdownhtml.RendererOptions{Flags: htmlFlag} + renderer := markdownhtml.NewRenderer(opts) + + bs := markdown.Render(doc, renderer) + gitList := &templates.GitItemPage{ - Name: name, - Ref: ref.Name().Short(), - GitItemBase: &templates.GitItemAboutPage{}, + Name: name, + Ref: ref.Name().Short(), + GitItemBase: &templates.GitItemAboutPage{ + About: bs, + }, } templates.WritePageTemplate(w, gitList) return nil |