Skip to content

Commit

Permalink
chore: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiscolin committed Jan 21, 2025
1 parent dce1299 commit bbb2cc7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gno.land/pkg/gnoweb/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ func (h *WebHandler) Get(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(status)

// NOTE: HTML escaping should have already been done by markdown rendering package
indexData.Body = template.HTML(body.String()) //nolint:gosec

// Render the final page with the rendered body
if err = components.RenderIndexComponent(w, indexData); err != nil {
h.Logger.Error("failed to render index component", "err", err)
}
Expand Down Expand Up @@ -151,18 +153,22 @@ func (h *WebHandler) renderPage(body *bytes.Buffer, r *http.Request, indexData *

// GetPackagePage handles package pages.
func (h *WebHandler) GetPackagePage(w io.Writer, gnourl *GnoURL) (int, PageData, error) {
// Handle Help page
if gnourl.WebQuery.Has("help") {
return h.GetHelpPage(w, gnourl)
}

// Handle Source page
if gnourl.WebQuery.Has("source") || gnourl.IsFile() {
return h.GetSourcePage(w, gnourl)
}

// Handle Source page
if gnourl.IsDir() || gnourl.IsPure() {
return h.GetDirectoryPage(w, gnourl)
}

// Ultimately render realm content
return h.renderRealmContent(w, gnourl)
}

Expand All @@ -186,6 +192,9 @@ func (h *WebHandler) renderRealmContent(w io.Writer, gnourl *GnoURL) (int, PageD
TocItems: &components.RealmTOCData{
Items: meta.Toc.Items,
},

// NOTE: `RenderRealm` should ensure that HTML content is
// sanitized before rendering
Content: template.HTML(content.String()), //nolint:gosec
})
if err != nil {
Expand Down Expand Up @@ -268,14 +277,14 @@ func (h *WebHandler) GetSourcePage(w io.Writer, gnourl *GnoURL) (int, PageData,
}

var fileName string
if gnourl.IsFile() {
if gnourl.IsFile() { // check path file from path first
fileName = gnourl.File
} else if file := gnourl.WebQuery.Get("file"); file != "" {
fileName = file
}

if fileName == "" {
fileName = files[0]
fileName = files[0] // fallback on the first file if
}

var source bytes.Buffer
Expand Down

0 comments on commit bbb2cc7

Please sign in to comment.