package about import ( "io" "net/http" "os" "github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown/html" "github.com/gomarkdown/markdown/parser" "git.gabrielgio.me/cerrado/templates" ) type ( AboutHandler struct { readmePath string } configurationRepository interface { GetRootReadme() string } ) func NewAboutHandler(configRepo configurationRepository) *AboutHandler { return &AboutHandler{configRepo.GetRootReadme()} } func (g *AboutHandler) About(w http.ResponseWriter, _ *http.Request) error { f, err := os.Open(g.readmePath) if err != nil { return err } bs, err := io.ReadAll(f) if err != nil { return err } extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock p := parser.NewWithExtensions(extensions) doc := p.Parse(bs) htmlFlags := html.CommonFlags | html.HrefTargetBlank opts := html.RendererOptions{Flags: htmlFlags} renderer := html.NewRenderer(opts) bs = markdown.Render(doc, renderer) gitList := &templates.AboutPage{ Body: bs, } templates.WritePageTemplate(w, gitList) return nil }