Documentation
¶
Index ¶
- Constants
- Variables
- func ParseFeedTermIDs(s string) []int
- func RegisterAdminRoutes(r modulekit.Mux, c *FeedController, admin func(http.Handler) http.Handler)
- func Wire(d modulekit.Deps) modulekit.Parts
- type EntFeedRepository
- func (r *EntFeedRepository) CreateFeed(ctx context.Context, f Feed) (id int, err error)
- func (r *EntFeedRepository) DeleteFeed(ctx context.Context, id int) error
- func (r *EntFeedRepository) FeedByID(ctx context.Context, id int) (*Feed, error)
- func (r *EntFeedRepository) FeedByPath(ctx context.Context, path string) (*Feed, error)
- func (r *EntFeedRepository) Feeds(ctx context.Context) ([]Feed, error)
- func (r *EntFeedRepository) UpdateFeed(ctx context.Context, f Feed) error
- type Feed
- type FeedController
- func (c *FeedController) FeedDelete(w http.ResponseWriter, r *http.Request)
- func (c *FeedController) FeedEdit(w http.ResponseWriter, r *http.Request)
- func (c *FeedController) FeedFallback(w http.ResponseWriter, r *http.Request) bool
- func (c *FeedController) FeedList(w http.ResponseWriter, r *http.Request)
- func (c *FeedController) FeedNew(w http.ResponseWriter, r *http.Request)
- func (c *FeedController) FeedSave(w http.ResponseWriter, r *http.Request)
- type FeedFieldMap
- type FeedFieldMaps
- type FeedFormat
- type FeedRepository
- type FeedService
- func (s *FeedService) Delete(ctx context.Context, id int) error
- func (s *FeedService) FeedByID(ctx context.Context, id int) (*Feed, error)
- func (s *FeedService) FeedByPath(ctx context.Context, path string) *Feed
- func (s *FeedService) Feeds(ctx context.Context) ([]Feed, error)
- func (s *FeedService) Nodes(ctx context.Context, f Feed, now time.Time) (modulekit.Nodes, error)
- func (s *FeedService) Save(ctx context.Context, f Feed) (int, error)
Constants ¶
const FeedMaxItems = 500
FeedMaxItems - the most items a feed may emit (Dzen takes up to 500 per upload).
Variables ¶
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).
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.
var FeedFormats = []FeedFormat{FeedFormatDzen, FeedFormatRSS}
FeedFormats - every feed format, for the admin form.
Functions ¶
func ParseFeedTermIDs ¶
ParseFeedTermIDs - positive integers from a comma/space separated list.
func RegisterAdminRoutes ¶
RegisterAdminRoutes registers the feeds admin behind admin (sign-in and the admin permission); the feeds themselves are served by FeedController.FeedFallback at their paths.
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 ¶
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 ¶
FeedByID - the feed with its field maps (ErrEntityNotFound - none).
func (*EntFeedRepository) FeedByPath ¶
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 ¶
HasContentType - whether the feed includes contentType.
func (Feed) TermIDsText ¶
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 ¶
func NewFeedController(base *modulekit.BaseController, feeds *FeedService, teasers modulekit.TeaserBuilder, site modulekit.SiteInformationRepository, contentTypes modulekit.ContentTypeService, imageStyles modulekit.ImageStyleService) *FeedController
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) 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.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
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). |