-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28f0ef0
commit d08cf4e
Showing
8 changed files
with
213 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package markdown | ||
|
||
import ( | ||
"github.com/lithammer/fuzzysearch/fuzzy" | ||
) | ||
|
||
func (md MarkdownFile) GetFrontMatter(key string, defaultValue interface{}) (value interface{}) { | ||
if md.FrontMatter == nil { | ||
return defaultValue | ||
} | ||
if val, ok := md.FrontMatter[key]; ok { | ||
return val | ||
} | ||
return defaultValue | ||
} | ||
|
||
// GetSection returns the first section of the specified type with the specified text | ||
func (md MarkdownFile) GetSection(sectionType SectionType, text string) (section *Section) { | ||
for _, s := range md.Sections { | ||
if s.SectionType == sectionType && s.Text == text { | ||
return &s | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// SearchSection returns a list of sections that contain the search string (with fuzzy search) | ||
func (md MarkdownFile) SearchSection(searchString string) (sections *[]Section) { | ||
var foundSections []Section | ||
for _, s := range md.Sections { | ||
if fuzzy.Match(searchString, s.Text) { | ||
foundSections = append(foundSections, s) | ||
} | ||
} | ||
return &foundSections | ||
} | ||
|
||
// SearchSection returns a list of sections with specified section type that contain the search string (with fuzzy search) | ||
func (md MarkdownFile) SearchSectionWithType(searchString string, sectionType SectionType) (sections *[]Section) { | ||
var foundSections []Section | ||
for _, s := range md.Sections { | ||
if s.SectionType == sectionType { | ||
if fuzzy.Match(searchString, s.Text) { | ||
foundSections = append(foundSections, s) | ||
} | ||
} | ||
} | ||
return &foundSections | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters