model

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Title   string  `json:"title,omitempty" yaml:"title,omitempty"`
	Author  string  `json:"author,omitempty" yaml:"author,omitempty"`
	BaseURL string  `json:"baseURl,omitempty" yaml:"baseURL,omitempty"`
	Posts   []*Post `json:"posts,omitempty" yaml:"posts,omitempty"`
	Tags    []Tag   `json:"tags,omitempty" yaml:"tags,omitempty"`
}

Data is the site's entire database of posts.

func (Data) EarliestPost

func (d Data) EarliestPost() (date time.Time)

EarliestPost returns the earliest post.

func (Data) IsZero

func (d Data) IsZero() bool

IsZero returns if the object is set.

func (Data) LatestPost

func (d Data) LatestPost() (date time.Time)

LatestPost returns the latest post.

func (Data) NumImagePosts

func (d Data) NumImagePosts() (count int)

NumImagePosts returns the number of image posts.

func (Data) NumPosts

func (d Data) NumPosts() (count int)

NumPosts returns the total number of posts.

func (Data) NumTags

func (d Data) NumTags() (count int)

NumTags returns the total number of tags.

func (Data) NumTextPosts

func (d Data) NumTextPosts() (count int)

NumTextPosts returns the number of text posts.

type Exif

type Exif struct {
	CaptureDate     time.Time `json:"captureDate" yaml:"captureDate"`
	CameraMake      string    `json:"cameraMake" yaml:"cameraMake"`
	CameraModel     string    `json:"cameraModel" yaml:"cameraModel"`
	LensModel       string    `json:"lensModel" yaml:"lensModel"`
	FNumber         string    `json:"fNumber" yaml:"fNumber"`
	ExposureTime    string    `json:"exposureTime" yaml:"exposureTime"`
	FocalLength     string    `json:"focalLength" yaml:"focalLength"`
	ISOSpeedRatings string    `json:"isoSpeedRatings" yaml:"isoSpeedRatings"`
}

Exif are known values for a subset of the full image exif data.

type Image

type Image struct {
	SourcePath string            `json:"sourcePath" yaml:"sourcePath"`
	Width      int               `json:"width" yaml:"width"`
	Height     int               `json:"height" yaml:"height"`
	Exif       Exif              `json:"exif" yaml:"exif"`
	Sizes      map[string]string `json:"sizes,omitempty" yaml:"sizes,omitempty"`
}

Image represents a posted image.

func (Image) IsZero

func (i Image) IsZero() bool

IsZero returns if the image has been processed or not.

func (Image) LongDimension

func (i Image) LongDimension() int

LongDimension returns the longest dimension of the image.

func (Image) Ratio

func (i Image) Ratio() float64

Ratio returns the ratio of the width to the height. As an example, for 3:2 images, the ratio is 1.5.

func (Image) Scale

func (i Image) Scale(longDimension int) image.Rectangle

Scale returns the image dimensions scaled to a given long dimension.

type Meta

type Meta struct {
	Captured time.Time         `json:"captured,omitempty" yaml:"captured,omitempty"`
	Posted   time.Time         `json:"posted" yaml:"posted"`
	Title    string            `json:"title" yaml:"title"`
	Location string            `json:"location,omitempty" yaml:"location,omitempty"`
	Comments string            `json:"comments,omitempty" yaml:"comments,omitempty"`
	Tags     []string          `json:"tags,omitempty" yaml:"tags,omitempty"`
	Extra    map[string]string `json:"extra,omitempty" yaml:"extra,omitempty"`
}

Meta is extra data for a post.

type Post

type Post struct {
	OriginalPath string    `json:"originalPath,omitempty" yaml:"originalPath,omitempty"`
	OutputPath   string    `json:"outputPath,omitempty" yaml:"outputPath,omitempty"`
	Slug         string    `json:"slug,omitempty" yaml:"slug,omitempty"`
	Index        int       `json:"index" yaml:"index"`
	ModTime      time.Time `json:"modTime" yaml:"modTime"`

	Meta  Meta  `json:"meta" yaml:"meta"`
	Text  Text  `json:"text,omitempty" yaml:"text,omitempty"`
	Image Image `json:"image,omitempty" yaml:"image,omitempty"`

	Template *template.Template `json:"-" yaml:"-"`
	Previous *Post              `json:"-" yaml:"-"`
	Next     *Post              `json:"-" yaml:"-"`
}

Post is a single post item.

func (Post) HasNext

func (p Post) HasNext() bool

HasNext returns if there is a next post.

func (Post) HasPrevious

func (p Post) HasPrevious() bool

HasPrevious returns if there is a previous post.

func (Post) ImagePathForSize

func (p Post) ImagePathForSize(size int) string

ImagePathForSize returns the image source for a given image size in pixels.

func (Post) ImagePathLarge

func (p Post) ImagePathLarge() string

ImagePathLarge returns the fully qualified image source path.

func (Post) ImagePathMedium

func (p Post) ImagePathMedium() string

ImagePathMedium returns the fully qualified image source path.

func (Post) ImagePathOriginal

func (p Post) ImagePathOriginal() string

ImagePathOriginal returns the fully qualified image source path.

func (Post) ImagePathSmall

func (p Post) ImagePathSmall() string

ImagePathSmall returns the fully qualified image source path.

func (Post) IndexPath

func (p Post) IndexPath() string

IndexPath is a helper that returns the fully qualified path for the post's index.html. It is in the form /Year/Month/Day/Slug/index.html

func (Post) IsImage

func (p Post) IsImage() bool

IsImage returns if the post is an image post.

func (Post) IsText

func (p Post) IsText() bool

IsText returns if the post is an text post.

func (Post) IsZero

func (p Post) IsZero() bool

IsZero returns if the post is set.

func (Post) Labels

func (p Post) Labels() map[string]string

Labels returns labels use for filtering with a selector.

func (Post) PostType

func (p Post) PostType() string

PostType returns a string version of the post type.

func (Post) TableRow

func (p Post) TableRow() PostTableRow

TableRow returns a post as an ansi table row.

func (Post) TitleOrDefault

func (p Post) TitleOrDefault() string

TitleOrDefault returns the title for the post.

type PostSorter

type PostSorter struct {
	Posts     []*Post
	SortKey   string
	Ascending bool
}

PostSorter sorts a set of posts by a given sort key.

func (PostSorter) Len

func (p PostSorter) Len() int

Len implements sorter.

func (PostSorter) Less

func (p PostSorter) Less(i, j int) bool

Less implements sorter.

func (PostSorter) Swap

func (p PostSorter) Swap(i, j int)

Swap implements sorter.

type PostTableRow

type PostTableRow struct {
	Title    string
	Location string
	Posted   time.Time
	Tags     string
	Slug     string
	PostType string
}

PostTableRow is a row for table output.

type Posts

type Posts []*Post

Posts is a list of posts.

func (Posts) FilterBySelector

func (p Posts) FilterBySelector(sel selector.Selector) []*Post

FilterBySelector filters the posts by a selector.

func (Posts) First

func (p Posts) First() (output Post)

First returns the first post in the list. It returns an empty post if the list is empty.

func (Posts) Sort

func (p Posts) Sort(key string, ascending bool) *PostSorter

Sort returns a sorter.

func (Posts) TableRows

func (p Posts) TableRows() []PostTableRow

TableRows returns table rows for the given slice of posts.

type RenderContext

type RenderContext struct {
	Data     *Data    `json:"data"`
	Partials []string `json:"partials"`
	Stats    Stats    `json:"stats"`
}

RenderContext is the full context for a particular render.

type Stats

type Stats struct {
	NumPosts      int
	NumTags       int
	NumImagePosts int
	NumTextPosts  int

	Earliest time.Time
	Latest   time.Time
}

Stats are stats about the blog.

func (Stats) TableData

func (s Stats) TableData() (columns []string, rows [][]string)

TableData returns the stats as ansi table data.

type Tag

type Tag struct {
	Tag   string
	Posts []*Post
}

Tag are posts associated with tags.

func (Tag) TableRow

func (t Tag) TableRow() TagTableRow

TableRow returns the ansi table row form of the tag.

type TagTableRow

type TagTableRow struct {
	Tag   string
	Posts int
}

TagTableRow is a ansi table row for tags.

type Tags

type Tags []Tag

Tags orders tag posts by tag.

func (Tags) Len

func (o Tags) Len() int

Len implements sorter.

func (Tags) Less

func (o Tags) Less(i, j int) bool

Less implements sorter.

func (Tags) Swap

func (o Tags) Swap(i, j int)

Swap implements sorter.

func (Tags) TableRows

func (o Tags) TableRows() []TagTableRow

TableRows returns the table rows for the given slice of tags.

type Text

type Text struct {
	SourcePath string `json:"sourcePath" yaml:"sourcePath"`
	Template   string `json:"template,omitempty" yaml:"template,omitempty"`
	Output     string `json:"output,omitempty" yaml:"output,omitempty"`
}

Text is a text post.

func (Text) IsZero

func (t Text) IsZero() bool

IsZero returns if the post is set or not.

type ViewModel

type ViewModel struct {
	Title  string
	Extra  map[string]interface{}
	Config config.Config
	Posts  []*Post
	Tags   []Tag

	Post Post
	Tag  Tag
}

ViewModel is the type passed to view rendering.

func (ViewModel) TitleOrDefault

func (vm ViewModel) TitleOrDefault() string

TitleOrDefault returns the title.

Jump to

Keyboard shortcuts

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