Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/article/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func SetImageLinks(filename string, images map[string]string, prefix string) (st

if replace, ok := images[parsed.frontMatter.CoverImage]; ok && replace != "" {
parsed.frontMatter.CoverImage = replace
} else {
} else if parsed.frontMatter.CoverImage != "" {
parsed.frontMatter.CoverImage = prefix + parsed.frontMatter.CoverImage
}

Expand All @@ -31,7 +31,7 @@ func SetImageLinks(filename string, images map[string]string, prefix string) (st
n := node.(*ast.Image)
if replace, ok := images[string(n.Destination)]; ok && replace != "" {
n.Destination = []byte(replace)
} else {
} else if len(n.Destination) > 0 {
n.Destination = []byte(prefix + string(n.Destination))
}
}
Expand Down Expand Up @@ -66,7 +66,9 @@ func GetImageLinks(filename string) (map[string]string, error) {
if err := ast.Walk(n, func(node ast.Node, entering bool) (ast.WalkStatus, error) {
if entering && node.Kind() == ast.KindImage {
n := node.(*ast.Image)
images[string(n.Destination)] = ""
if len(n.Destination) > 0 {
images[string(n.Destination)] = ""
}
}
return ast.WalkContinue, nil
}); err != nil {
Expand Down
27 changes: 27 additions & 0 deletions pkg/article/article_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ cover_image: test/./cv.jpg
![image](./image.png)
[Google](www.google.com)
![image](./image-2.png)
`,
assertion: assert.NoError,
},
{
name: "prefix with no entries in config",
args: args{
filename: "./testdata/testdata_nocoverimage.md",
images: map[string]string{},
prefix: "test/",
},
want: `---
title: A title
published: false
description: A description
tags: tag-one, tag-two
---
![image]()
[Google](www.google.com)
![image](test/./image-2.png)
`,
assertion: assert.NoError,
},
Expand Down Expand Up @@ -113,6 +132,14 @@ func TestGetImageLinks(t *testing.T) {
},
assertion: assert.NoError,
},
{
name: "normal",
args: args{filename: "./testdata/testdata_nocoverimage.md"},
want: map[string]string{
"./image-2.png": "",
},
assertion: assert.NoError,
},
{
name: "not found",
args: args{filename: "./testdata/unknown.md"},
Expand Down
10 changes: 10 additions & 0 deletions pkg/article/testdata/testdata_nocoverimage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "A title"
published: false
description: "A description"
tags: "tag-one, tag-two"
---

![image]()
[Google](www.google.com)
![image](./image-2.png)