Skip to content

Commit

Permalink
Merge pull request #90 from x-motemen/expand-home
Browse files Browse the repository at this point in the history
expand tilde in LocalPath with home directory
  • Loading branch information
Songmu authored Oct 13, 2023
2 parents a0c8610 + b52a955 commit c612e9a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -47,8 +48,17 @@ func loadConfig(r io.Reader, fpath string) (*config, error) {
if b == nil {
b = &blogConfig{}
}
if b.LocalRoot != "" && !filepath.IsAbs(b.LocalRoot) {
b.LocalRoot = filepath.Join(absDir, b.LocalRoot)
if b.LocalRoot != "" {
if b.LocalRoot == "~" || strings.HasPrefix(b.LocalRoot, "~/") {
home, err := os.UserHomeDir()
if err != nil {
return nil, err
}
b.LocalRoot = strings.Replace(b.LocalRoot, "~", home, 1)
}
if !filepath.IsAbs(b.LocalRoot) {
b.LocalRoot = filepath.Join(absDir, b.LocalRoot)
}
}
if b.BlogID != "default" {
b.BlogID = key
Expand Down

0 comments on commit c612e9a

Please sign in to comment.