Skip to content

Commit

Permalink
Add new sections to the ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
umutphp committed Jul 26, 2020
1 parent 1647683 commit 698fcf3
Showing 1 changed file with 41 additions and 42 deletions.
83 changes: 41 additions & 42 deletions lib/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ func Parse(readme string, r *repo.Repo) {

var parseStatus = false
var content repo.Content
for _, line := range strings.Split(strings.TrimSuffix(readme, "\n"), "\n") {
if IsCategory(line) {
if !IsCategoryIgnored(line) {
if (LineToTitle(line) == "Laws") {
cat = 0
} else {
if (cat == 0) {
r.Categories[cat].Contents = append(r.Categories[cat].Contents, content)
content = repo.NewContent("", "")
}

cat = 1
}

parseStatus = true

continue
} else {
parseStatus = false
}
}

if (parseStatus == true) {
if IsContent(line) {
if content.Title != "" {
r.Categories[cat].Contents = append(r.Categories[cat].Contents, content)
}
content = repo.NewContent(LineToTitle(line), "")
continue
}

content.Body = content.Body + line + "\n"
}
for _, line := range strings.Split(strings.TrimSuffix(readme, "\n"), "\n") {
if IsCategory(line) {
if !IsCategoryIgnored(line) {
if LineToTitle(line) == "Laws" {
cat = 0
} else {
if cat == 0 {
r.Categories[cat].Contents = append(r.Categories[cat].Contents, content)
content = repo.NewContent("", "")
}

cat = 1
}

parseStatus = true

continue
} else {
parseStatus = false
}
}

if parseStatus == true {
if IsContent(line) {
if content.Title != "" {
r.Categories[cat].Contents = append(r.Categories[cat].Contents, content)
}

content = repo.NewContent(LineToTitle(line), "")
continue
}

content.Body = content.Body + line + "\n"
}
}

r.Categories[cat].Contents = append(r.Categories[cat].Contents, content)
Expand All @@ -54,21 +54,20 @@ func IsCategory(line string) bool {
return strings.HasPrefix(line, "## ") && !strings.HasPrefix(line, "### ")
}


func IsContent(line string) bool {
return strings.HasPrefix(line, "### ")
}

func IsCategoryIgnored(line string) bool {
ignoreList := []string{"Reading List", "Contributing", "TODO", "Introduction", "Translations"}
str := LineToTitle(line)
ignoreList := []string{"Reading List", "Contributing", "TODO", "Introduction", "Translations", "Online Resources", "Podcast"}
str := LineToTitle(line)
for _, s := range ignoreList {
if (s == str) {
return true
}
}
if s == str {
return true
}
}

return false
return false
}

func LineToTitle(line string) string {
Expand Down

0 comments on commit 698fcf3

Please sign in to comment.