Documentation ¶
Index ¶
- Constants
- Variables
- func ContentTypeFromExtension(ext string) string
- func Sluggify(in *string) *string
- func Titlenate(fn *string) *string
- type Aggregator
- type Aggregators
- type AtomAggregator
- type Attribute
- type ContentTypesExtraT
- type Feed
- func (F *Feed) Add(T *Text) error
- func (F Feed) CanonicalStructure() (*FeedStructure, error)
- func (F *Feed) Close() error
- func (F *Feed) Filename(T *Text) (string, error)
- func (F Feed) Get(a Attribute, T *Text) (string, error)
- func (f *Feed) GetPath(id string) string
- func (F *Feed) Path(T *Text) ([]string, error)
- func (F *Feed) SortByCreatedAscending()
- func (F *Feed) SortByCreatedDescending()
- type FeedStructure
- type Feeds
- type File
- func (f *File) As(contentType *string) *File
- func (f *File) At(modtime *time.Time) *File
- func (f *File) Close() error
- func (f *File) Err() error
- func (f *File) From(path string) error
- func (f *File) ReadFrom(r io.Reader) (int64, error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Sync() error
- func (f *File) Truncate(size int64) error
- func (f *File) Write(b []byte) (int, error)
- func (f *File) WriteAt(b []byte, off int64) (int, error)
- func (f *File) WriteString(s string) (int, error)
- type Generator
- type IndexAggregator
- type IndexAggregatorContent
- type MetaT
- type PathComponent
- type RSSAggregator
- type RSSAggregatorContent
- type RSSDate
- type RSSFeedDocument
- type RSSFeedItem
- type RSSGUID
- type RobotsExcludeAggregator
- type SearchAggregator
- type SitemapAggregator
- type Text
- type Texts
Constants ¶
const ( TextAttributeSlug = Attribute("slug") TextAttributeId = Attribute("id") TextAttributeTemplate = Attribute("template") TextAttributeYear = Attribute("year") TextAttributeMonth = Attribute("month") TextAttributeDay = Attribute("day") TextAttributeDayOfWeek = Attribute("dow") TextAttributeYMD = Attribute("date") FeedAttributeSlug = Attribute("feedslug") FeedAttributeId = Attribute("feedid") )
Variables ¶
var SlugMakeDash = regexp.MustCompile(`[^[:alnum:]]+`)
var TextMetadataDelimiter = regexp.MustCompile(`(?m:^---+[\r\n]+)`)
TextMetadataDelimiter indicates the text boundary between metadata and body in a Text. This is set to the traditional three (or more) dashes typically used for Markdown front matter.
var TextUnlikelyCreationDate = must1(time.Parse(time.RFC3339, "1993-08-31T23:59:59Z"))
TextUnlikelyCreationDate represents an arbitrary threshold where filesystem times before this point are not trusted. If enbypub examines a file with a modification time before this time, that modification time will be ignored and will instead be substituted with the current time.
Functions ¶
func ContentTypeFromExtension ¶
ContentTypeFromExtension returns a (guessed) content-type suitable for an HTTP header based on a given file extension, or an empty string. If ContentTypesExtra has been set, it will be referenced first.
Types ¶
type Aggregator ¶
type Aggregators ¶
type Aggregators []Aggregator
func (*Aggregators) UnmarshalYAML ¶
func (a *Aggregators) UnmarshalYAML(unmarshal func(interface{}) error) (err error)
type AtomAggregator ¶
AtomAggregator provides an Atom feed XML document intended for consumption with an Atom feed reader.
type ContentTypesExtraT ¶
var ContentTypesExtra *ContentTypesExtraT
type Feed ¶
type Feed struct { // Tags specifies the list of tags that will be scanned to add content to this Feed Tags []string `yaml:",omitempty"` // CanonicalPath specifies the location where a Text will be publicly reachable relative to a public root // If empty/nil, this feed does not produce output files CanonicalPath []PathComponent `yaml:",omitempty"` // MaximumCount, if specified, limits the feed to the MaximumCount most recent Texts according to their Created time // (not yet implemented) MaximumCount *uint `yaml:",omitempty"` // MaximumAge, if specified, limits the feed to the Texts with a Created time no older than MaximumAge // (not yet implemented) MaximumAge *time.Duration `yaml:",omitempty"` // Id is a randomly generated UUID for this Feed Id *uuid.UUID `yaml:",omitempty"` // Slug is a URL-friendly reference to this Feed Slug *string `yaml:",omitempty"` // Aggregators is a list of zero or more aggregation methods, like the Feed Index or RSS // (not yet implemented) Aggregators Aggregators `yaml:",omitempty"` // Index contains a list of every Text that is published to this Feed // Note that this list is not neccessarily orderd in any particular way; the Index must be sorted if that's desired Index []*Text `yaml:"-"` // DefaultTemplate set a default "Style" value for a Text if one is not set DefaultTemplate *string `yaml:",omitempty"` // contains filtered or unexported fields }
func (Feed) CanonicalStructure ¶
func (F Feed) CanonicalStructure() (*FeedStructure, error)
func (*Feed) SortByCreatedAscending ¶
func (F *Feed) SortByCreatedAscending()
Sorts the Feed Index by the Created date of each Text, with the oldest first.
func (*Feed) SortByCreatedDescending ¶
func (F *Feed) SortByCreatedDescending()
Sorts the Feed Index by the Created date of each Text, with the newest first.
type FeedStructure ¶
type FeedStructure struct { // Segments is a map of each distinct path segment and the Texts under that segment Segments map[string][]*Text // Files is the generated final content path for each Text Files map[string]*Text }
FeedStructure describes the content structure published to the feed.
func (*FeedStructure) GetPath ¶
func (fs *FeedStructure) GetPath(id string) string
GetPath scans the file map for the specified uuid and returns the published Feed location for that Text if found, or an empty string
type File ¶
type File struct {
// contains filtered or unexported fields
}
File holds an open os.File pointer representing a pending piece of written content.
func (*File) Close ¶
Close calls the underlying os.*File.Close() method, then sets the modification time specified with At(), if any. Close is always safe to call, even if the original file open failed.
func (*File) From ¶
From reads the File contents from path. If the File's content type has not been set yet, it's guessed from the extension of path (if any). The File is Close()d.
type Generator ¶
func NewGenerator ¶
func (*Generator) Create ¶
Create returns a *File for writing that has many of the semantics of an os.*File. The method is intended to be chained together with other File methods. path may be a single single composed path (eg `Create("directory/file.txt")`) or a series of path components (eg `Create("directory", "file.txt")`) or a slice of path components (eg `Create(pathSlice...)`). The returned *File may not be ready to use. Any error on opening the file to create it will be stored in the *File and returned on subsequent writes.
type IndexAggregator ¶
type IndexAggregator struct { // Kind is always "index" Kind string MinPath *int `yaml:",omitempty"` MaxPath *int `yaml:",omitempty"` Paginate *int `yaml:",omitempty"` // TODO Filename *string `yaml:",omitempty"` Template *string `yaml:",omitempty"` Sort *string `yaml:",omitempty"` // contains filtered or unexported fields }
IndexAggregator provides an HTML article index intended for consumption with a web browser.
func (*IndexAggregator) AddText ¶
func (ia *IndexAggregator) AddText(t *Text) error
func (*IndexAggregator) Close ¶
func (ia *IndexAggregator) Close() (err error)
type IndexAggregatorContent ¶
type MetaT ¶
type MetaT struct { // Ver is the version of the enbypub package if available, or the main package Ver *string // Commit is either the abbreviated git sha-1 commit id, or the whole revision if it doesn't look like a git commit Commit *string // BuildTime is the reported build time of the main package BuildTime *time.Time // Package is the enbypub library package path Package string // MainPackage is the main package path (ie the repo importing this package) MainPackage string }
MetaT is a placeholder for metadata about the enbypub library generating the content
type PathComponent ¶
type PathComponent struct { String *string `yaml:",omitempty"` Attr *Attribute `yaml:",omitempty"` }
A PathComponent describes a static string, an attribute of a published Text, or an attribute of the Feed
type RSSAggregator ¶
type RSSAggregator struct { // Kind is always "rss" Kind string MinPath *int `yaml:",omitempty"` MaxPath *int `yaml:",omitempty"` Filename *string `yaml:",omitempty"` // Title, if provided, is used as the RSS feed title value. Otherwise a default is made from the Feed slug. Title *string `yaml:",omitempty"` // Description, if provided, is used as the RSS description. Otherwise a default is made from the Feed slug. Description *string `yaml:",omitempty"` // PublicBaseURL is used to calculate the public URLs in this feed. PublicBaseURL string // TTL is the minimum recommended refresh speed for consumers. TTL *time.Duration `yaml:",omitempty"` // contains filtered or unexported fields }
RSSAggregator provides an HTML article index intended for consumption with a web browser.
func (*RSSAggregator) AddText ¶
func (a *RSSAggregator) AddText(t *Text) error
func (*RSSAggregator) Close ¶
func (a *RSSAggregator) Close() error
type RSSAggregatorContent ¶
type RSSFeedDocument ¶
type RSSFeedDocument struct { XMLName xml.Name `xml:"rss"` NS string `xml:"xmlns:atom,attr"` // always "http://www.w3.org/2005/Atom" Version string `xml:"version,attr"` // always "2.0" LastBuildDate RSSDate `xml:"channel>lastBuildDate"` Title string `xml:"channel>title,omitempty"` Link string `xml:"channel>link,omitempty"` Description string `xml:"channel>description,omitempty"` Language *language.Tag `xml:"channel>language,omitempty"` PubDate *RSSDate `xml:"channel>pubDate,omitempty"` Docs string `xml:"channel>docs,omitempty"` // always "https://www.rssboard.org/rss-specification" TTL int `xml:"channel>ttl,omitempty"` // minutes // advises clients when not to re-fetch SkipHours *[]int `xml:"channel>skipHours>hour,omitempty"` // hour of day in GMT SkipDays *[]string `xml:"channel>skipDays>day,omitempty"` // day of week Items []*RSSFeedItem `xml:"channel>item,omitempty"` // contains filtered or unexported fields }
func NewRSSFeedDocument ¶
func NewRSSFeedDocument() *RSSFeedDocument
type RSSFeedItem ¶
type RobotsExcludeAggregator ¶
type RobotsExcludeAggregator struct {
MinPath *uint `yaml:",omitempty"`
}
RobotsExcludeAggregator adds the path component to an exclusion directive in robots.txt.
type SearchAggregator ¶
type SearchAggregator struct { IndexJSONPath *string `yaml:",omitempty"` IndexHTMLPath *string `yaml:",omitempty"` IndexHTMLTemplate *string `yaml:",omitempty"` }
SearchAggregator produces a basic search index of keywords to enable a client-side search.
type SitemapAggregator ¶
type SitemapAggregator struct { }
SitemapAggregator generates a sitemap XML document intended for consumption by search engines. It also adds a pointer to this generated sitemap file in robots.txt.
type Text ¶
type Text struct { // Title specifies the title of the Text Title *string `yaml:",omitempty"` // Slug is a generated URL-friendly string usually derived from the Title Slug *string `yaml:",omitempty"` // Created indicates the time this Text was first processed by enbypub Created *time.Time `yaml:",omitempty"` // Modified indicates the time this Text was most recently processed by enbypub Modified *time.Time `yaml:",omitempty"` // Id is the unique identifier assigned to this Text on first processing Id *uuid.UUID `yaml:",omitempty"` // Template specifies what template to use for rendering this Text Template *string `yaml:",omitempty"` // Tags specifies the distrubition of this Text Tags []string `yaml:",omitempty"` // Checksum determines whether the body of the Text has been changed since last processed Checksum *string `yaml:",omitempty"` // contains filtered or unexported fields }
func LoadTextFromFile ¶
func (*Text) ChecksumMatch ¶
ChecksumMatch calculates the hash of the raw Text body. If the hash doesn't exist in the Text value, or if the calculated hash doesn't match the Text value, ChecksumMatch updates the Text value and returns false. Otherwise, it returns true.
The Checkum value of the Text should be opaque, but may match the regex:
(sha1|sha256|md5):[0-9a-f]{32,}
func (*Text) IsModified ¶
IsModified returns true if the Modified attribute is at least 5 minutes after the Created attribute