Cleanup
- update deps - add open-browser option - allow to change port and host
This commit is contained in:
parent
7d3d3a5abf
commit
6be2b5aeb5
4 changed files with 52 additions and 9 deletions
|
@ -2,9 +2,9 @@ version: '3'
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
DEBUG_PORT: 2345
|
DEBUG_PORT: 2345
|
||||||
REVEALJS_VERSION: 4.1.2
|
REVEALJS_VERSION: 4.2.1
|
||||||
HIGHLIGHTJS_VERSION: 11.3.1
|
HIGHLIGHTJS_VERSION: 11.3.1
|
||||||
MERMAID_VERSION: 8.13.4
|
MERMAID_VERSION: 8.13.6
|
||||||
BINARY_NAME: goveal
|
BINARY_NAME: goveal
|
||||||
OUT_DIR: ./out
|
OUT_DIR: ./out
|
||||||
GO_BUILD_ARGS: -ldflags="-w -s"
|
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
|
- 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}
|
- 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/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:
|
go-get-tool:
|
||||||
vars:
|
vars:
|
||||||
|
|
|
@ -2,10 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/template/html"
|
"github.com/gofiber/template/html"
|
||||||
|
@ -20,9 +23,17 @@ import (
|
||||||
"github.com/baez90/goveal/web"
|
"github.com/baez90/goveal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultListeningPort uint16 = 3000
|
||||||
|
defaultHost = "127.0.0.1"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
workingDir string
|
workingDir string
|
||||||
cfg *config.Components
|
cfg *config.Components
|
||||||
|
host string
|
||||||
|
port uint16
|
||||||
|
openBrowser bool
|
||||||
serveCmd = &cobra.Command{
|
serveCmd = &cobra.Command{
|
||||||
Use: "serve",
|
Use: "serve",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
@ -47,6 +58,10 @@ var (
|
||||||
h := fnv.New32a()
|
h := fnv.New32a()
|
||||||
return hex.EncodeToString(h.Sum([]byte(path.Base(fileName))))
|
return hex.EncodeToString(h.Sum([]byte(path.Base(fileName))))
|
||||||
}),
|
}),
|
||||||
|
AppName: "goveal",
|
||||||
|
GETOnly: true,
|
||||||
|
DisableStartupMessage: true,
|
||||||
|
StreamRequestBody: true,
|
||||||
})
|
})
|
||||||
hub := events.NewEventHub(
|
hub := events.NewEventHub(
|
||||||
wdfs,
|
wdfs,
|
||||||
|
@ -63,11 +78,38 @@ var (
|
||||||
return err
|
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() {
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ var defaults = map[string]interface{}{
|
||||||
"mermaid.theme": "forest",
|
"mermaid.theme": "forest",
|
||||||
"theme": "beige",
|
"theme": "beige",
|
||||||
"codeTheme": "monokai",
|
"codeTheme": "monokai",
|
||||||
|
"verticalSeparator": `\*\*\*`,
|
||||||
|
"horizontalSeparator": `---`,
|
||||||
"transition": TransitionNone,
|
"transition": TransitionNone,
|
||||||
"controlsLayout": ControlsLayoutEdges,
|
"controlsLayout": ControlsLayoutEdges,
|
||||||
"controls": true,
|
"controls": true,
|
||||||
|
|
|
@ -91,7 +91,7 @@ for (var j = 0; j < i; j++) {
|
||||||
### Mermaid
|
### Mermaid
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
%%{init: {'theme': 'dark'}}%%
|
%%{init: {'theme': 'neutral'}}%%
|
||||||
flowchart LR
|
flowchart LR
|
||||||
a --> b & c--> d
|
a --> b & c--> d
|
||||||
```
|
```
|
||||||
|
@ -101,7 +101,6 @@ flowchart LR
|
||||||
### The inadequacy of a non-highlighted being
|
### The inadequacy of a non-highlighted being
|
||||||
|
|
||||||
{line-numbers="1-2|3|4"}
|
{line-numbers="1-2|3|4"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
let a = 1;
|
let a = 1;
|
||||||
let b = 2;
|
let b = 2;
|
||||||
|
|
Loading…
Reference in a new issue