diff options
Diffstat (limited to 'indexers/pikdex/meta.go')
| -rw-r--r-- | indexers/pikdex/meta.go | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/indexers/pikdex/meta.go b/indexers/pikdex/meta.go index 750ce47..ef2c029 100644 --- a/indexers/pikdex/meta.go +++ b/indexers/pikdex/meta.go @@ -2,24 +2,28 @@ package pikdex import ( "github.com/charmbracelet/lipgloss" + "github.com/ewy1/pik/describe" "strings" ) type MetaSetter func(s *SourceData, content string) var MetaFiles = map[string]MetaSetter{ + ".wants": func(s *SourceData, content string) { + s.Wants = contentLines(content) + }, + ".includes": func(s *SourceData, content string) { + s.Includes = contentLines(content) + }, ".alias": func(s *SourceData, content string) { - split := strings.Split(content, "\n") - s.Aliases = make([]string, 0, len(split)) - for _, line := range split { - stripped := strip(line) - if stripped != "" { - s.Aliases = append(s.Aliases, stripped) - } - } + s.Aliases = contentLines(content) }, ".icon": func(s *SourceData, content string) { - icon := strip(content) + lines := contentLines(content) + if len(lines) == 0 { + return + } + icon := lines[0] desiredWidth := lipgloss.Width(icon) diff := desiredWidth - len([]rune(icon)) icon += strings.Repeat(" ", diff) @@ -27,6 +31,23 @@ var MetaFiles = map[string]MetaSetter{ }, } -func strip(input string) string { - return strings.TrimSpace(input) +func contentLines(input string) []string { + result := make([]string, 0, len(input)) +nextLine: + for _, l := range strings.Split(input, "\n") { + l = strings.TrimSpace(l) + + if l == "" { + continue nextLine + } + + for _, c := range describe.CommentPrefixes { + if strings.HasPrefix(l, c) { + continue nextLine + } + } + + result = append(result, l) + } + return result } |
