minor refactor
This commit is contained in:
parent
e4bbc26959
commit
4b2041f759
1 changed files with 10 additions and 14 deletions
|
|
@ -360,15 +360,12 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, rende
|
||||||
ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(outputPath), dur)
|
ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(outputPath), dur)
|
||||||
return pdf, true, nil
|
return pdf, true, nil
|
||||||
case ".pptx":
|
case ".pptx":
|
||||||
ext := filepath.Ext(outputPath)
|
|
||||||
trimmedPath := strings.TrimSuffix(outputPath, ext)
|
|
||||||
splitPath := strings.Split(trimmedPath, "/")
|
|
||||||
rootName := splitPath[len(splitPath)-1]
|
|
||||||
var username string
|
var username string
|
||||||
if user, err := user.Current(); err == nil {
|
if user, err := user.Current(); err == nil {
|
||||||
username = user.Username
|
username = user.Username
|
||||||
}
|
}
|
||||||
description := "Presentation auto-generated by D2 - https://d2lang.com/"
|
description := "Presentation auto-generated by D2 - https://d2lang.com/"
|
||||||
|
rootName := getFileName(outputPath)
|
||||||
p := pptx.NewPresentation(rootName, description, rootName, username, version.OnlyNumbers())
|
p := pptx.NewPresentation(rootName, description, rootName, username, version.OnlyNumbers())
|
||||||
err := renderPPTX(ctx, ms, p, plugin, renderOpts, outputPath, page, diagram, nil)
|
err := renderPPTX(ctx, ms, p, plugin, renderOpts, outputPath, page, diagram, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -673,11 +670,7 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opt
|
||||||
var currBoardPath []string
|
var currBoardPath []string
|
||||||
// Root board doesn't have a name, so we use the output filename
|
// Root board doesn't have a name, so we use the output filename
|
||||||
if diagram.Name == "" {
|
if diagram.Name == "" {
|
||||||
ext := filepath.Ext(outputPath)
|
currBoardPath = append(boardPath, getFileName(outputPath))
|
||||||
trimmedPath := strings.TrimSuffix(outputPath, ext)
|
|
||||||
splitPath := strings.Split(trimmedPath, "/")
|
|
||||||
rootName := splitPath[len(splitPath)-1]
|
|
||||||
currBoardPath = append(boardPath, rootName)
|
|
||||||
} else {
|
} else {
|
||||||
currBoardPath = append(boardPath, diagram.Name)
|
currBoardPath = append(boardPath, diagram.Name)
|
||||||
}
|
}
|
||||||
|
|
@ -764,11 +757,7 @@ func renderPPTX(ctx context.Context, ms *xmain.State, presentation *pptx.Present
|
||||||
var currBoardPath []string
|
var currBoardPath []string
|
||||||
// Root board doesn't have a name, so we use the output filename
|
// Root board doesn't have a name, so we use the output filename
|
||||||
if diagram.Name == "" {
|
if diagram.Name == "" {
|
||||||
ext := filepath.Ext(outputPath)
|
currBoardPath = append(boardPath, getFileName(outputPath))
|
||||||
trimmedPath := strings.TrimSuffix(outputPath, ext)
|
|
||||||
splitPath := strings.Split(trimmedPath, "/")
|
|
||||||
rootName := splitPath[len(splitPath)-1]
|
|
||||||
currBoardPath = append(boardPath, rootName)
|
|
||||||
} else {
|
} else {
|
||||||
currBoardPath = append(boardPath, diagram.Name)
|
currBoardPath = append(boardPath, diagram.Name)
|
||||||
}
|
}
|
||||||
|
|
@ -844,6 +833,13 @@ func renameExt(fp string, newExt string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFileName(path string) string {
|
||||||
|
ext := filepath.Ext(path)
|
||||||
|
trimmedPath := strings.TrimSuffix(path, ext)
|
||||||
|
splitPath := strings.Split(trimmedPath, "/")
|
||||||
|
return splitPath[len(splitPath)-1]
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: remove after removing slog
|
// TODO: remove after removing slog
|
||||||
func DiscardSlog(ctx context.Context) context.Context {
|
func DiscardSlog(ctx context.Context) context.Context {
|
||||||
return ctxlog.With(ctx, slog.Make(sloghuman.Sink(io.Discard)))
|
return ctxlog.With(ctx, slog.Make(sloghuman.Sink(io.Discard)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue