diff --git a/README.md b/README.md index 4280371..1219f54 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ Text ### Meta data -Meta data separated by lines and in format `- name: value`. By default library supports `tags` as comma separated array. +Meta data separated by lines and in format `* name: value`. By default library supports `tags` as comma separated array. During populating tree it adds missing `id` in `abcex` format and empty meta data lines and saves in `source` directory then copy to `destination` directory. ### File structure ``` -- tags: linux,command,video -- meta1: example -- meta2: some long description +* tags: linux,command,video +* meta1: example +* meta2: some long description --- diff --git a/testdata/sunny/file1.md b/testdata/sunny/file1.md index 9df5a0d..d6419df 100644 --- a/testdata/sunny/file1.md +++ b/testdata/sunny/file1.md @@ -1,7 +1,7 @@ -- tags: t1,t2 +* tags: t1,t2 -- description: Če test file __va__ -- option1: test option +* description: Če test file __va__ +* option1: test option --- # Če kažkas torietom būtė diff --git a/testdata/sunny/file2.md b/testdata/sunny/file2.md index 53be1f9..61b675d 100644 --- a/testdata/sunny/file2.md +++ b/testdata/sunny/file2.md @@ -1,5 +1,5 @@ -- tags: t1 -- description: Če test 2 +* tags: t1 +* description: Če test 2 --- diff --git a/testdata/sunny/subcategory/file3.md b/testdata/sunny/subcategory/file3.md index 7710da8..78414fe 100644 --- a/testdata/sunny/subcategory/file3.md +++ b/testdata/sunny/subcategory/file3.md @@ -1,6 +1,6 @@ -- tags: t1 -- description: Če test 3 -- option2: it exists +* tags: t1 +* description: Če test 3 +* option2: it exists --- diff --git a/tree.go b/tree.go index 904446d..0259709 100644 --- a/tree.go +++ b/tree.go @@ -131,7 +131,7 @@ func addMissingMeta(dir string, meta []string) error { for scanner.Scan() { line := scanner.Text() for _, option := range meta { - if strings.HasPrefix(line, "- "+option+":") { + if strings.HasPrefix(line, "* "+option+":") { check[option] = true } } @@ -200,7 +200,7 @@ func addMeta(path string, option string, value string) error { } str := string(b) - str = strings.Replace(str, "\n\n---\n", fmt.Sprintf("\n- %s: %s\n\n---\n", option, value), 1) + str = strings.Replace(str, "\n\n---\n", fmt.Sprintf("\n* %s: %s\n\n---\n", option, value), 1) err = ioutil.WriteFile(path, []byte(str), 0644) return err @@ -299,8 +299,8 @@ func readFile(file fs.FileInfo, fullPath string, category []string, meta []strin break } - if strings.HasPrefix(line, "- tags:") { - line = strings.TrimPrefix(line, "- tags:") + if strings.HasPrefix(line, "* tags:") { + line = strings.TrimPrefix(line, "* tags:") t := strings.Split(line, ",") tags := []string{} for _, tag := range t { @@ -309,13 +309,13 @@ func readFile(file fs.FileInfo, fullPath string, category []string, meta []strin f.Tags = tags } - if strings.HasPrefix(line, "- id:") { - line = strings.TrimPrefix(line, "- id:") + if strings.HasPrefix(line, "* id:") { + line = strings.TrimPrefix(line, "* id:") f.Id = strings.Trim(line, " ") } for _, option := range meta { - if strings.HasPrefix(line, "- "+option) { - line = strings.TrimPrefix(line, "- "+option+":") + if strings.HasPrefix(line, "* "+option) { + line = strings.TrimPrefix(line, "* "+option+":") f.Meta[option] = strings.Trim(line, " ") } } diff --git a/tree_test.go b/tree_test.go index e18176c..8daa4a5 100644 --- a/tree_test.go +++ b/tree_test.go @@ -70,7 +70,7 @@ func TestFixFormat(t *testing.T) { } str := string(b) t.Log(str) - if !strings.Contains(str, "- tags: t1,t2\n- description: Če test file __va__\n") { + if !strings.Contains(str, "* tags: t1,t2\n* description: Če test file __va__\n") { t.Fatal("Empty lines has not been removed in file 'file1.md'.") } if !strings.Contains(str, "\n\n---\n") { @@ -124,7 +124,7 @@ func TestId(t *testing.T) { t.Fatal("No destination file 'file1.md'.") } str := string(b) - if !strings.Contains(str, "\n- id: 1\n") { + if !strings.Contains(str, "\n* id: 1\n") { t.Fatal("No id in file 'file1.md'.") } @@ -133,7 +133,7 @@ func TestId(t *testing.T) { t.Fatal("No destination file 'substring/file3.md'.") } str = string(b) - if !strings.Contains(str, "\n- id: 3\n") { + if !strings.Contains(str, "\n* id: 3\n") { t.Fatal("No id in file 'file3.md'.") } } @@ -160,10 +160,10 @@ func TestMissingOptions(t *testing.T) { t.Fatal("No destination file 'file1.md'.") } str := string(b) - if !strings.Contains(str, "\n- option1: test option\n") { + if !strings.Contains(str, "\n* option1: test option\n") { t.Fatal("Changed old value for 'option1' in file 'file1.md'.") } - if !strings.Contains(str, "\n- option2: \n") { + if !strings.Contains(str, "\n* option2: \n") { t.Fatal("'option2' has not been added to file 'file1.md'.") } @@ -172,10 +172,10 @@ func TestMissingOptions(t *testing.T) { t.Fatal("No destination file 'file2.md'.") } str = string(b) - if !strings.Contains(str, "\n- option1: \n") { + if !strings.Contains(str, "\n* option1: \n") { t.Fatal("'option1' has not been added to file 'file2.md'.") } - if !strings.Contains(str, "\n- option2: \n") { + if !strings.Contains(str, "\n* option2: \n") { t.Fatal("'option2' has not been added to file 'file2.md'.") } @@ -184,10 +184,10 @@ func TestMissingOptions(t *testing.T) { t.Fatal("No destination file 'substring/file3.md'.") } str = string(b) - if !strings.Contains(str, "\n- option1: \n") { + if !strings.Contains(str, "\n* option1: \n") { t.Fatal("'option1' has not been added to file 'file3.md'.") } - if !strings.Contains(str, "\n- option2: it exists\n") { + if !strings.Contains(str, "\n* option2: it exists\n") { t.Fatal("Changed old value for 'option2' in file 'file3.md'.") } }