core

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

package core implements the structs and other necessary resources for storing and managing feeds and pages

Index

Constants

This section is empty.

Variables

View Source
var (
	Header string
	Footer string
)

the Header and Footer of feeds.gmi. set in Init, either to the contents of header.gmi or to the default string

View Source
var (
	Version = "Unknown"
	Commit  = "Unknown"
)

These variables are set by the linker. They can be modified in the Makefile.

View Source
var Data = FullData{
	FeedsMu: &sync.RWMutex{},
	PagesMu: &sync.RWMutex{},
}

Global instance of FullData

View Source
var HistoryDays time.Time

Number of days of history to keep

View Source
var Timeout int

Timeout for requests

Functions

func Init

func Init(dataPath string, localizer *localizations.Localizer, days int) error

have to do this instead of the automatically called init() because initialization stuff requires parsing of command line args first

func TranslateString added in v1.7.0

func TranslateString(template, localizerTag string, replacements *localizations.Replacements) string

TranslateString takes a template string, a localizer tag, and a localizer replacement set and will get the localized string from the localizer tag, replace everything using the localizer replacements, and then substitute that string into the template string.

func TranslateStringLocalizer added in v1.7.0

func TranslateStringLocalizer(localizer *localizations.Localizer, template, localizerTag string, replacements *localizations.Replacements) string

TranslateStringLocalizer takes a localizations.Localizer, template string, a localizer tag, and a localizer replacement set and will get the localized string from the localizer tag, replace everything using the localizer replacements, and then substitute that string into the template string. Should not be used once core.Init() is called, instead use TranslateString().

Types

type Feed

type Feed struct {
	Title    string    `json:"title,omitempty"`
	Link     string    `json:"link,omitempty"`     // link to the human-readable page for the feed. same as FeedLink for gemini feeds.
	FeedLink string    `json:"feedlink,omitempty"` // link to the feed itself.
	Updated  time.Time `json:"updated,omitempty"`
	Items    []*Item   `json:"items,omitempty"`
}

Feed holds all the necessary fields when storing a feed

func GofeedConvert

func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error)

gofeedConvert converts a gofeed.Feed into a Feed struct

func (*Feed) Len

func (f *Feed) Len() int

Len returns the length of Items.

func (*Feed) Less

func (f *Feed) Less(i, j int) bool

Less compares Published of Items[i], Items[k] and returns true if Items[i] is before Items[j].

func (*Feed) Swap

func (f *Feed) Swap(i, j int)

Swap swaps Items[i] and Items[j].

type FullData

type FullData struct {
	Feeds map[string]*Feed `json:"feeds,omitempty"`
	Pages map[string]*Page `json:"pages,omitempty"`

	FeedsMu *sync.RWMutex `json:"-"`
	PagesMu *sync.RWMutex `json:"-"`
}

FullData is used for both reading from json and for storing the global feeds map. contains read mutexes so concurrency can be used.

func (*FullData) InsertFeed

func (d *FullData) InsertFeed(new *Feed, remote string)

InsertFeed will insert or update a core.Feed in a core.FullData

func (*FullData) InsertPage

func (d *FullData) InsertPage(new *Page, remote string)

InsertPage will insert or update a core.Page in a core.FullData

func (*FullData) Lock

func (j *FullData) Lock()

Lock locks both feed and page mutexes.

func (*FullData) RLock

func (j *FullData) RLock()

RLock read-locks both feed and page mutexes.

func (*FullData) RUnlock

func (j *FullData) RUnlock()

RUnlock read-unlocks both feed and page mutexes.

func (*FullData) Unlock

func (j *FullData) Unlock()

Unlock unlocks both feed and page mutexes.

func (*FullData) WriteFeed

func (d *FullData) WriteFeed(dataPath string) error

func (*FullData) WriteJSON

func (d *FullData) WriteJSON(dataPath string) error

WriteJSON writes a FullData to disk

func (*FullData) WriteSubs

func (d *FullData) WriteSubs(dataPath string) error

type Item

type Item struct {
	Title     string    `json:"title,omitempty"` // if empty, use Link as title
	Content   string    `json:"content,omitempty"`
	Link      string    `json:"link,omitempty"`
	Published time.Time `json:"updated,omitempty"`
}

Item is a single item from a subscripton

type Page

type Page struct {
	Title   string    `json:"title,omitempty"`
	Link    string    `json:"link,omitempty"`
	Updated time.Time `json:"updated,omitempty"`
	Hash    string    `json:"hash,omitempty"`
}

Page holds all the necessary fields when storing a page being watched for changes.

type PageEntries

type PageEntries struct {
	Entries []*PageEntry
}

PageEntries is reverse chronological list of entries used when generating subs.

func (*PageEntries) Len

func (e *PageEntries) Len() int

Len returns the length of Entries

func (*PageEntries) Less

func (e *PageEntries) Less(i, j int) bool

Less compares the Published if Entries[i], Entries[j] and returns true if Entries[i] is /after/ Entries[j] (for reverse chronological sorting)

func (*PageEntries) Swap

func (e *PageEntries) Swap(i, j int)

Swap swaps Entries[i] and Entries[j]

type PageEntry

type PageEntry struct {
	Prefix    string // whatever goes before the post title to identify the feed.
	Title     string // article/entry title
	URL       string
	Published time.Time
}

PageEntry is a single item on a subscriptions page. It is used for both feeds and pages.

Jump to

Keyboard shortcuts

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