- update deps
- add open-browser option
- allow to change port and host
This commit is contained in:
Peter 2021-12-22 23:05:59 +01:00
parent 7d3d3a5abf
commit 6be2b5aeb5
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
4 changed files with 52 additions and 9 deletions

View file

@ -2,9 +2,9 @@ version: '3'
vars:
DEBUG_PORT: 2345
REVEALJS_VERSION: 4.1.2
REVEALJS_VERSION: 4.2.1
HIGHLIGHTJS_VERSION: 11.3.1
MERMAID_VERSION: 8.13.4
MERMAID_VERSION: 8.13.6
BINARY_NAME: goveal
OUT_DIR: ./out
GO_BUILD_ARGS: -ldflags="-w -s"
@ -98,7 +98,7 @@ tasks:
- curl -L -o ./assets/reveal/plugin/mouse-pointer/mouse-pointer.js https://raw.githubusercontent.com/caiofcm/plugin-revealjs-mouse-pointer/master/mouse-pointer.js
- rm -f ./assets/reveal/plugin/menu/{bower.json,CONTRIBUTING.md,LICENSE,package.json,README.md,.gitignore,gulpfile.js,package-lock.json}
- curl -L https://github.com/highlightjs/highlight.js/archive/{{ .HIGHLIGHTJS_VERSION }}.tar.gz | tar -xvz --strip-components=3 -C ./assets/reveal/plugin/highlight --wildcards "*.css" highlight.js-{{ .HIGHLIGHTJS_VERSION }}/src/styles/
- curl -L https://github.com/mermaid-js/mermaid/archive/refs/tags/{{ .MERMAID_VERSION }}.tar.gz | tar -xvz -C ./assets/mermaid/ mermaid-{{ .MERMAID_VERSION }}/dist --strip-components=2
- curl -L https://registry.npmjs.org/mermaid/-/mermaid-{{ .MERMAID_VERSION }}.tgz | tar -xvz -C ./assets/mermaid/ package/dist --strip-components=2
go-get-tool:
vars:

View file

@ -2,10 +2,13 @@ package main
import (
"encoding/hex"
"fmt"
"hash/fnv"
"net/http"
"os/exec"
"path"
"path/filepath"
"runtime"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html"
@ -20,10 +23,18 @@ import (
"github.com/baez90/goveal/web"
)
const (
defaultListeningPort uint16 = 3000
defaultHost = "127.0.0.1"
)
var (
workingDir string
cfg *config.Components
serveCmd = &cobra.Command{
workingDir string
cfg *config.Components
host string
port uint16
openBrowser bool
serveCmd = &cobra.Command{
Use: "serve",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) (err error) {
@ -47,6 +58,10 @@ var (
h := fnv.New32a()
return hex.EncodeToString(h.Sum([]byte(path.Base(fileName))))
}),
AppName: "goveal",
GETOnly: true,
DisableStartupMessage: true,
StreamRequestBody: true,
})
hub := events.NewEventHub(
wdfs,
@ -63,11 +78,38 @@ var (
return err
}
return app.Listen(":3000")
if openBrowser {
log.Info("Opening browser...")
openBrowserInBackground(fmt.Sprintf("http://%s:%d", host, port))
}
log.Infof("Listening on %s:%d", host, port)
return app.Listen(fmt.Sprintf("%s:%d", host, port))
},
}
)
func init() {
serveCmd.Flags().Uint16Var(&port, "port", defaultListeningPort, "port to listen on")
serveCmd.Flags().StringVar(&host, "host", defaultHost, "address/hostname to bind on")
serveCmd.Flags().BoolVar(&openBrowser, "open-browser", true, "Open browser when starting")
rootCmd.AddCommand(serveCmd)
}
func openBrowserInBackground(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Warn(err)
}
}

View file

@ -4,6 +4,8 @@ var defaults = map[string]interface{}{
"mermaid.theme": "forest",
"theme": "beige",
"codeTheme": "monokai",
"verticalSeparator": `\*\*\*`,
"horizontalSeparator": `---`,
"transition": TransitionNone,
"controlsLayout": ControlsLayoutEdges,
"controls": true,

View file

@ -91,7 +91,7 @@ for (var j = 0; j < i; j++) {
### Mermaid
```mermaid
%%{init: {'theme': 'dark'}}%%
%%{init: {'theme': 'neutral'}}%%
flowchart LR
a --> b & c--> d
```
@ -101,7 +101,6 @@ flowchart LR
### The inadequacy of a non-highlighted being
{line-numbers="1-2|3|4"}
```js
let a = 1;
let b = 2;