internal

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeneratorName    string = "feedloggr"
	GeneratorVersion string = "v0.4.2"
	GeneratorSource  string = "https://github.com/lmas/feedloggr"
)

Basic info about this generator

Variables

View Source
var TemplateFuncs = html.FuncMap{
	"shortdate": func(t time.Time) string {
		return t.Format("2006-01-02")
	},
	"prevday": func(t time.Time) time.Time {
		return t.AddDate(0, 0, -1)
	},
	"nextday": func(t time.Time) time.Time {
		return t.AddDate(0, 0, 1)
	},
}

TemplateFuncs contains some simple helper functions available inside a template.

Functions

func DiscoverFeeds added in v0.4.0

func DiscoverFeeds(site string) (feeds []string, err error)

DiscoverFeeds tries to discover any URLs that looks like feeds, from a site.

func LoadTemplate added in v0.4.0

func LoadTemplate(file string) (tmpl *html.Template, err error)

LoadTemplates tries to parse a template from file or use a default template. The returned template has no name and has some helper functions declared.

func Symlink(src, dst string) error

Symlink tries to make a new symlink dst pointing to file src.

func WriteTemplate

func WriteTemplate(file string, tmpl *html.Template, vars interface{}) error

WriteTemplate executes a loaded template (using provided vars) and writes it's output to a file.

Types

type Conf

type Conf struct {
	Settings Settings // General settings
	Feeds    []Feed   // Per feed settings
}

Conf contains ALL settings for a Generator, usually loaded from a yaml file.

func ExampleConf

func ExampleConf() Conf

ExampleConf returns a working example Conf.

func LoadConf

func LoadConf(path string) (c Conf, err error)

LoadConf tries to load a Conf from a yaml file.

func (Conf) String

func (conf Conf) String() string

String tries to return a yaml formatted string of Conf or an error

type Feed

type Feed struct {
	Title  string // Custom title
	Url    string // URL to feed
	Parser Parser `yaml:",omitempty"` // Custom parsing rule.
}

Feed represents a single news feed and how to download and parse it.

func (Feed) Source

func (f Feed) Source() string

Source returns the "correct" URL host used as the source for the feed.

type FilterStats

type FilterStats struct {
	Capacity  uint    // Total capacity for the internal series of bloom filters
	Hashes    uint    // Number of hash functions for each internal filter
	FillRatio float64 // Average ratio of set bits across all internal filters
}

FilterStats contains basic info about the internal Bloom Filter.

func (FilterStats) String

func (fs FilterStats) String() string

String returns a pretty string of FilterStats.

type Generator

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

Generator is used for downloading, parsing and then filtering items from feeds.

func NewGenerator added in v0.4.0

func NewGenerator(conf Conf) (gen *Generator, err error)

New creates a new Generator instance, based on conf.

func (*Generator) FetchItems added in v0.4.0

func (g *Generator) FetchItems(f Feed) (items []Item, err error)

FetchItems downloads a feed and tries to find any items in it.

func (*Generator) FilterStats

func (g *Generator) FilterStats() FilterStats

FilterStats returns a FilterStats struct with the current state of the internal bloom filter.

func (*Generator) NewItems

func (g *Generator) NewItems(f Feed) (items []Item, err error)

NewItems downloads a feed, tries to find any items and filter out the ones that has already been seen before.

type Item

type Item struct {
	Title   string
	Url     string
	Content string // optional
}

Item represents a single news item in a feed.

type Parser

type Parser struct {
	Rule string // Regexp rule for gragging items' title/url fields in a feed body
	Host string // Optional prefix the item urls with this host
}

Parser contains a custom regexp rule for parsing non- atom/rss/json feeds.

type Settings

type Settings struct {
	Output   string // Dir to output the feeds and internal bloom filter
	Template string // Filepath to custom HTML template
	MaxDays  int    // Max amount of days to keep generated pages for
	MaxItems int    // Max amount of items per feed and per day
	Timeout  int    // Max time in seconds when trying to download a feed
	Jitter   int    // Time in seconds used for randomising rate limits.
	Verbose  bool   // Verbose, debug output
}

Settings contains the general Generator settings.

type TemplateFeed added in v0.4.0

type TemplateFeed struct {
	Conf  Feed   // Basic config for the feed
	Items []Item // Any parsed and filtered items
	Error error  // Error returned when trying to download/parse the feed
}

TemplateFeed contains a feed and it's parsed output (items or an error).

type TemplateGenerator added in v0.4.0

type TemplateGenerator struct {
	Name    string
	Version string
	Source  string
}

TemplateGenerator contains the basic info for this generator.

type TemplateVars added in v0.4.0

type TemplateVars struct {
	Today     time.Time         // Current time
	Generator TemplateGenerator // Basic generator info
	Feeds     []TemplateFeed    // List of feeds and their config, items and errors
}

TemplateVars is a set of basic info that can be provided when executing/writing a template.

func NewTemplateVars added in v0.4.0

func NewTemplateVars() TemplateVars

NewTemplateVars creates a new instance and adds current time and generator info to it. The Feeds field will be empty and has to be manually updated.

Jump to

Keyboard shortcuts

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