microblog

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: BSD-2-Clause, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions defaultOptions = defaultOptions{
	Template: `
	<div class="blog-post">
		<h2>{{.Heading}}</h2>
		<span class="dt-posted">{{.DtPosted}}</span>
		{{.Content}}
	</div>
	`,
	Backend:                   SQLite,
	EnablePublicationTracking: false,
}

Default options used in BlogPost.WriteHtml(). You can pass options `WithTemplateFile`/`WithTemplateString` and `WithPublicationTracking` to Blog and BlogPost to override the default behaviour. If you wish, you can also manipulate this struct directly to change behaviour globally.

Functions

func WithPublicationTracking

func WithPublicationTracking() func(*blogPost) error

Enable publication tracking using a database backend. With this option enabled, the date of the first blogpost.WriteHtml call will be stored in a database backend and used in subsequent blogpost.WriteHtml calls

func WithTemplateFile

func WithTemplateFile(fp string) func(*blogPost) error

Override the default template (microblog.DefaultOptions.Template) with a template file

func WithTemplateString

func WithTemplateString(s string) func(*blogPost) error

Override the default template (microblog.DefaultOptions.Template) with a string

Types

type Blog

type Blog interface {
	RenderPosts() ([]byte, error)
	RenderPostsAsync() ([]byte, error)
	GetDirectory() string
	GetBlogPosts() []BlogPost
}

Represents a collection of BlogPosts in the same directory. Provides methods to render these BlogPosts as HTML.

func NewBlog

func NewBlog(directory string, postOptions ...func(*blogPost) error) (Blog, error)

Creates a new Blog. The first parameter is the path to the directory that contains the different blog posts as .md files. You can also pass post options to apply to all the BlogPost structs created within this function, see microblog.BlogPost for more information.

blog, err := microblog.NewBlog("/path/to/mm/directory")
blog, err := microblog.NewBlog("/path/to/mm/directory", microblog.WithTemplateFile("/path/to/html/template"))

type BlogPost

type BlogPost interface {
	GetFilePath() string
	GetName() string
	Markdown() (string, error)
	WriteHtml(io.Writer) error
}

Represents a blog post in the form of a Markdown file. Exposes methods to render its contents as HTML.

func NewBlogPost

func NewBlogPost(fp string, options ...func(*blogPost) error) (BlogPost, error)

Create a new BlogPost The first argument is the filepath to the Markdown file that contains the blog post. You can use the following options to configure the behaviour further:

blogPost, err := microblog.NewBlogPost("/path/to/post.md")) // use default template
blogPost, err := microblog.NewBlogPost("/path/to/post.md", microblog.WithTemplateString(`<html>...</html>`))
blogPost, err := microblog.NewBlogPost("/path/to/post.md", microblog.WithTemplateFile("/path/to/html/template"))

The template itself must be written using the Golang template language and contain the same variables as the default template. You can however change the tags and classes. You can access the default template at microblog.Template.

type Registry

type Registry interface {
	GetPublicationDate(*blogPost) (*time.Time, error)
	SetPublicationDate(*blogPost) error
}

Represents a storage backend with functionality to retrieve and set the publication date for a blog post.

type RegistryType

type RegistryType string

Type of storage backend.

const (
	SQLite RegistryType = "sqlite"
)

Jump to

Keyboard shortcuts

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