diff --git a/d2cli/main.go b/d2cli/main.go
index 4e377bdef..47e6744f5 100644
--- a/d2cli/main.go
+++ b/d2cli/main.go
@@ -795,7 +795,7 @@ func renderPPTX(ctx context.Context, ms *xmain.State, presentation *ppt.Presenta
return err
}
- err = presentation.AddSlide(strings.Join(boardPath, " / "), pngImg)
+ err = presentation.AddSlide(pngImg, currBoardPath)
if err != nil {
return err
}
diff --git a/lib/ppt/pptx.go b/lib/ppt/pptx.go
index f6d13b403..1de5d589e 100644
--- a/lib/ppt/pptx.go
+++ b/lib/ppt/pptx.go
@@ -61,11 +61,21 @@ func getRelsSlideXml(imageId string) string {
return fmt.Sprintf(RELS_SLIDE_XML, imageId, imageId)
}
-const SLIDE_XML = `%s`
+const SLIDE_XML = `%s`
-func getSlideXml(slideTitle, imageId string, top, left, width, height int) string {
+func getSlideXml(boardPath []string, imageId string, top, left, width, height int) string {
+ var slideTitle string
+ boardName := boardPath[len(boardPath)-1]
+ prefixPath := boardPath[:len(boardPath)-1]
+ if len(prefixPath) > 0 {
+ prefix := strings.Join(prefixPath, " / ") + " / "
+ slideTitle = fmt.Sprintf(`%s%s`, prefix, boardName)
+ } else {
+ slideTitle = fmt.Sprintf(`%s`, boardName)
+ }
+ slideDescription := strings.Join(boardPath, " / ")
top += HEADER_HEIGHT
- return fmt.Sprintf(SLIDE_XML, slideTitle, slideTitle, imageId, left, top, width, height, slideTitle, HEADER_HEIGHT, slideTitle)
+ return fmt.Sprintf(SLIDE_XML, slideDescription, slideDescription, imageId, left, top, width, height, slideDescription, HEADER_HEIGHT, slideTitle)
}
func getPresentationXmlRels(slideFileNames []string) string {
diff --git a/lib/ppt/presentation.go b/lib/ppt/presentation.go
index 2f6cde1a1..5003df26d 100644
--- a/lib/ppt/presentation.go
+++ b/lib/ppt/presentation.go
@@ -21,7 +21,7 @@ type Presentation struct {
}
type Slide struct {
- Title string
+ BoardPath []string
Image []byte
ImageWidth int
ImageHeight int
@@ -33,7 +33,7 @@ func NewPresentation() *Presentation {
return &Presentation{}
}
-func (p *Presentation) AddSlide(title string, pngContent []byte) error {
+func (p *Presentation) AddSlide(pngContent []byte, boardPath []string) error {
src, err := png.Decode(bytes.NewReader(pngContent))
if err != nil {
return fmt.Errorf("error decoding PNG image: %v", err)
@@ -55,15 +55,18 @@ func (p *Presentation) AddSlide(title string, pngContent []byte) error {
left = (IMAGE_WIDTH - width) / 2
}
- p.Slides = append(p.Slides, &Slide{
- Title: title,
+ slide := &Slide{
+ BoardPath: make([]string, len(boardPath)),
Image: pngContent,
ImageWidth: width,
ImageHeight: height,
ImageTop: top,
ImageLeft: left,
- })
+ }
+ // it must copy the board path to avoid slice reference issues
+ copy(slide.BoardPath, boardPath)
+ p.Slides = append(p.Slides, slide)
return nil
}
@@ -101,7 +104,7 @@ func (p *Presentation) SaveTo(filePath string) error {
err = addFile(
zipFile,
fmt.Sprintf("ppt/slides/%s.xml", slideFileName),
- getSlideXml(slide.Title, imageId, slide.ImageTop, slide.ImageLeft, slide.ImageWidth, slide.ImageHeight),
+ getSlideXml(slide.BoardPath, imageId, slide.ImageTop, slide.ImageLeft, slide.ImageWidth, slide.ImageHeight),
)
if err != nil {
return err