this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve wikipedia preview handling

+42 -2
+3 -1
internal/assets/css/screen.css
··· 303 303 .og-description { 304 304 font-size: 15px; 305 305 line-height: 22px; 306 - color: #1d1c1d; 306 + color: #2d2d2d; /* Slightly softer than #1d1c1d */ 307 307 margin-bottom: 8px; 308 + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 309 + letter-spacing: normal; 308 310 } 309 311 310 312 .og-image {
+39 -1
internal/handler/preview.go
··· 29 29 } 30 30 31 31 // Fetch data 32 - resp, err := http.Get(urlParam) 32 + req, err := http.NewRequest("GET", urlParam, nil) 33 + if err != nil { 34 + json.NewEncoder(w).Encode(map[string]string{"error": "Invalid URL"}) 35 + return 36 + } 37 + // Use a standard browser UA to avoid 403s (e.g. Wikipedia) 38 + req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") 39 + 40 + client := &http.Client{} 41 + resp, err := client.Do(req) 33 42 if err != nil { 34 43 json.NewEncoder(w).Encode(map[string]string{"error": "Failed to fetch URL"}) 35 44 return ··· 44 53 } 45 54 46 55 metadata := make(map[string]string) 56 + 57 + // Helper to extract text from a node's children 58 + var extractText func(*html.Node) string 59 + extractText = func(n *html.Node) string { 60 + var sb strings.Builder 61 + if n.Type == html.TextNode { 62 + sb.WriteString(n.Data) 63 + } 64 + for c := n.FirstChild; c != nil; c = c.NextSibling { 65 + sb.WriteString(extractText(c)) 66 + } 67 + return sb.String() 68 + } 69 + 47 70 var f func(*html.Node) 48 71 f = func(n *html.Node) { 49 72 if n.Type == html.ElementNode && n.Data == "meta" { ··· 83 106 if n.FirstChild != nil { 84 107 if _, ok := metadata["title"]; !ok { 85 108 metadata["title"] = n.FirstChild.Data 109 + } 110 + } 111 + } 112 + 113 + // Look for first paragraph if no description yet 114 + if n.Type == html.ElementNode && n.Data == "p" { 115 + if _, hasDesc := metadata["description"]; !hasDesc { 116 + text := strings.TrimSpace(extractText(n)) 117 + // Wikipedia paragraphs often have citations [1] or are empty/short 118 + // Simple heuristic: length > 50 119 + if len(text) > 50 { 120 + // Check for "Coordinates:" which matches length but isn't intro 121 + if !strings.HasPrefix(text, "Coordinates:") { 122 + metadata["description"] = text 123 + } 86 124 } 87 125 } 88 126 }