engine

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPartitionCountTooLarge = errors.New("partition count greater than number of posts")
	ErrPartitionIndexTooLarge = errors.New("partition index greater than number of partitions")
	ErrPartitionCountInvalid  = errors.New("partition count invalid; must be greater than 1")
)

Partition Errors

Functions

func Copy

func Copy(src, dest string) error

Copy copies src to dest, doesn't matter if src is a directory or a file

func ETag

func ETag(contents []byte) (string, error)

ETag creates an etag for a given blob.

func Exists

func Exists(path string) bool

Exists returns if a given file exists.

func ExtractCaptureDate

func ExtractCaptureDate(imagePath string) (captureDate time.Time, err error)

ExtractCaptureDate extracts the capture date from an image file by path.

func GenerateExifData

func GenerateExifData(imagePath string) (*exif.Exif, error)

GenerateExifData gets exif data from a file on disk.

func GetExifData

func GetExifData(exifData *exif.Exif) (data model.Exif, err error)

GetExifData generates the parsed exif data for the post.

func GetRenderContext

func GetRenderContext(ctx context.Context) *model.RenderContext

GetRenderContext returns the render context off a context.

func HasExtension

func HasExtension(filename string, extensions ...string) bool

HasExtension returns if a given filename has any of a given set of extensions.

func ListDirectory

func ListDirectory(path string) (files []os.FileInfo, err error)

ListDirectory returns all the file infos within a given directory by path.

func MakeDir

func MakeDir(path string) error

MakeDir creates a new directory.

func ParseTemplate

func ParseTemplate(literal string) (*template.Template, error)

ParseTemplate creates a new template from a string

func ReadImage

func ReadImage(path string) (output model.Image, err error)

ReadImage reads image metadata.

func ReadYAML

func ReadYAML(path string, obj interface{}) error

ReadYAML reads a yaml file into a given object reference.

func RenderString

func RenderString(tmp *template.Template, vm interface{}) (string, error)

RenderString renders a template to a string for a given viewmodel.

func Slugify

func Slugify(v string) string

Slugify replaces non-letter or digit runes with '-'. It will not add repeated '-'.

func StripQuotes

func StripQuotes(v string) string

StripQuotes strips leading or trailing quotes.

func ViewFuncs

func ViewFuncs() template.FuncMap

ViewFuncs is the template funcs.

func WithRenderContext

func WithRenderContext(ctx context.Context, rc *model.RenderContext) context.Context

WithRenderContext returns a context with a render context set.

func WriteFile

func WriteFile(path string, contents []byte) error

WriteFile writes a file with default perms.

func WriteYAML

func WriteYAML(path string, obj interface{}) error

WriteYAML writes an object as yaml to disk.

Types

type Engine

type Engine struct {
	Config      config.Config
	Parallelism int
	DryRun      bool
	Log         *log.Logger
}

Engine returns a

func MustNew

func MustNew(options ...Option) *Engine

MustNew returns a new engine but panics on error.

func New

func New(options ...Option) (*Engine, error)

New returns a new engine..

func (Engine) Build

func (e Engine) Build(ctx context.Context) error

Build generates the blog to the given output directory.

func (Engine) BuildRenderContext

func (e Engine) BuildRenderContext(ctx context.Context) (*model.RenderContext, error)

BuildRenderContext builds the render context used by the render function.

func (Engine) CleanThumbnailCache

func (e Engine) CleanThumbnailCache(ctx context.Context) error

CleanThumbnailCache cleans the thumbnail cache by purging cached thumbnails for posts that may have been deleted.

func (Engine) CompileTemplate

func (e Engine) CompileTemplate(templatePath string, partials []string) (contents string, final *template.Template, err error)

CompileTemplate compiles a template.

func (Engine) CopyImageOriginal

func (e Engine) CopyImageOriginal(ctx context.Context, originalPath, destinationPath string) error

CopyImageOriginal copies the original image to the destination.

func (Engine) CopyThumbnail

func (e Engine) CopyThumbnail(etag, destinationPath string, size int) error

CopyThumbnail copies a cached thumbnail to the output directory.

func (Engine) CopyThumbnails

func (e Engine) CopyThumbnails(etag, destinationPath string) error

CopyThumbnails copies all thumbnails to the destination path by etag from the thumbnail cache.

func (Engine) CreateSlug

func (e Engine) CreateSlug(slugTemplate *template.Template, p model.Post) string

CreateSlug creates a slug for a post.

func (Engine) DiscoverPartials

func (e Engine) DiscoverPartials(ctx context.Context) ([]string, error)

DiscoverPartials reads all the partials named in the config. These are then injected into any subsequent renders as potential helper views.

func (Engine) DiscoverPosts

func (e Engine) DiscoverPosts(ctx context.Context) (*model.Data, error)

DiscoverPosts generates the blog data.

func (Engine) GeneratePost

func (e Engine) GeneratePost(ctx context.Context, slugTemplate *template.Template, path string, postIndex int) (*model.Post, error)

GeneratePost reads post contents and metadata from a folder.

func (Engine) GenerateThumbnail

func (e Engine) GenerateThumbnail(original image.Image, size int, imagePath, etag string) error

GenerateThumbnail generates a thumbnail and stores it in the cache if it doesn't exist and copies the cached thumbail to the output directory.

func (Engine) GenerateThumbnails

func (e Engine) GenerateThumbnails(originalContents []byte, originalImagePath, etag string) error

GenerateThumbnails generates and copies our main thumbnails for the post image. - originalContents should be the bytes of the original image file - etag should be the sha sum as an etag, it is used as a path component in the file cache

func (Engine) GetImageSizePaths

func (e Engine) GetImageSizePaths(post model.Post) map[string]string

GetImageSizePaths gets the map that corresponds to the image sizes and the image path.

func (Engine) InitializeOutputPath

func (e Engine) InitializeOutputPath() error

InitializeOutputPath creates the output path if it doesn't exist.

func (Engine) InitializeThumbnailCache

func (e Engine) InitializeThumbnailCache() error

InitializeThumbnailCache creates the output path if it doesn't exist.

func (Engine) ParallelismOrDefault

func (e Engine) ParallelismOrDefault() int

ParallelismOrDefault is the parallelism or a default.

func (*Engine) ParseSlugTemplate

func (e *Engine) ParseSlugTemplate() (*template.Template, error)

ParseSlugTemplate ensures the slug template

func (Engine) ProcessThumbnails

func (e Engine) ProcessThumbnails(ctx context.Context, originalFilePath, destinationPath string) error

ProcessThumbnails processes thumbnails.

func (Engine) Render

func (e Engine) Render(ctx context.Context) error

Render writes the templates out for each of the posts.

func (Engine) RenderTemplateToFile

func (e Engine) RenderTemplateToFile(tpl *template.Template, outputPath string, data *model.ViewModel) (string, error)

RenderTemplateToFile writes a template to a given path with a given data viewmodel.

func (Engine) Resize

func (e Engine) Resize(original image.Image, destination string, maxDimension uint) error

Resize resizes an image to a destination.

func (Engine) ShouldGenerateThumbnails

func (e Engine) ShouldGenerateThumbnails(etag string) bool

ShouldGenerateThumbnails returns if we should process any thumbnais for a given etag.

func (Engine) WriteDataJSON

func (e Engine) WriteDataJSON(data *model.Data, path string) error

WriteDataJSON writes a data file to disk.

type Option

type Option func(*Engine) error

Option is a mutator for an engine.

func OptConfig

func OptConfig(cfg config.Config) Option

OptConfig sets the engine config.

func OptDryRun

func OptDryRun(dryRun bool) Option

OptDryRun sets DryRun on the engine.

func OptLog

func OptLog(log *log.Logger) Option

OptLog sets the logger.

func OptParallelism

func OptParallelism(paralellism int) Option

OptParallelism sets the engine parallelism if relevant.

Jump to

Keyboard shortcuts

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