This commit is contained in:
Arnas Udovicius 2022-05-08 23:19:55 +03:00
parent fdbbc02d0a
commit cbee75e3c3
2 changed files with 20 additions and 20 deletions

22
tree.go
View file

@ -33,12 +33,13 @@ func BuildTree(dirPath string, meta []string) (Tree, error) {
} }
func PopulateTree(sourcePath string, destPath string, meta []string) error { func PopulateTree(sourcePath string, destPath string, meta []string) error {
err = fixFormat(sourcePath) err := fixFormat(sourcePath)
if err != nil { if err != nil {
return err return err
} }
id, err := getMaxId(sourcePath) var id int64 = 0
id, err = getMaxId(sourcePath)
if err != nil { if err != nil {
return err return err
} }
@ -87,9 +88,9 @@ func fixFormat(dir string) error {
format = false format = false
} }
if (format) { if format {
line = strings.Trim(line, " ") line = strings.Trim(line, " ")
if (line != "") { if line != "" {
content = content + "\n" + line content = content + "\n" + line
} }
} else { } else {
@ -319,15 +320,15 @@ func readFile(file fs.FileInfo, fullPath string, category []string, meta []strin
} }
} }
} }
osf.Close() _ = osf.Close()
return f, nil return f, nil
} }
func ReadFileContent(file File) (string, error) { func ReadFileContent(file File) (string, error) {
osf, err := os.Open(path) osf, err := os.Open(file.FullPath)
if err != nil { if err != nil {
return nil, err return "", err
} }
content := "" content := ""
@ -342,13 +343,13 @@ func ReadFileContent(file File) (string, error) {
continue continue
} }
if (isMetaPart) { if isMetaPart {
continue continue
} }
if (removeEmptyLine) { if removeEmptyLine {
line = strings.Trim(line, " ") line = strings.Trim(line, " ")
if (line == "") { if line == "" {
continue continue
} else { } else {
removeEmptyLine = false removeEmptyLine = false
@ -357,6 +358,7 @@ func ReadFileContent(file File) (string, error) {
content = content + "\n" + line content = content + "\n" + line
} }
_ = osf.Close()
return content, nil return content, nil
} }

View file

@ -75,8 +75,6 @@ func TestFixFormat(t *testing.T) {
if !strings.Contains(str, "\n\n---\n") { if !strings.Contains(str, "\n\n---\n") {
t.Fatal("Split line has not been formatted in file 'file1.md'.") t.Fatal("Split line has not been formatted in file 'file1.md'.")
} }
t.Log(tree)
} }
func TestMeta(t *testing.T) { func TestMeta(t *testing.T) {