Skip to content

Commit

Permalink
parser: infer tags for tldr from the filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed May 11, 2024
1 parent fbc9dd4 commit 7dd384b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ingest/cheatsheet/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (t *tldr) Parse(path string) (*cheatsheet.CheatSheet, error) {
scanner := bufio.NewScanner(f)

cs := &cheatsheet.CheatSheet{}

var description []string
var explanations []string
var commands []string
Expand All @@ -73,6 +74,12 @@ func (t *tldr) Parse(path string) (*cheatsheet.CheatSheet, error) {
}
}

dir, _ := filepath.Split(path)
// If the directory is not empty and not common, add it to the tags.
if tag := filepath.Base(dir); tag != "" && tag != "common" {
cs.Tags = append(cs.Tags, tag)
}

cs.Description = strings.Join(description, " ")
cs.Examples = zip(explanations, commands)
return cs, nil
Expand Down
1 change: 1 addition & 0 deletions ingest/cheatsheet/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestTLDR(t *testing.T) {
filepath: "testdata/sh.md",
cheatSheet: &cheatsheet.CheatSheet{
Title: "sh",
Tags: []string{"testdata"},
Description: "Bourne shell, the standard command language interpreter. See also `histexpand` for history expansion. More information: <https://manned.org/sh>.",
Examples: []*cheatsheet.Example{
{
Expand Down

0 comments on commit 7dd384b

Please sign in to comment.