Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store
.lite_project.lua
*.md
.vogte/

/bin/
config.yaml
Expand Down
2 changes: 1 addition & 1 deletion analyst.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func collectArticlesForAnalysis(cfg *Config, store *Storage, fp *gofeed.Parser)
articles = append(articles, articleText)

if !seenToday {
if err := store.MarkAsSeen(articleLink, summary); err != nil {
if err := store.MarkAsSeen(articleLink, summary, item.Title, feed.Title, feed.Link); err != nil {
continue
}
}
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Config struct {
DatabaseFilePath string
NotificationTrigger string
NotificationWebhookURL string
GenerateAll bool
}

type RSS struct {
Expand All @@ -81,6 +82,8 @@ func LoadConfig() (*Config, error) {
configFile := flag.String("c", "", "Config file path (if you want to override the current directory config.yaml)")
opmlFile := flag.String("o", "", "OPML file path to append feeds from opml files")
build := flag.Bool("build", false, "Dev: Build matcha binaries in the bin directory")
generateAll := flag.Bool("generate-all", false, "Generate markdown files for all days in the database")

flag.Parse()

if *build {
Expand Down Expand Up @@ -125,6 +128,7 @@ func LoadConfig() (*Config, error) {
DatabaseFilePath: viper.GetString("database_file_path"),
NotificationTrigger: viper.GetString("notification_trigger"),
NotificationWebhookURL: viper.GetString("notification_webhook_url"),
GenerateAll: *generateAll,
}

if cfg.MarkdownDirPath == "" {
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log"
"os"
"time"

"github.com/mmcdole/gofeed"
_ "modernc.org/sqlite"
Expand All @@ -20,13 +21,18 @@ func main() {
}
defer store.Close()

if cfg.GenerateAll {
runGenerateAll(cfg, store)
return
}

llm := NewLLMClient(cfg)

var writer Writer
if cfg.TerminalMode {
writer = TerminalWriter{}
} else {
mw := NewMarkdownWriter(cfg)
mw := NewMarkdownWriter(cfg, time.Now().Format("2006-01-02"))
os.Remove(mw.FilePath)
writer = mw
}
Expand Down
36 changes: 28 additions & 8 deletions markdown_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,36 @@ type MarkdownWriter struct {
FilePath string
}

func NewMarkdownWriter(cfg *Config) *MarkdownWriter {
date := time.Now().Format("2006-01-02")
fname := cfg.MarkdownFilePrefix + date + cfg.MarkdownFileSuffix + ".md"
func NewMarkdownWriter(cfg *Config, dateStr string) *MarkdownWriter {
if dateStr == "" {
dateStr = time.Now().Format("2006-01-02")
}
fname := cfg.MarkdownFilePrefix + dateStr + cfg.MarkdownFileSuffix + ".md"
return &MarkdownWriter{
FilePath: filepath.Join(cfg.MarkdownDirPath, fname),
}
}

func (w MarkdownWriter) WriteFeedHeaderRaw(title, articleURL string) string {
// Logic to reconstruct the Favicon HTML without a gofeed object
var src string
if strings.Contains(title, "Hacker News") {
src = "https://news.ycombinator.com/favicon.ico"
} else if articleURL == "" {
return fmt.Sprintf("\n### 🍵 %s\n", title)
} else {
u, err := url.Parse(articleURL)
if err != nil {
return fmt.Sprintf("\n### 🍵 %s\n", title)
}
// Google S2 Favicon service
src = "https://www.google.com/s2/favicons?sz=32&domain=" + u.Hostname()
}

faviconImg := fmt.Sprintf(`<img src="%s" width="32" height="32" />`, src)
return fmt.Sprintf("\n### %s %s\n", faviconImg, title)
}

func (w MarkdownWriter) Write(body string) {
f, err := os.OpenFile(w.FilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
Expand All @@ -42,9 +64,8 @@ func (w MarkdownWriter) WriteLink(title string, url string, newLine bool, readin
if readingTime != "" {
content += fmt.Sprintf(" (%s)", readingTime)
}

if newLine {
content += " \n"
content += " \n"
}
return content
}
Expand All @@ -53,16 +74,15 @@ func (w MarkdownWriter) WriteSummary(content string, newLine bool) string {
if content == "" {
return ""
}

if newLine {
content += " \n\n"
content += " \n\n"
}
return content
}

func (w MarkdownWriter) WriteHeader(feed *gofeed.Feed) string {
favicon := w.getFaviconHTML(feed)
return fmt.Sprintf("\n### %s %s\n", favicon, feed.Title)
return fmt.Sprintf("\n### %s %s\n", favicon, feed.Title)
}

// Helper method specifically for MarkdownWriter
Expand Down
Loading