internal

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeneratorName    string = "feedloggr"
	GeneratorVersion string = "v0.5.0"
	GeneratorLink    string = "https://code.larus.se/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

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

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

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 TemplateVars) error

WriteTemplate executes a loaded template (using provided vars) and writes the resulting output to a file.

Types

type Conf

type Conf struct {
	Settings     Settings // General settings
	PipeCommands []string // List of commands to pipe data to the template
	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 // User-defined title
	Link   string // Link to the page for finding news items
	Regexp string `yaml:",omitempty"` // Custom parsing rule, for finding non-feed items
}

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

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

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

New creates a new Generator instance, based on conf.

func (*Generator) FetchItems

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
	Link    string
	Content string // optional
}

Item represents a single news item in a feed.

type Settings

type Settings struct {
	Output   string // Directory where the feed pages will be saved
	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

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

type TemplateGenerator struct {
	Name    string
	Version string
	Link    string
}

TemplateGenerator contains the basic info for this generator.

type TemplateVars

type TemplateVars map[string]any

TemplateVars is a map of any extra info that can be provided when executing a template.

func LoadTemplate

func LoadTemplate(cmds []string, timeout int) (tmpl *html.Template, vars TemplateVars, err error)

LoadTemplates tries to parse "template.html" from dir (or use a builtin default), adds some extra helper functions (see TemplateFuncs) and sets up a map of template variables (with optional data from executing cmds, with timeout). Default variables: today (timestamp), generator name/version/link.

Jump to

Keyboard shortcuts

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