Skip to content

Commit

Permalink
feat(gnoweb): added link to readme if present (#2461)
Browse files Browse the repository at this point in the history
Added a link to the `README.md` file of the realm if it exists 

![image](https://github.com/gnolang/gno/assets/68433935/8259ebd7-9a15-4647-9280-80618f870fcc)
To allow for quicker access while browsing gnoweb

This should solve #2458

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Lee ByeongJun <[email protected]>
Co-authored-by: Guilhem Fanton <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2024
1 parent 0ef28e8 commit bbcb2f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gno.land/pkg/gnoweb/gnoweb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gnoweb

import (
"bytes"
"embed"
"encoding/json"
"errors"
Expand Down Expand Up @@ -335,6 +336,15 @@ func handleRealmRender(logger *slog.Logger, app gotuna.App, cfg *Config, w http.
return
}
}

dirdata := []byte(rlmpath)
dirres, err := makeRequest(logger, cfg, qFileStr, dirdata)
if err != nil {
writeError(logger, w, err)
return
}
hasReadme := bytes.Contains(append(dirres.Data, '\n'), []byte("README.md\n"))

// linkify querystr.
queryParts := strings.Split(querystr, "/")
pathLinks := []pathLink{}
Expand All @@ -354,6 +364,7 @@ func handleRealmRender(logger *slog.Logger, app gotuna.App, cfg *Config, w http.
tmpl.Set("PathLinks", pathLinks)
tmpl.Set("Contents", string(res.Data))
tmpl.Set("Config", cfg)
tmpl.Set("HasReadme", hasReadme)
tmpl.Render(w, r, "realm_render.html", "funcs.html")
}

Expand Down
3 changes: 3 additions & 0 deletions gno.land/pkg/gnoweb/views/realm_render.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
{{- end -}}
</span>
<span id="realm_links">
{{ if .Data.HasReadme }}
<a href="/r/{{ .Data.RealmName }}/README.md">[readme]</a>
{{ end }}
<a href="/r/{{ .Data.RealmName }}/">[source]</a>
<a href="/r/{{ .Data.RealmName }}?help">[help]</a>
</span>
Expand Down

0 comments on commit bbcb2f6

Please sign in to comment.