feeds

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const FeedMaxItems = 500

FeedMaxItems - the most items a feed may emit (Dzen takes up to 500 per upload).

Variables

View Source
var (
	ErrFeedLabel        = errors.New("feed label is required")
	ErrFeedPath         = errors.New("feed path: latin letters, digits, - _ . /")
	ErrFeedPathTaken    = errors.New("feed path is taken")
	ErrFeedContentTypes = errors.New("feed needs at least one content type")
	ErrFeedFieldMap     = errors.New("feed field map refers to a missing or unsuitable field")
)

Feed errors (the admin form shows each as its own message).

View Source
var Assets embed.FS

Assets - the module's templates/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.

FeedFormats - every feed format, for the admin form.

Functions

func ParseFeedTermIDs

func ParseFeedTermIDs(s string) []int

ParseFeedTermIDs - positive integers from a comma/space separated list.

func RegisterAdminRoutes

func RegisterAdminRoutes(r modulekit.Mux, c *FeedController, admin func(http.Handler) http.Handler)

RegisterAdminRoutes registers the feeds admin behind admin (sign-in and the admin permission); the feeds themselves are served by FeedController.FeedFallback at their paths.

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the module's service, controller, admin routes and feed pages (the 404-path fallback) (modulekit); an enabled feed's address is the module's (AddPathOwner).

Types

type EntFeedRepository

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

EntFeedRepository - feeds / feed_field_maps, on the module's own ent schema (ent/).

func NewFeedRepository

func NewFeedRepository(db *sql.DB) *EntFeedRepository

NewFeedRepository - the feeds' repository on db.

func (*EntFeedRepository) CreateFeed

func (r *EntFeedRepository) CreateFeed(ctx context.Context, f Feed) (id int, err error)

CreateFeed stores f with its field maps; returns its ID.

func (*EntFeedRepository) DeleteFeed

func (r *EntFeedRepository) DeleteFeed(ctx context.Context, id int) error

DeleteFeed deletes the feed with its field maps.

func (*EntFeedRepository) FeedByID

func (r *EntFeedRepository) FeedByID(ctx context.Context, id int) (*Feed, error)

FeedByID - the feed with its field maps (ErrEntityNotFound - none).

func (*EntFeedRepository) FeedByPath

func (r *EntFeedRepository) FeedByPath(ctx context.Context, path string) (*Feed, error)

FeedByPath - the feed at path, with its field maps (ErrEntityNotFound - none).

func (*EntFeedRepository) Feeds

func (r *EntFeedRepository) Feeds(ctx context.Context) ([]Feed, error)

Feeds - every feed with its field maps, by label.

func (*EntFeedRepository) UpdateFeed

func (r *EntFeedRepository) UpdateFeed(ctx context.Context, f Feed) error

UpdateFeed - see FeedRepository.UpdateFeed.

type Feed

type Feed struct {
	ID     int
	Label  string
	Path   string // URL path without the leading "/", e.g. "feeds/dzen.xml"
	Format FeedFormat
	Status int // 1 - served, 0 - off
	// ContentTypes - machine names of the types whose materials go in.
	ContentTypes []string
	// TermIDs - only materials tagged with any of these terms (none -
	// every material of ContentTypes).
	TermIDs []int
	// ItemLimit - at most this many items (1…FeedMaxItems).
	ItemLimit int
	// Days - items created within this many days (0 - the format's
	// own window, FeedFormat.DefaultDays).
	Days int
	// Title/Description/Language - the channel's texts (empty - the
	// site's name, slogan and language).
	Title       string
	Description string
	Language    string
	// ImageStyle - the image style for the cover and the images inside
	// the text ("" - the originals). Dzen takes only JPEG/GIF/PNG.
	ImageStyle string
	FieldMaps  FeedFieldMaps
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Feed - an XML feed of the site's materials for an aggregator (feeds module, /admin/config/feeds): which materials (content types, optional terms, count, age), the format served at Path and, per content type, which fields give the text, cover and category (FieldMaps).

func (Feed) HasContentType

func (f Feed) HasContentType(contentType string) bool

HasContentType - whether the feed includes contentType.

func (Feed) TermIDsText

func (f Feed) TermIDsText() string

TermIDsText - TermIDs comma-separated (for storage and the form).

type FeedController

type FeedController struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

FeedController - the module's pages: the feeds at their paths (Fallback) and their admin (/admin/config/feeds).

func NewFeedController

NewFeedController creates the module's controller on base.

func (*FeedController) FeedDelete

func (c *FeedController) FeedDelete(w http.ResponseWriter, r *http.Request)

FeedDelete handles POST /admin/config/feeds/{id}/delete.

func (*FeedController) FeedEdit

func (c *FeedController) FeedEdit(w http.ResponseWriter, r *http.Request)

FeedEdit renders GET /admin/config/feeds/{id}.

func (*FeedController) FeedFallback

func (c *FeedController) FeedFallback(w http.ResponseWriter, r *http.Request) bool

FeedFallback serves a feed of the feeds module (/admin/config/feeds) at its path: its materials as XML in its format. Returns false when the path isn't an enabled feed, so the next fallback runs.

func (*FeedController) FeedList

func (c *FeedController) FeedList(w http.ResponseWriter, r *http.Request)

FeedList renders GET /admin/config/feeds.

func (*FeedController) FeedNew

func (c *FeedController) FeedNew(w http.ResponseWriter, r *http.Request)

FeedNew renders GET /admin/config/feeds/new.

func (*FeedController) FeedSave

func (c *FeedController) FeedSave(w http.ResponseWriter, r *http.Request)

FeedSave handles POST /admin/config/feeds (new) and POST /admin/config/feeds/{id}.

type FeedFieldMap

type FeedFieldMap struct {
	ContentType   string
	BodyField     string
	ImageField    string
	CategoryField string
}

FeedFieldMap - for one content type of a feed: the fields giving an item's text, cover and category, by machine name ("" - BodyField: the type's body field; ImageField/CategoryField: none).

type FeedFieldMaps

type FeedFieldMaps []FeedFieldMap

FeedFieldMaps - a feed's field maps, one per content type (Feed.FieldMaps).

func (FeedFieldMaps) For

func (ms FeedFieldMaps) For(contentType string) FeedFieldMap

For - the map of contentType (zero value - none set).

type FeedFormat

type FeedFormat string

FeedFormat - the XML a feed produces.

const (
	// FeedFormatRSS - plain RSS 2.0 (title, link, summary, cover).
	FeedFormatRSS FeedFormat = "rss"
	// FeedFormatDzen - RSS 2.0 per Dzen's export spec: full text in
	// content:encoded, cover in enclosure, category.
	FeedFormatDzen FeedFormat = "dzen"
)

func ParseFeedFormat

func ParseFeedFormat(f string) FeedFormat

ParseFeedFormat - f if known, else FeedFormatRSS.

func (FeedFormat) DefaultDays

func (f FeedFormat) DefaultDays() int

DefaultDays - how many days back a feed of this format goes when it sets none: Dzen takes items up to 7 days old; plain RSS has no window.

func (FeedFormat) Label

func (f FeedFormat) Label() string

Label - the format's name in the admin (untranslated: shown through {{t .Label}}).

type FeedRepository

type FeedRepository interface {
	Feeds(ctx context.Context) ([]Feed, error)
	FeedByID(ctx context.Context, id int) (*Feed, error)
	FeedByPath(ctx context.Context, path string) (*Feed, error)
	CreateFeed(ctx context.Context, f Feed) (int, error)
	// UpdateFeed saves f and replaces its FieldMaps.
	UpdateFeed(ctx context.Context, f Feed) error
	DeleteFeed(ctx context.Context, id int) error
}

FeedRepository - the feeds' storage: the list, one by ID or by path, creating, updating and deleting one with its field maps.

type FeedService

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

FeedService - the feeds module: feed settings and the nodes each feed includes.

func NewFeedService

func NewFeedService(repo FeedRepository, nodes modulekit.NodesRepository, contentTypes feedContentTypes, pathOwner func(ctx context.Context, path string) (string, error), logger *slog.Logger) *FeedService

NewFeedService - the feeds of repo, their content from nodes and contentTypes; pathOwner tells what else answers an address.

func (*FeedService) Delete

func (s *FeedService) Delete(ctx context.Context, id int) error

Delete deletes the feed id.

func (*FeedService) FeedByID

func (s *FeedService) FeedByID(ctx context.Context, id int) (*Feed, error)

FeedByID - the feed, enabled or not (ErrEntityNotFound - none).

func (*FeedService) FeedByPath

func (s *FeedService) FeedByPath(ctx context.Context, path string) *Feed

FeedByPath - the enabled feed at path (nil - none, or the feeds can't be read: logged).

func (*FeedService) Feeds

func (s *FeedService) Feeds(ctx context.Context) ([]Feed, error)

Feeds - every feed, by label.

func (*FeedService) Nodes

func (s *FeedService) Nodes(ctx context.Context, f Feed, now time.Time) (modulekit.Nodes, error)

Nodes - the nodes feed f emits now: its types and terms, within its day window (or the format's), newest first, at most ItemLimit.

func (*FeedService) Save

func (s *FeedService) Save(ctx context.Context, f Feed) (int, error)

Save validates and creates (ID == 0) or updates f; returns its ID.

Directories

Path Synopsis
ent
Package ent - the feeds module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
Package ent - the feeds module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
schema
Package schema - the feeds module's own ent schema: its tables, apart from the core's.
Package schema - the feeds module's own ent schema: its tables, apart from the core's.
Package manifest declares the feeds module (its registry entry).
Package manifest declares the feeds module (its registry entry).

Jump to

Keyboard shortcuts

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