Skip to content

Commit

Permalink
feat(gnoweb): rework & Implement new gnoweb design (#3195)
Browse files Browse the repository at this point in the history
address #3191

Reworking the `gnoweb` package:  
-  Implement `gnoweb` new interface design(cc @alexiscolin).  
- Move Markdown rendering to the server to enhance speed and security.
This change also simplifies the implementation of new components, making
it more standardized as a Go library.
- Aim to keep dependencies minimal, using only `goldmark` for Markdown
and `chroma` for code highlighting, with almost no (in)direct
dependencies.
-  Transition to Tailwind for simplicity and maintainability.  
-  Retain all features from the previous `gnoweb` iteration.  

### Preview
- Home
![Screenshot 2024-11-25 at 19 39
54](https://github.com/user-attachments/assets/7a4b99d9-c223-49e7-9ae6-6561be85d1d3)

- Source
![Screenshot 2024-11-25 at 19 41
25](https://github.com/user-attachments/assets/cb650eca-70d6-48f5-9c25-d247aecf45c3)

- Docs
![Screenshot 2024-11-25 at 19 45
16](https://github.com/user-attachments/assets/1d79bb25-e431-42db-bc0e-0fdefca85339)


### TODO: 
- [x] port and adapt all previous tests to ensure compatibility (it
should not take too long)
- [x] Some cleanup and restructuring + linting.

---------

Signed-off-by: gfanton <[email protected]>
Co-authored-by: alexiscolin <[email protected]>
Co-authored-by: Morgan Bazalgette <[email protected]>
  • Loading branch information
3 people authored and albttx committed Jan 10, 2025
1 parent bb2a189 commit 179face
Show file tree
Hide file tree
Showing 125 changed files with 4,696 additions and 4,575 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/gnoland.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,25 @@ jobs:
tests-extra-args: "-coverpkg=github.com/gnolang/gno/gno.land/..."
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}

gnoweb_generate:
strategy:
fail-fast: false
matrix:
go-version: ["1.22.x"]
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: actions/setup-node@v4
with:
node-version: lts/Jod # (22.x) https://github.com/nodejs/Release
- uses: actions/checkout@v4
- run: |
make -C gno.land/pkg/gnoweb fclean generate
# Check if there are changes after running generate.gnoweb
git diff --exit-code || \
(echo "\`gnoweb generate\` out of date, please run \`make gnoweb.generate\` within './gno.land'" && exit 1)
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ ENTRYPOINT ["/usr/bin/gno"]
# gnoweb
FROM base AS gnoweb
COPY --from=build-gno /gnoroot/build/gnoweb /usr/bin/gnoweb
COPY --from=build-gno /opt/gno/src/gno.land/cmd/gnoweb /opt/gno/src/gnoweb
EXPOSE 8888
ENTRYPOINT ["/usr/bin/gnoweb"]

Expand Down
48 changes: 31 additions & 17 deletions contribs/gnodev/cmd/gnodev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ type devCfg struct {
txsFile string

// Web Configuration
noWeb bool
webHTML bool
webListenerAddr string
webRemoteHelperAddr string
webWithHTML bool

// Node Configuration
minimal bool
Expand Down Expand Up @@ -123,6 +124,20 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
"gno root directory",
)

fs.BoolVar(
&c.noWeb,
"no-web",
defaultDevOptions.noWeb,
"disable gnoweb",
)

fs.BoolVar(
&c.webHTML,
"web-html",
defaultDevOptions.webHTML,
"gnoweb: enable unsafe HTML parsing in markdown rendering",
)

fs.StringVar(
&c.webListenerAddr,
"web-listener",
Expand All @@ -137,13 +152,6 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
"gnoweb: web server help page's remote addr (default to <node-rpc-listener>)",
)

fs.BoolVar(
&c.webWithHTML,
"web-with-html",
defaultDevOptions.webWithHTML,
"gnoweb: enable HTML parsing in markdown rendering",
)

fs.StringVar(
&c.nodeRPCListenerAddr,
"node-rpc-listener",
Expand Down Expand Up @@ -323,7 +331,10 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) {
defer server.Close()

// Setup gnoweb
webhandler := setupGnoWebServer(logger.WithGroup(WebLogName), cfg, devNode)
webhandler, err := setupGnoWebServer(logger.WithGroup(WebLogName), cfg, devNode)
if err != nil {
return fmt.Errorf("unable to setup gnoweb server: %w", err)
}

// Setup unsafe APIs if enabled
if cfg.unsafeAPI {
Expand Down Expand Up @@ -351,14 +362,17 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) {
mux.Handle("/", webhandler)
}

go func() {
err := server.ListenAndServe()
cancel(err)
}()
// Serve gnoweb
if !cfg.noWeb {
go func() {
err := server.ListenAndServe()
cancel(err)
}()

logger.WithGroup(WebLogName).
Info("gnoweb started",
"lisn", fmt.Sprintf("http://%s", server.Addr))
logger.WithGroup(WebLogName).
Info("gnoweb started",
"lisn", fmt.Sprintf("http://%s", server.Addr))
}

watcher, err := watcher.NewPackageWatcher(loggerEvents, emitterServer)
if err != nil {
Expand All @@ -377,7 +391,7 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) {
return runEventLoop(ctx, logger, book, rt, devNode, watcher)
}

var helper string = `For more in-depth documentation, visit the GNO Tooling CLI documentation:
var helper string = `For more in-depth documentation, visit the GNO Tooling CLI documentation:
https://docs.gno.land/gno-tooling/cli/gno-tooling-gnodev
P Previous TX - Go to the previous tx
Expand Down
29 changes: 18 additions & 11 deletions contribs/gnodev/cmd/gnodev/setup_web.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log/slog"
"net/http"

Expand All @@ -9,19 +10,25 @@ import (
)

// setupGnowebServer initializes and starts the Gnoweb server.
func setupGnoWebServer(logger *slog.Logger, cfg *devCfg, dnode *gnodev.Node) http.Handler {
webConfig := gnoweb.NewDefaultConfig()
func setupGnoWebServer(logger *slog.Logger, cfg *devCfg, dnode *gnodev.Node) (http.Handler, error) {
if cfg.noWeb {
return http.HandlerFunc(http.NotFound), nil
}

remote := dnode.GetRemoteAddress()

webConfig.HelpChainID = cfg.chainId
webConfig.RemoteAddr = dnode.GetRemoteAddress()
webConfig.HelpRemote = cfg.webRemoteHelperAddr
webConfig.WithHTML = cfg.webWithHTML
appcfg := gnoweb.NewDefaultAppConfig()
appcfg.UnsafeHTML = cfg.webHTML
appcfg.NodeRemote = remote
appcfg.ChainID = cfg.chainId
if cfg.webRemoteHelperAddr != "" {
appcfg.RemoteHelp = cfg.webRemoteHelperAddr
}

// If `HelpRemote` is empty default it to `RemoteAddr`
if webConfig.HelpRemote == "" {
webConfig.HelpRemote = webConfig.RemoteAddr
router, err := gnoweb.NewRouter(logger, appcfg)
if err != nil {
return nil, fmt.Errorf("unable to create router app: %w", err)
}

app := gnoweb.MakeApp(logger, webConfig)
return app.Router
return router, nil
}
10 changes: 3 additions & 7 deletions contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (

require (
dario.cat/mergo v1.0.1 // indirect
github.com/alecthomas/chroma/v2 v2.8.0 // indirect
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand All @@ -48,7 +48,7 @@ require (
github.com/creack/pty v1.1.21 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand All @@ -57,10 +57,6 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/gotuna/gotuna v0.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand All @@ -81,7 +77,7 @@ require (
github.com/rs/xid v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark v1.7.2 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
Expand Down
28 changes: 10 additions & 18 deletions contribs/gnodev/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions gno.land/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ install.gnoland:; go install ./cmd/gnoland
install.gnoweb:; go install ./cmd/gnoweb
install.gnokey:; go install ./cmd/gnokey

.PHONY: dev.gnoweb generate.gnoweb
dev.gnoweb:
make -C ./pkg/gnoweb dev
generate.gnoweb:
make -C ./pkg/gnoweb generate

.PHONY: fclean
fclean: clean
rm -rf gnoland-data genesis.json
Expand Down
20 changes: 0 additions & 20 deletions gno.land/cmd/gnoweb/CONTRIBUTING.md

This file was deleted.

10 changes: 1 addition & 9 deletions gno.land/cmd/gnoweb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@

The gno.land web interface.

Live demo: https://gno.land/

## Install `gnoweb`

Install and run a local [`gnoland`](../gnoland) instance first.

$> git clone [email protected]:gnolang/gno.git
$> cd ./gno/gno.land
$> make install.gnoweb
Live demo: [https://gno.land/](https://gno.land/) or using `gnodev` from the directory [gnodev](../../../contribs/gnodev).
Loading

0 comments on commit 179face

Please sign in to comment.