enbypub

package
v0.0.0-...-22f04e9 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var SlugMakeDash = regexp.MustCompile(`[^[:alnum:]]+`)
View Source
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.

View Source
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

func ContentTypeFromExtension(ext string) string

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.

func Sluggify

func Sluggify(in *string) *string

func Titlenate

func Titlenate(fn *string) *string

Types

type Aggregator

type Aggregator interface {
	Init(*Feed, *Generator) error
	AddText(*Text) error
	Close() error
}

type Aggregators

type Aggregators []Aggregator

func (*Aggregators) UnmarshalYAML

func (a *Aggregators) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

type AtomAggregator

type AtomAggregator struct {
	MinPath *uint `yaml:",omitempty"`
	MaxPath *uint `yaml:",omitempty"`
}

AtomAggregator provides an Atom feed XML document intended for consumption with an Atom feed reader.

type Attribute

type Attribute string

type ContentTypesExtraT

type ContentTypesExtraT struct {
	FromExtension map[string]string
}
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) Add

func (F *Feed) Add(T *Text) error

func (Feed) CanonicalStructure

func (F Feed) CanonicalStructure() (*FeedStructure, error)

func (*Feed) Close

func (F *Feed) Close() error

func (*Feed) Filename

func (F *Feed) Filename(T *Text) (string, error)

func (Feed) Get

func (F Feed) Get(a Attribute, T *Text) (string, error)

func (*Feed) GetPath

func (f *Feed) GetPath(id string) string

GetPath gets the whole canonical path plus filename for a Text id

func (*Feed) Path

func (F *Feed) Path(T *Text) ([]string, 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 Feeds

type Feeds map[uuid.UUID]*Feed

func LoadFeedsFromFile

func LoadFeedsFromFile(fn string, g *Generator) (Feeds, error)

func (Feeds) Scan

func (f Feeds) Scan(t Texts) error

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) As

func (f *File) As(contentType *string) *File

As sets the intended content type of the output File

func (*File) At

func (f *File) At(modtime *time.Time) *File

At sets the intended modification time of the output File.

func (*File) Close

func (f *File) Close() error

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) Err

func (f *File) Err() error

Err returns the most recent error this File encountered.

func (*File) From

func (f *File) From(path string) error

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.

func (*File) ReadFrom

func (f *File) ReadFrom(r io.Reader) (int64, error)

ReadFrom wraps the underlying os.*File.ReadFrom method

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek wraps the underlying os.*File.Seek method

func (*File) Sync

func (f *File) Sync() error

Sync wraps the underlying os.*File.Sync method

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate wraps the underlying os.*File.Truncate method

func (*File) Write

func (f *File) Write(b []byte) (int, error)

Write wraps the underlying os.*File.Write method

func (*File) WriteAt

func (f *File) WriteAt(b []byte, off int64) (int, error)

WriteAt wraps the underlying os.*File.WriteAt method

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString wraps the underlying os.*File.WriteString method

type Generator

type Generator struct {
	Root      string
	Files     map[string]*File
	Templates *html.Template
}

func NewGenerator

func NewGenerator(root string) (*Generator, error)

func (*Generator) Create

func (g *Generator) Create(path ...string) (f *File)

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.

func (*Generator) Manifest

func (g *Generator) Manifest() (m []string)

Manifest returns a list of each created file.

func (*Generator) OSPath

func (g *Generator) OSPath(path string) string

func (*Generator) Template

func (g *Generator) Template(template string, data any, mtime *time.Time, path ...string) error

Template is complicated

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)

func (*IndexAggregator) Init

func (ia *IndexAggregator) Init(f *Feed, g *Generator) error

type IndexAggregatorContent

type IndexAggregatorContent struct {
	Meta  *MetaT
	Feed  *Feed
	Index []*Text
}

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

func Meta

func Meta() (M *MetaT)

func (*MetaT) Generator

func (M *MetaT) Generator() string

Generator returns a string describing the specific build of either enbypub or whatever is importing it.

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

func (PathComponent) Get

func (pc PathComponent) Get(F *Feed, T *Text) (string, error)

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

func (*RSSAggregator) Init

func (a *RSSAggregator) Init(f *Feed, g *Generator) error

type RSSAggregatorContent

type RSSAggregatorContent struct {
	Meta  *MetaT
	Feed  *Feed
	Index []*Text
}

type RSSDate

type RSSDate time.Time

RSSDate formats a time.Time as an RFC 1123 time.

func (*RSSDate) MarshalText

func (d *RSSDate) MarshalText() ([]byte, error)

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 RSSFeedItem struct {
	Title       string     `xml:"title"`
	Link        string     `xml:"link"`
	Description string     `xml:"description,omitempty"`
	Author      string     `xml:"author,omitempty"`
	PubDate     *RSSDate   `xml:"pubDate,omitempty"`
	Id          *uuid.UUID `xml:"guid,omitempty"`
}

type RSSGUID

type RSSGUID struct {
	*uuid.UUID `xml:"guid"`
	PermaLink  bool `xml:"isPermaLink,attr"`
}

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 LoadTextFromFile(fn string) (*Text, error)

func (*Text) ChecksumMatch

func (T *Text) ChecksumMatch() bool

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) Get

func (T *Text) Get(a Attribute) (string, error)

func (*Text) HTML

func (T *Text) HTML() template.HTML

HTML returns an HTML fragment for the document body

func (*Text) IsModified

func (T *Text) IsModified() bool

IsModified returns true if the Modified attribute is at least 5 minutes after the Created attribute

func (Text) IsTagged

func (T Text) IsTagged(tag ...string) bool

func (*Text) Process

func (T *Text) Process() error

func (*Text) String

func (T *Text) String() string

func (*Text) UpdateFile

func (T *Text) UpdateFile() error

type Texts

type Texts map[uuid.UUID]*Text

func (Texts) Get

func (t Texts) Get(id string) *Text

Jump to

Keyboard shortcuts

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