Documentation ¶
Index ¶
- Variables
- func EstimateReadingTime(content string) string
- func GenerateETag(content string) string
- func IsValidPostPath(path string) bool
- func PostPathID(postType, slug string) string
- type Author
- type AuthorLink
- type CacheStore
- type DefaultMarkdownProcessor
- type DownCache
- func (cm *DownCache) Create(ctx context.Context, post *Post) (*Post, error)
- func (cm *DownCache) Delete(ctx context.Context, postType, slug string) error
- func (cm *DownCache) Get(ctx context.Context, postType, slug string) (*Post, error)
- func (cm *DownCache) Search(ctx context.Context, filter FilterOptions) ([]*Post, int, error)
- func (cm *DownCache) SyncAll(ctx context.Context) error
- func (cm *DownCache) Update(ctx context.Context, oldType, oldSlug string, post *Post) error
- type FilterOptions
- type FilterType
- type FrontmatterFormat
- type KeyValueFilter
- type LocalMarkdownFS
- func (fs *LocalMarkdownFS) Delete(_ context.Context, postType, slug string) error
- func (fs *LocalMarkdownFS) Move(_ context.Context, oldType, oldSlug, newType, newSlug string) error
- func (fs *LocalMarkdownFS) Read(_ context.Context, postType, slug string) (*Post, error)
- func (fs *LocalMarkdownFS) Walk(ctx context.Context) (<-chan *Post, <-chan error)
- func (fs *LocalMarkdownFS) Write(_ context.Context, post *Post) error
- type MarkdownFS
- type MarkdownProcessor
- type MemoryCacheStore
- func (m *MemoryCacheStore) Clear(ctx context.Context) error
- func (m *MemoryCacheStore) Close() error
- func (m *MemoryCacheStore) Create(ctx context.Context, post *Post) (*Post, error)
- func (m *MemoryCacheStore) Delete(ctx context.Context, postType, slug string) error
- func (m *MemoryCacheStore) Get(ctx context.Context, postType, slug string) (*Post, error)
- func (m *MemoryCacheStore) GetTaxonomies(ctx context.Context) ([]string, error)
- func (m *MemoryCacheStore) GetTaxonomyTerms(ctx context.Context, taxonomy string) ([]string, error)
- func (m *MemoryCacheStore) Init() error
- func (m *MemoryCacheStore) Search(ctx context.Context, options FilterOptions) ([]*Post, int, error)
- func (m *MemoryCacheStore) Update(ctx context.Context, oldType, oldSlug string, post *Post) error
- type Paginator
- type Post
- func (p *Post) FileTimeInSlug() string
- func (p *Post) HasAuthor() bool
- func (p *Post) HasFileTimeInSlug() bool
- func (p *Post) HasName() bool
- func (p *Post) HasPhoto() bool
- func (p *Post) HasProperties() bool
- func (p *Post) HasPublished() bool
- func (p *Post) HasSubtitle() bool
- func (p *Post) HasSummary() bool
- func (p *Post) HasTaxonomies() bool
- func (p *Post) HasTaxonomy(taxonomy string) bool
- func (p *Post) HasUpdated() bool
- func (p *Post) Meta() *PostMeta
- func (p *Post) PublishedDate() string
- func (p *Post) PublishedTime() time.Time
- func (p *Post) PublishedYear() int
- func (p *Post) Serialize() ([]byte, error)
- func (p *Post) SlugWithYear() string
- func (p *Post) SlugWithYearMonth() string
- func (p *Post) SlugWithYearMonthDay() string
- func (p *Post) SlugWithoutDate() string
- func (p *Post) Taxonomy(taxonomy string) []string
- type PostMeta
- type PostType
- type PostTypes
- type SlugPath
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidPostMeta = errors.New("invalid post metadata")
)
Functions ¶
func EstimateReadingTime ¶
EstimateReadingTime estimates the reading time of the content.
func GenerateETag ¶
GenerateETag generates an ETag for the content.
func IsValidPostPath ¶
func PostPathID ¶ added in v0.0.2
PostPathID returns the unique identifier for a page of the specified type and slug
Types ¶
type Author ¶
type Author struct { Username string `json:"username" yaml:"username" toml:"username"` Name string `json:"name" yaml:"name" toml:"name"` Country string `json:"country" yaml:"country" toml:"country"` Active bool `json:"active" yaml:"active" toml:"active"` Bio string `json:"bio" yaml:"bio" toml:"bio"` AvatarURL string `json:"avatarURL" yaml:"avatarURL" toml:"avatarURL"` Links []AuthorLink `json:"links" yaml:"links" toml:"links"` }
type AuthorLink ¶
type CacheStore ¶ added in v0.0.2
type CacheStore interface { // Init initializes the post store, such as creating the necessary tables or indexes. Init() error // Clear clears all data from the post store and resets the store. Clear(ctx context.Context) error // Close closes the post store. Close() error // Create creates a new post. Create(ctx context.Context, post *Post) (*Post, error) // Delete deletes a post. Delete(ctx context.Context, postType, slug string) error // Get retrieves a post by its slug. Get(ctx context.Context, postType, slug string) (*Post, error) // GetTaxonomies returns a list of taxonomies. GetTaxonomies(ctx context.Context) ([]string, error) // GetTaxonomyTerms returns a list of terms for a given taxonomy. GetTaxonomyTerms(ctx context.Context, taxonomy string) ([]string, error) // Search searches for posts based on the provided filter options. Search(ctx context.Context, opts FilterOptions) ([]*Post, int, error) // Update updates an existing post. Update(ctx context.Context, oldType, oldSlug string, post *Post) error }
type DefaultMarkdownProcessor ¶ added in v0.0.2
type DefaultMarkdownProcessor struct{}
DefaultMarkdownProcessor is the default implementation of the MarkdownProcessor interface
func (DefaultMarkdownProcessor) GenerateFrontmatter ¶ added in v0.0.2
func (d DefaultMarkdownProcessor) GenerateFrontmatter(meta *PostMeta, format FrontmatterFormat) (string, error)
type DownCache ¶
type DownCache struct {
// contains filtered or unexported fields
}
DownCache is the main entry point for the markdown cache system
func NewDownCache ¶
func NewDownCache(fs MarkdownFS, store CacheStore) *DownCache
type FilterOptions ¶
type FilterOptions struct { PageNum int // The page number to retrieve PageSize int // The number of items per page SortBy []string // The frontmatter fields to sort by. Default is ["-featured", "-published", "name] FilterAuthor string // The authors to filter by FilterProperties []KeyValueFilter // The frontmatter fields to filter by FilterTaxonomies []KeyValueFilter // The taxonomies to filter by FilterSearch string // A search string to filter by. Searches the post content, title, etc. FilterPostType PostType // The type of post to filter by (e.g. PostTypeKeyArticle, PostTypeKeyPage). Default is PostTypeKeyAny. FilterStatus string // The status of the post to filter by (e.g. "published", "draft"). Default is "published". FilterVisibility string // The visibility of the post to filter by (e.g. "public", "private"). Default is "public". SplitPinned bool // Whether to split featured items from the main list IncludeUnpublished bool }
FilterOptions contains the options to filter posts.
type FilterType ¶
type FilterType string
const ( FilterTypeAny FilterType = "any" FilterTypeAuthor FilterType = "author" FilterTypeTaxonomy FilterType = "taxonomy" )
func (FilterType) String ¶
func (ft FilterType) String() string
type FrontmatterFormat ¶
type FrontmatterFormat string
const ( FrontmatterTOML FrontmatterFormat = "toml" FrontmatterYAML FrontmatterFormat = "yaml" )
type KeyValueFilter ¶ added in v0.0.2
type LocalMarkdownFS ¶ added in v0.0.2
type LocalMarkdownFS struct {
// contains filtered or unexported fields
}
LocalMarkdownFS implements MarkdownFS for the local file system
func NewLocalMarkdownFS ¶ added in v0.0.2
func NewLocalMarkdownFS(rootDir string, proc MarkdownProcessor, format FrontmatterFormat) *LocalMarkdownFS
func (*LocalMarkdownFS) Delete ¶ added in v0.0.2
func (fs *LocalMarkdownFS) Delete(_ context.Context, postType, slug string) error
func (*LocalMarkdownFS) Move ¶ added in v0.0.2
func (fs *LocalMarkdownFS) Move(_ context.Context, oldType, oldSlug, newType, newSlug string) error
type MarkdownFS ¶ added in v0.0.2
type MarkdownFS interface { Walk(ctx context.Context) (<-chan *Post, <-chan error) Read(ctx context.Context, postType, slug string) (*Post, error) Write(ctx context.Context, post *Post) error Delete(ctx context.Context, postType, slug string) error Move(ctx context.Context, oldType, oldSlug, newType, newSlug string) error }
MarkdownFS handles file system operations for markdown files
type MarkdownProcessor ¶ added in v0.0.2
type MarkdownProcessor interface { Process(input []byte) (*Post, error) GenerateFrontmatter(meta *PostMeta, format FrontmatterFormat) (string, error) }
MarkdownProcessor handles markdown parsing and processing
type MemoryCacheStore ¶ added in v0.0.2
type MemoryCacheStore struct {
// contains filtered or unexported fields
}
MemoryCacheStore implements CacheStore interface using in-memory storage
func NewMemoryCacheStore ¶ added in v0.0.2
func NewMemoryCacheStore() *MemoryCacheStore
NewMemoryCacheStore creates a new MemoryCacheStore
func (*MemoryCacheStore) Clear ¶ added in v0.0.2
func (m *MemoryCacheStore) Clear(ctx context.Context) error
Clear clears all data from the post store
func (*MemoryCacheStore) Close ¶ added in v0.0.2
func (m *MemoryCacheStore) Close() error
Close closes the post store
func (*MemoryCacheStore) Delete ¶ added in v0.0.2
func (m *MemoryCacheStore) Delete(ctx context.Context, postType, slug string) error
Delete removes a post from the store
func (*MemoryCacheStore) GetTaxonomies ¶ added in v0.0.2
func (m *MemoryCacheStore) GetTaxonomies(ctx context.Context) ([]string, error)
GetTaxonomies returns a list of taxonomies. TODO: This is inefficient and should be optimized for large datasets.
func (*MemoryCacheStore) GetTaxonomyTerms ¶ added in v0.0.2
GetTaxonomyTerms returns a list of terms for a given taxonomy. TODO: This is inefficient and should be optimized for large datasets.
func (*MemoryCacheStore) Init ¶ added in v0.0.2
func (m *MemoryCacheStore) Init() error
Init initializes the post store
func (*MemoryCacheStore) Search ¶ added in v0.0.2
func (m *MemoryCacheStore) Search(ctx context.Context, options FilterOptions) ([]*Post, int, error)
Search searches for posts based on the provided FilterOptions
type Paginator ¶
type Paginator struct { TotalPages int CurrentPage int NextPage int PrevPage int PageSize int HasNext bool HasPrev bool HasPosts bool TotalPosts int AllPosts []*Post FeaturedPosts []*Post NonFeaturedPosts []*Post Visible bool // True by default, but can be set to false in the view. E.g. on the home page. }
Paginator is a struct that holds information about pagination, such as the total number of pages, the current page, the next and previous pages, the page size, whether there are more pages, whether there are posts, the total number of posts, all posts, featured posts, non-featured posts, and whether the paginator is visible.
type Post ¶
type Post struct { ID int64 `json:"id"` // ID is the unique identifier for the post PostID string `json:"post_id"` // PostID is the unique identifier for the post (post type + slug) Slug string `json:"slug"` // Slug is the URL-friendly version of the name PostType string `json:"postType"` // PostType is the type of post (e.g. post, page) Author string `json:"author"` // Author is a list of author Content string `json:"content"` // Content is raw content of the post HTML string `json:"html"` // HTML is the HTML content of the post ETag string `json:"etag"` // ETag is the entity tag EstimatedReadTime string `json:"estimatedReadTime"` // EstimatedReadTime is the estimated reading time Pinned bool `json:"pinned"` // Pinned is true if the post is pinned Photo string `json:"photo"` // Photo is the URL of the featured image FileTimePath string `json:"fileTimePath"` // FileTimePath is the file time path in the format YYYY-MM-DD for the original file path Name string `json:"name"` // Name is the name/title of the post Properties map[string]string `json:"properties"` // Properties is a map of additional, arbitrary key-value pairs. This can be used to store additional metadata such as extra microformat properties. Published sql.NullString `json:"published"` // Published is the published date Status string `json:"status"` // Status is the status of the post (should be one of draft, published, or archived) Subtitle string `json:"subtitle"` // Subtitle is the subtitle Summary string `json:"summary"` // Summary is the summary Taxonomies map[string][]string `json:"taxonomies"` // Taxonomies is a map of taxonomies (e.g. tags, categories) Visibility string `json:"visibility"` // Visibility is the visibility of the post (should be one of public, private, or unlisted) Created string `json:"created"` // Created is the creation date Updated string `json:"updated"` // Updated is the last modified date // contains filtered or unexported fields }
Post represents a Markdown post
func Deserialize ¶
Deserialize deserializes the byte slice to a post
func MarkdownToPost ¶
MarkdownToPost converts markdown content to a Post.
func (*Post) FileTimeInSlug ¶
FileTimeInSlug returns the file date
func (*Post) HasFileTimeInSlug ¶
HasFileTimeInSlug returns true if the post has a file time path. This is the date part of the original file path.
func (*Post) HasProperties ¶
HasProperties returns true if the post has additional/arbitrary metadata properties
func (*Post) HasPublished ¶
HasPublished returns true if the post has a published date
func (*Post) HasSubtitle ¶
HasSubtitle returns true if the post has a subtitle
func (*Post) HasSummary ¶
HasSummary returns true if the post has a summary
func (*Post) HasTaxonomies ¶
HasTaxonomies returns true if the post has taxonomies
func (*Post) HasTaxonomy ¶
HasTaxonomy returns true if the post has the specified taxonomy
func (*Post) HasUpdated ¶
HasUpdated returns true if the post has a last modified date
func (*Post) PublishedDate ¶
PublishedDate returns the published date in the format Jan 2, 2006
func (*Post) PublishedTime ¶ added in v0.0.2
PublishedTime returns the published date as a time.Time
func (*Post) PublishedYear ¶
PublishedYear returns the year of the published date
func (*Post) SlugWithYear ¶
SlugWithYear returns the slug with the published year prepended as a directory (if it exists)
func (*Post) SlugWithYearMonth ¶
SlugWithYearMonth returns the slug with the published year and month prepended as a directory (if it exists)
func (*Post) SlugWithYearMonthDay ¶
SlugWithYearMonthDay returns the slug with the published year, month, and day prepended as a directory (if it exists)
func (*Post) SlugWithoutDate ¶
SlugWithoutDate returns the slug without a file time path (if it exists)
type PostMeta ¶
type PostMeta struct { Author string `yaml:"author,omitempty" toml:"author,omitempty"` Pinned bool `yaml:"pinned,omitempty" toml:"pinned,omitempty"` Name string `yaml:"name,omitempty" toml:"name,omitempty"` Photo string `yaml:"photo,omitempty" toml:"photo,omitempty"` Properties map[string]string `yaml:"properties,omitempty" toml:"properties,omitempty"` Published string `yaml:"published,omitempty" toml:"published,omitempty"` Status string `yaml:"status,omitempty" toml:"status,omitempty"` Subtitle string `yaml:"subtitle,omitempty" toml:"subtitle,omitempty"` Summary string `yaml:"summary,omitempty" toml:"summary,omitempty"` Taxonomies map[string][]string `yaml:"taxonomies,omitempty" toml:"taxonomies,omitempty"` //Updated time.Time `yaml:"updated,omitempty" toml:"updated,omitempty"` Visibility string `yaml:"visibility,omitempty" toml:"visibility,omitempty"` }
PostMeta represents the frontmatter of a post
type PostType ¶
type PostType string
PostType is a string key that represents a post type and is used to determine the directory where posts of the given type are stored.
type PostTypes ¶ added in v0.0.2
type PostTypes []PostType
PostTypes is a slice of PostType.
func DefaultPostTypes ¶
func DefaultPostTypes() PostTypes
func (PostTypes) HasPostType ¶ added in v0.0.2
HasPostType returns true if the PostType is not empty.
type SlugPath ¶
func SlugifyPath ¶
SlugifyPath transforms a full OS path into a slugified path. - It trims the `rootPath` from the beginning of the `fullPath` to get the relative path. - The slug is then a combination of the `postType` and the relative path. - It removes leading and trailing slashes, and ensures no leading slash remains. - It finds the extension based on the last period in the path and trims it from the path. - If the file part of a path starts with an RFC3339 date (2006-01-02), it extracts it and removes it from the path. Note, it does not include the time part. - It trims the "/index" suffix if it exists. - It replaces all path separators with browser-compatible forward slashes. - Finally, it slugifies each path part using the slug package.
The function returns a SlugPath struct with the slugified path, the file time path, the file time, and the post type.