| 60 | } |
| 61 | |
| 62 | func parseCatalogMarkdown(content, relPath string, kind entities.Kind) []DiscoveredResource { |
| 63 | content = strings.ReplaceAll(content, "\r\n", "\n") |
| 64 | lines := strings.Split(content, "\n") |
| 65 | var out []DiscoveredResource |
| 66 | seen := map[string]bool{} |
| 67 | |
| 68 | for i := 0; i < len(lines)-1; i++ { |
| 69 | headerLine := strings.TrimSpace(lines[i]) |
| 70 | separatorLine := strings.TrimSpace(lines[i+1]) |
| 71 | if !looksLikeTableHeader(headerLine, separatorLine) { |
| 72 | continue |
| 73 | } |
| 74 | |
| 75 | header := splitTableRow(headerLine) |
| 76 | nameIdx, descIdx, ok := catalogColumnIndexes(header, kind) |
| 77 | if !ok { |
| 78 | continue |
| 79 | } |
| 80 | |
| 81 | for j := i + 2; j < len(lines); j++ { |
| 82 | line := strings.TrimSpace(lines[j]) |
| 83 | if line == "" || !strings.Contains(line, "|") { |
| 84 | break |
| 85 | } |
| 86 | cells := splitTableRow(line) |
| 87 | if nameIdx >= len(cells) { |
| 88 | continue |
| 89 | } |
| 90 | name, source := cleanCatalogNameCell(cells[nameIdx]) |
| 91 | if name == "" || strings.EqualFold(name, "name") { |
| 92 | continue |
| 93 | } |
| 94 | key := strings.ToLower(catalogInstallKeyName(name, source)) |
| 95 | if seen[key] { |
| 96 | continue |
| 97 | } |
| 98 | desc := "" |
| 99 | if descIdx >= 0 && descIdx < len(cells) { |
| 100 | desc = cleanCatalogCell(cells[descIdx]) |
| 101 | } |
| 102 | seen[key] = true |
| 103 | res := DiscoveredResource{ |
| 104 | Name: name, |
| 105 | Description: desc, |
| 106 | RelPath: relPath, |
| 107 | ManifestRel: relPath, |
| 108 | InstallKeyName: catalogInstallKeyName(name, source), |
| 109 | } |
| 110 | // Attribute the row to its real source repo when the name link points |
| 111 | // at one, so awesome-list "pointer" catalogs don't duplicate the skills |
| 112 | // they merely list. |
| 113 | if owner, repo, branch, path, ok := parseGithubSource(source); ok { |
| 114 | res.SourceOwner = owner |
| 115 | res.SourceRepo = repo |
| 116 | res.SourceBranch = branch |
| 117 | res.SourcePath = path |
| 118 | } |
| 119 | out = append(out, res) |