feed

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Tpl = template.Must(template.New("").Parse(`
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="data:image/x-icon;base64,AAABAAEAEBAQAAAAAAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAhFAUAVUCzAJSHhQD1PycAo6OjAFmWqADo6e0ARCPZAFdUUQDe3t4AL5E6AHvF2wBIgbAAAAAAAAAAAAAAAAAAOqqqaZmZbMyqOqNoSEhszGZmZmZmZmZmiEhIZxEXaEiZmZlnEXdpmYSEhGN3c2SEmZmZYztzaZmISEhjuyNoSJmZmWO7U2mZhISEY4iDZIRmZmZmZmZmZgYAYABgYGAABgBgZgBgBmAGYGAGBgYGAABgYGYGBgYGAGBgBgZmBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" rel="icon" type="image/x-icon" />
<title>News</title>
<style type="text/css">
html {
	padding: 0;
	margin: 0;
}
body {
	padding: 2em 0;
	margin: 0;
	font-family: sans-serif;
	font-size: 16px;
	background-color:#282828;
}
.container {
	max-width: 1024px;
	margin: 0 auto;
	text-align: center;
}
.item {
	display: block;
	font-size: 18px;
	padding: 1em 0.5em 0.5em 0.5em;
	color: #000;
	font-weight: bold;
	background: #EEE;
	border-bottom: 1px solid #ccc;
}
.tag {
	float: right;
	border: 1px solid #ccc;
	border-radius: 3px;
	padding: 5px;
	margin: -10px 0 0 5px;
    background-color: #ddd;
	font-weight: normal;
}
.item:first-child  {
	border-top: 1px solid #aaa;
}
.item:visited {
	color: #873B3B;
}
.item, .item:visited {
	text-decoration: none;
	text-align: left;
}
.item:hover, .item:active {
	text-decoration: underline;
}
.next {
    display: inline-block;
    margin: 20px auto;
    font-size: 24px;
    padding: 0.5em;
    color: #000;
    font-weight: bold;
    background: #EEE;
    border-bottom: 1px solid #ccc;
    border-radius: 5px;
    text-decoration: none;
}
.next:hover, .next:active {
	text-decoration: underline;
}
.feed {
	display: none;
}
</style>
</head>
<body>
<div class="container">{{range .Items}}
<a class="item" target="_blank" href="{{.URL}}">{{if .Tag}}<div class="tag">{{.Tag}}</div>{{end}}{{.Title}}</a>{{end}}

{{if gt .NextPage 1}}<a class="next" href="page{{.NextPage}}.html">Next</a>{{end}}

</div>
{{range $url, $title := .Feeds}}
<a class="feed" href="{{$url}}">{{$title}}</a>{{end}}

</body>
</html>`))

Tpl is the template used to render index.html and page.html files. Can be customized using -c command-line argument.

Functions

func MakeURLFetcher

func MakeURLFetcher(client *http.Client) func(URL string) (content []byte, err error)

MakeURLFetcher is the default HTTP client used to fetch feed XML. The other one is fakeURLFetcher() used for testing. There's also a retired makeCachedURLFetcher() which was using during initial phases of development and is kept in misc.go

func SetLogger

func SetLogger(logger *logrus.Logger)

SetLogger is used from main to set custom unified logger

Types

type Aggregator

type Aggregator struct {
	Items []Item // Ordered from newest to oldest. Always prepend new items.
	// Feeds is a map of URLs -> Titles for feeds. This needs to be stored somewhere so reader knows from where to fetch news
	Feeds map[string]string
	// We store item URLs so we know when something new appears
	KnownItems map[string]bool
	Directory  string
	URLFetcher func(url string) ([]byte, error)

	ItemsPerPage int
	NextPage     int
	// contains filtered or unexported fields
}

Aggregator is the core structure than fetches feeds and saves them to html

func New

func New(directory string) (*Aggregator, error)

New creates an Aggregator with default URL fetcher

func NewWithCustom

func NewWithCustom(directory string, itemsPerPage int, URLFetcher func(URL string) ([]byte, error)) (*Aggregator, error)

NewWithCustom allows for creating customized Aggregators such as custom URL fetcher for testing or with custom http.client

func (*Aggregator) Update

func (agg *Aggregator) Update() (err error)

Update load feeds from index.html, fetches items from them and save everything back to index.html. Also generates pageX.html if necessary.

type CustomRSSTranslator

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

CustomRSSTranslator is currently used to instruct mmcdole/gofeed to parse <comments> as item link in Reddit's feed

func NewCustomRSSTranslator

func NewCustomRSSTranslator() *CustomRSSTranslator

NewCustomRSSTranslator creates a new XML feed translator to be used by our instance of mmcdole/gofeed

func (*CustomRSSTranslator) Translate

func (ct *CustomRSSTranslator) Translate(feed interface{}) (*gofeed.Feed, error)

Translate is called by mmcdole/gofeed

type Item

type Item struct {
	Title string
	URL   string
	Tag   string
}

Item represents a link retrieved from feed

Jump to

Keyboard shortcuts

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