mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-03 20:13:03 +00:00
updage
This commit is contained in:
@@ -13,6 +13,20 @@ import (
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
)
|
||||
|
||||
// titleCase converts a string to title case (first letter of each word capitalized)
|
||||
func titleCase(s string) string {
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
words := strings.Fields(s)
|
||||
for i, word := range words {
|
||||
if len(word) > 0 {
|
||||
words[i] = strings.ToUpper(word[:1]) + strings.ToLower(word[1:])
|
||||
}
|
||||
}
|
||||
return strings.Join(words, " ")
|
||||
}
|
||||
|
||||
// Document represents a scraped document to be formatted as markdown
|
||||
type Document struct {
|
||||
ID string `json:"id"`
|
||||
@@ -66,7 +80,7 @@ func (f *Formatter) ToMarkdown(doc *Document) string {
|
||||
if doc.Metadata != nil {
|
||||
for key, value := range doc.Metadata {
|
||||
if strValue := fmt.Sprintf("%v", value); strValue != "" && strValue != "<nil>" {
|
||||
buf.WriteString(fmt.Sprintf("| **%s** | %s |\n", strings.Title(key), strValue))
|
||||
buf.WriteString(fmt.Sprintf("| **%s** | %s |\n", titleCase(key), strValue))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user