Skip to content

Commit 9e6e17a

Browse files
committed
feat: add dteather.com blog
1 parent d2cf59b commit 9e6e17a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
harvest

src/feed/fetcher.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ var dateFormats = []string{
2727
"January 2, 2006",
2828
}
2929

30-
func cleanHTML(input string) string {
30+
// We're rendering to markdown so to preserve formatting we need to strip out any markdown characters
31+
func stripMarkdown(input string) string {
32+
invalidChars := []string{"*", "_", "#", "`", ">", "<", "[", "]", "(", ")", "!", "~", "|", "{", "}", "+"}
33+
for _, char := range invalidChars {
34+
input = strings.ReplaceAll(input, char, "")
35+
}
36+
37+
return input
38+
}
39+
40+
func cleanHTML(input string, maxLength int) string {
3141
// first, remove HTML tags
3242
tagRegex := regexp.MustCompile("<[^>]*>")
3343
cleaned := tagRegex.ReplaceAllString(input, "")
@@ -43,6 +53,17 @@ func cleanHTML(input string) string {
4353
wsRegex := regexp.MustCompile(`\s+`)
4454
cleaned = wsRegex.ReplaceAllString(cleaned, " ")
4555

56+
// & truncate to maxLength
57+
if len(cleaned) > maxLength {
58+
cleaned = cleaned[:maxLength]
59+
60+
if cleaned[len(cleaned)-1] == ' ' || cleaned[len(cleaned)-1] == '.' {
61+
cleaned = cleaned[:len(cleaned)-1]
62+
}
63+
64+
cleaned += "..."
65+
}
66+
4667
return strings.TrimSpace(cleaned)
4768
}
4869

@@ -73,13 +94,14 @@ func parseDate(item Item) time.Time {
7394
func getDescription(item Item) string {
7495
candidates := []string{
7596
item.Description,
97+
item.Summary,
7698
item.Content,
7799
item.Encoded,
78100
}
79101

80102
for _, candidate := range candidates {
81103
if candidate != "" {
82-
return cleanHTML(candidate)
104+
return stripMarkdown(cleanHTML(candidate, 200))
83105
}
84106
}
85107

src/feed/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Item struct {
1818
Description string `xml:"description"`
1919
Content string `xml:"content"`
2020
Encoded string `xml:"encoded"`
21+
Summary string `xml:"summary"`
2122
}
2223

2324
type Channel struct {

whitelist.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ feeds = [
66
"https://ben.enterprises/rss.xml",
77
"https://www.amoses.dev/rss.xml",
88
"https://nick.winans.io/rss.xml",
9+
"https://dteather.com/blogs/rss.xml",
910
]

0 commit comments

Comments
 (0)