flag
This commit is contained in:
parent
b37b5571e1
commit
df7d6536e9
3 changed files with 17 additions and 3 deletions
|
|
@ -109,6 +109,9 @@ An appendix for tooltips and links is added to PNG exports since they are not in
|
||||||
.Ns .
|
.Ns .
|
||||||
.It Fl d , -debug
|
.It Fl d , -debug
|
||||||
Print debug logs.
|
Print debug logs.
|
||||||
|
.It Fl -img-cache Ar true
|
||||||
|
In watch mode, images used in icons are cached for subsequent compilations. This should be disabled if images might change
|
||||||
|
.Ns .
|
||||||
.It Fl h , -help
|
.It Fl h , -help
|
||||||
Print usage information and exit.
|
Print usage information and exit.
|
||||||
.It Fl v , -version
|
.It Fl v , -version
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,10 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
imgCacheFlag, err := ms.Opts.Bool("IMG_CACHE", "img-cache", "", true, "in watch mode, images used in icons are cached for subsequent compilations. This should be disabled if images might change.")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
layoutFlag := ms.Opts.String("D2_LAYOUT", "layout", "l", "dagre", `the layout engine used`)
|
layoutFlag := ms.Opts.String("D2_LAYOUT", "layout", "l", "dagre", `the layout engine used`)
|
||||||
themeFlag, err := ms.Opts.Int64("D2_THEME", "theme", "t", 0, "the diagram theme ID")
|
themeFlag, err := ms.Opts.Int64("D2_THEME", "theme", "t", 0, "the diagram theme ID")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -150,6 +154,9 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
ms.Env.Setenv("DEBUG", "1")
|
ms.Env.Setenv("DEBUG", "1")
|
||||||
}
|
}
|
||||||
|
if *imgCacheFlag {
|
||||||
|
ms.Env.Setenv("IMG_CACHE", "1")
|
||||||
|
}
|
||||||
if *browserFlag != "" {
|
if *browserFlag != "" {
|
||||||
ms.Env.Setenv("BROWSER", *browserFlag)
|
ms.Env.Setenv("BROWSER", *browserFlag)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,10 @@ func runWorkers(ctx context.Context, ms *xmain.State, svg []byte, imgs [][][]byt
|
||||||
}
|
}
|
||||||
|
|
||||||
func worker(ctx context.Context, ms *xmain.State, href []byte, isRemote bool) ([]byte, error) {
|
func worker(ctx context.Context, ms *xmain.State, href []byte, isRemote bool) ([]byte, error) {
|
||||||
if hit, ok := imgCache.Load(string(href)); ok {
|
if ms.Env.Getenv("IMG_CACHE") == "1" {
|
||||||
return hit.([]byte), nil
|
if hit, ok := imgCache.Load(string(href)); ok {
|
||||||
|
return hit.([]byte), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var buf []byte
|
var buf []byte
|
||||||
var mimeType string
|
var mimeType string
|
||||||
|
|
@ -175,7 +177,9 @@ func worker(ctx context.Context, ms *xmain.State, href []byte, isRemote bool) ([
|
||||||
b64 := base64.StdEncoding.EncodeToString(buf)
|
b64 := base64.StdEncoding.EncodeToString(buf)
|
||||||
|
|
||||||
out := []byte(fmt.Sprintf(`<image href="data:%s;base64,%s"`, mimeType, b64))
|
out := []byte(fmt.Sprintf(`<image href="data:%s;base64,%s"`, mimeType, b64))
|
||||||
imgCache.Store(string(href), out)
|
if ms.Env.Getenv("IMG_CACHE") == "1" {
|
||||||
|
imgCache.Store(string(href), out)
|
||||||
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue