From bbcb2f6eb6f03f7d91229aa01ab652b663431394 Mon Sep 17 00:00:00 2001 From: Alex Gherasie <68433935+agherasie@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:14:51 +0300 Subject: [PATCH] feat(gnoweb): added link to readme if present (#2461) 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 https://github.com/gnolang/gno/issues/2458
Contributors' checklist... - [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).
--------- Co-authored-by: Lee ByeongJun Co-authored-by: Guilhem Fanton <8671905+gfanton@users.noreply.github.com> --- gno.land/pkg/gnoweb/gnoweb.go | 11 +++++++++++ gno.land/pkg/gnoweb/views/realm_render.html | 3 +++ 2 files changed, 14 insertions(+) diff --git a/gno.land/pkg/gnoweb/gnoweb.go b/gno.land/pkg/gnoweb/gnoweb.go index b997de7840d..1cd0d664193 100644 --- a/gno.land/pkg/gnoweb/gnoweb.go +++ b/gno.land/pkg/gnoweb/gnoweb.go @@ -1,6 +1,7 @@ package gnoweb import ( + "bytes" "embed" "encoding/json" "errors" @@ -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{} @@ -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") } diff --git a/gno.land/pkg/gnoweb/views/realm_render.html b/gno.land/pkg/gnoweb/views/realm_render.html index 9a4507777a6..924ef2b414f 100644 --- a/gno.land/pkg/gnoweb/views/realm_render.html +++ b/gno.land/pkg/gnoweb/views/realm_render.html @@ -16,6 +16,9 @@ {{- end -}} + {{ if .Data.HasReadme }} + [readme] + {{ end }} [source] [help]