Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit f5bdb96

Browse files
committed
remove hardcoded paths
1 parent babfcd9 commit f5bdb96

File tree

9 files changed

+15
-38
lines changed

9 files changed

+15
-38
lines changed

blog/article.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ type Article struct {
1313
baseDir string
1414
}
1515

16-
// constructor ensures that path is always provided for safety
17-
func NewArticleWithPath(meta Metadata,path string) *Article {
18-
return &Article{Meta:meta,path:path}
19-
}
20-
21-
func NewArticle(meta Metadata) *Article {
22-
return &Article{Meta:meta, baseDir: obsidianVault}
23-
}
24-
2516
func NewArticleWithBaseDir(meta Metadata,baseDir string) *Article {
2617
return &Article{Meta:meta,baseDir:baseDir}
2718
}

blog/article_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111

1212
func TestArticleFilePath(t *testing.T) {
13-
sut := NewArticle(Metadata{Title: "Article title"})
14-
assert.Equal(t, filepath.Join(obsidianVault,articleDir, "Article title.md"), sut.Path())
13+
sut := NewArticleWithBaseDir(Metadata{Title: "Article title"},"/")
14+
assert.Equal(t, filepath.Join("/",articleDir, "Article title.md"), sut.Path())
1515
}
1616

1717

blog/blog.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"github.com/pkg/errors"
1212
"github.com/spf13/afero"
1313
)
14-
const obsidianVault = "/Users/adria/Library/Mobile Documents/iCloud~md~obsidian/Documents/Second_brain"
15-
1614

1715
func GetFilepath(articleTitle,folderPath string) string {
1816
return path.Join(folderPath,articleTitle+".md")

blog/blog_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ func TestBlog(t *testing.T) {
9393
}
9494

9595
func TestLink(t *testing.T) {
96-
post := blog.NewArticleWithPath(blog.Metadata{Title:"Examples are good"},"")
96+
post := blog.NewArticleWithBaseDir(blog.Metadata{Title:"Examples are good"},"/")
9797
assert.Equal(t,"posts/examples-are-good",blog.ConstructPostLink(post))
9898
}

blog/book.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ type Book struct {
1515
baseDir string
1616
}
1717

18-
// constructor ensures that path is always provided for safety
19-
func NewBookWithPath(meta Metadata,path string) *Book {
20-
return &Book{Meta:meta,path:path}
21-
}
22-
23-
func NewBook(meta Metadata) *Book {
24-
return &Book{Meta:meta, baseDir:obsidianVault}
25-
}
26-
2718
func NewBookWithBaseDir(meta Metadata,baseDir string) *Book {
2819
return &Book{Meta:meta,baseDir:baseDir}
2920
}

blog/letter.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
package blog
22

3-
import "io"
3+
import (
4+
"io"
5+
"path/filepath"
6+
)
47

58
const letterCategory = "Letters"
6-
const letterDir = obsidianVault +"/Letters"
9+
const letterDir = "/Letters"
710

811

912
type Letter struct {
1013
TemplateFile io.Reader
1114
Meta Metadata
12-
path string
15+
baseDir string
1316
}
1417

15-
// constructor ensures that path is always provided for safety
16-
func NewLetter(meta Metadata) *Letter {
17-
return &Letter{Meta:meta}
18-
}
19-
20-
21-
func NewLetterWithPath(meta Metadata, path string) *Letter {
22-
return &Letter{Meta:meta,path:path}
18+
func NewLetterWithBaseDir(meta Metadata, baseDir string) *Letter {
19+
return &Letter{Meta:meta,baseDir:baseDir}
2320
}
2421

2522
func (b Letter) Title() string {
2623
return b.Meta.Title
2724
}
2825

29-
func (b Letter) Path() string { return GetFilepath(b.Meta.Title,letterDir)}
26+
func (b Letter) Path() string { return GetFilepath(b.Meta.Title,filepath.Join(b.baseDir,letterDir))}
3027

3128
func (a Letter) Write(file io.Writer) {
3229
io.WriteString(file,a.Meta.String())

blog/letter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import (
1010

1111

1212
func TestLetterFilePath(t *testing.T) {
13-
sut := NewLetter(Metadata{Title: "Letter title"})
13+
sut := NewLetterWithBaseDir(Metadata{Title: "Letter title"},"/")
1414
assert.Equal(t, filepath.Join(letterDir,"Letter title.md"), sut.Path())
1515
}

blog/post.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (f PostFactory) NewPost(meta Metadata) (post Post,err error) {
4141
book.TemplateFile = f.BookTemplate
4242
return book, nil
4343
case contains(meta.Categories,letterCategory):
44-
return NewLetter(meta),nil
44+
return NewLetterWithBaseDir(meta,f.BaseDir),nil
4545
default:
4646
return NewArticleWithBaseDir(meta,f.BaseDir),nil
4747
}

git/blogpush_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ func (r *fakeRepo) RepoPath() string {
4040
func TestPushOrder(t *testing.T) {
4141
fakeRepo := &fakeRepo{repoPath:""}
4242
sut := BlogPush{fakeRepo}
43-
sut.Push(blog.NewArticleWithPath(blog.Metadata{},""))
43+
sut.Push(blog.NewArticleWithBaseDir(blog.Metadata{},"/"))
4444
assert.Equal(t, []string{"StageAll", "Commit", "Pull", "Push"}, fakeRepo.callOrder)
4545
}

0 commit comments

Comments
 (0)