feed

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadImages

func DownloadImages(ctx context.Context, urls []string, cacheDir string) (map[string]string, error)

DownloadImages fetches all URLs into cacheDir, returning a url→path map. Files are named after the SHA256 of the URL so the same URL resolves to the same path across runs. Already-cached URLs are skipped; network errors on individual URLs are logged-and-ignored so one bad image doesn't break the batch.

func ExtractImageURLs added in v0.8.0

func ExtractImageURLs(md string) []string

ExtractImageURLs scans the markdown for `![alt](url)` references and returns URLs in the order they appear, deduplicated. URLs without a scheme are skipped (local/relative refs aren't reachable here). SVG URLs are also dropped: Go's stdlib image package can't decode SVG, so ToPNG would fail per image — skipping them keeps the log clean and saves a wasted network round-trip.

func ImageFileName

func ImageFileName(u string) string

ImageFileName returns a deterministic filename for the given image URL. The filename is the first 16 bytes of the URL's SHA256 in hex, plus the URL's file extension (if it's a sane-looking ASCII extension).

func ImageID added in v0.8.0

func ImageID(url string) uint32

ImageID returns a deterministic 24-bit image ID derived from the URL. We fold SHA256 down to 24 bits so the low bytes fit in a standard truecolor FG triple (used by older placeholder approach). IDs are not strictly unique but collisions across one article are vanishingly rare and tolerable.

func IsYouTubeURL added in v0.11.0

func IsYouTubeURL(raw string) bool

IsYouTubeURL reports whether raw points at a YouTube host we know how to resolve to the built-in channel RSS feed.

func ToPNG added in v0.8.0

func ToPNG(data []byte) ([]byte, image.Point, error)

ToPNG ensures the given bytes are PNG-encoded. Kitty Graphics Protocol with f=100 requires PNG; we convert JPEG/GIF/etc. via the stdlib image package. Already-PNG input is returned unchanged.

func WriteOPML

func WriteOPML(w io.Writer, title string, feeds []OPMLEntry) error

WriteOPML serializes feeds as an OPML 2.0 document. Each feed becomes a top-level outline under <body>; no category nesting is produced.

Types

type FetchResult

type FetchResult struct {
	Feed    db.Feed
	Added   int
	Updated int
	Err     error
}

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

func New

func New(d *db.DB) *Fetcher

func (*Fetcher) FetchAll

func (f *Fetcher) FetchAll(ctx context.Context) ([]FetchResult, error)

func (*Fetcher) FetchFull

func (f *Fetcher) FetchFull(ctx context.Context, articleURL string) (string, error)

func (*Fetcher) FetchFullWithTitle added in v0.7.0

func (f *Fetcher) FetchFullWithTitle(ctx context.Context, articleURL string) (string, string, error)

FetchFullWithTitle fetches a URL, extracts the main article via go-readability, and returns the page title alongside the Markdown body. Title is whatever readability resolved (often the <title> tag or first <h1>); callers should keep their own placeholder when this returns an empty string.

func (*Fetcher) FetchOne

func (f *Fetcher) FetchOne(ctx context.Context, feed db.Feed) (FetchResult, error)

func (*Fetcher) ResolveYouTube added in v0.11.0

func (f *Fetcher) ResolveYouTube(ctx context.Context, raw string) (ResolvedFeed, bool, error)

ResolveYouTube resolves a YouTube channel/handle/video URL to YouTube's RSS endpoint: https://www.youtube.com/feeds/videos.xml?channel_id=...

type OPMLEntry

type OPMLEntry struct {
	Name string
	URL  string
}

OPMLEntry is a flat representation of a feed extracted from an OPML file.

func ParseOPML

func ParseOPML(r io.Reader) ([]OPMLEntry, error)

ParseOPML decodes an OPML document and returns a flat list of feed entries. Nested categories are flattened — only outlines with a non-empty xmlUrl are emitted. The title/text attribute is preferred for the entry name.

type ResolvedFeed added in v0.11.0

type ResolvedFeed struct {
	Name string
	URL  string
}

ResolvedFeed is a user-facing URL resolved to an RSS/Atom feed URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL