events

package
v0.0.0-...-963cf5d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events implements the events module (see CWUP/tasks/events.md): dates, events and performances listed from one SML file of the content repo, with a page and a calendar file per event.

Index

Constants

View Source
const ThumbWidth = 600

ThumbWidth is the width of list preview images: two times a typical list column, sharp on high-density screens.

Variables

View Source
var ErrUnsupported = errors.New("image format not supported for thumbnails")

ErrUnsupported means the image cannot be turned into a thumbnail; the caller serves the original instead.

Functions

func Downscale

func Downscale(src image.Image, width int) *image.RGBA

Downscale scales src down to at most width pixels wide (never up) with the same box filter as Thumbnail; transparent areas become white. Used by the market module for uploaded photos.

func ICS

func ICS(e Event, d ICSData) string

ICS returns an iCalendar (RFC 5545) file with one event. Times are written in UTC, all-day events as dates, so no VTIMEZONE is needed.

func ParseTime

func ParseTime(v string, loc *time.Location) (t time.Time, dateOnly bool, err error)

ParseTime parses a start or end value in loc.

func RenderDetail

func RenderDetail(d DetailData) (template.HTML, error)

RenderDetail renders the page of one event.

func RenderList

func RenderList(d ListData) (template.HTML, error)

RenderList renders the Events element.

func Thumbable

func Thumbable(path string) bool

Thumbable reports whether path has an extension Thumbnail can read.

func Thumbnail

func Thumbnail(src []byte, width int) ([]byte, error)

Thumbnail scales a JPEG or PNG image down to at most width pixels wide (never up) and returns it as JPEG. Transparent areas become white.

func ValidID

func ValidID(id string) bool

ValidID reports whether id can be an event id (and thus a URL segment).

Types

type Card

type Card struct {
	URL      string
	Title    string
	When     string
	ISOStart string // machine-readable start for <time> and schema.org
	ISOEnd   string
	Place    string
	Teaser   string
	Thumb    string // list image (thumbnail when possible)
	Image    string // full image
	Alt      string
	Past     bool
}

Card is one event prepared for display: texts in the visitor's language, dates formatted, image URLs resolved.

func NewCard

func NewCard(e Event, base, lang string, f Formatter, now time.Time, imageURL, thumbURL func(string) string) Card

NewCard prepares e for display. imageURL maps the event's image to the full image URL, thumbURL to the list image URL.

type DetailData

type DetailData struct {
	Texts       Texts
	Card        Card
	ListURL     string
	Description template.HTML // compiled Markdown, empty = teaser
	Link        string        // external link
	ICS         string        // calendar file URL, empty for past events
}

DetailData feeds the page of one event.

type Event

type Event struct {
	ID        string
	Start     time.Time
	End       time.Time // zero when the event has no end
	AllDay    bool      // start given as a date only
	EndAllDay bool      // end given as a date only
	Image     string    // path below static/ or an absolute URL
	Link      string    // external link (tickets, more info)
	// contains filtered or unexported fields
}

Event is one entry of the index file.

func (Event) Alt

func (e Event) Alt(lang string) string

Alt returns the image description in lang, the title if there is none.

func (Event) HasEnd

func (e Event) HasEnd() bool

HasEnd reports whether the event has an end.

func (Event) IsPast

func (e Event) IsPast(now time.Time) bool

IsPast reports whether the event is over at now.

func (Event) Local

func (e Event) Local(key, lang string) string

Local returns property key in lang (key_<lang>), falling back to key.

func (Event) Place

func (e Event) Place(lang string) string

Place returns the place in lang.

func (Event) Teaser

func (e Event) Teaser(lang string) string

Teaser returns the short text in lang.

func (Event) Text

func (e Event) Text(lang string) string

Text returns the Markdown file with the long description in lang.

func (Event) Title

func (e Event) Title(lang string) string

Title returns the title in lang.

func (Event) Until

func (e Event) Until() time.Time

Until is the moment the event is over: its end, or the end of its last day when only a date is known. An event without an end stays upcoming for the whole day it takes place.

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter formats dates with the labels of one language.

func (Formatter) Date

func (f Formatter) Date(t time.Time) string

Date formats the day of t.

func (Formatter) DateTime

func (f Formatter) DateTime(t time.Time) string

DateTime formats day and time of t.

func (Formatter) Time

func (f Formatter) Time(t time.Time) string

Time formats the time of day of t.

func (Formatter) When

func (f Formatter) When(e Event) string

When formats the date range of e: "start", the timerange label on one day, "start – end" across days.

type ICSData

type ICSData struct {
	UID         string // globally unique, e.g. "<id>@<domain>"
	Title       string
	Place       string
	Description string
	URL         string // the event's page
	Stamp       time.Time
}

ICSData is what goes into the calendar file of one event.

type Index

type Index struct {
	Events []Event
	Labels Labels
	// contains filtered or unexported fields
}

Index is a parsed index file: the events in file order and the labels.

func Parse

func Parse(source string, loc *time.Location) (*Index, error)

Parse parses an Events { Labels {} Event {} ... } document; times are local to loc. Only a broken document or a wrong root is an error: invalid events are skipped with a warning, so one typo never empties the list.

func (*Index) Get

func (x *Index) Get(id string) (Event, bool)

Get returns the event with id.

func (*Index) Split

func (x *Index) Split(now time.Time, pastLimit int, all bool) (upcoming, past []Event, more bool)

Split sorts the events at now: upcoming ascending by start, past descending (most recent first). Unless all is set, past is cut to pastLimit and more reports whether events were cut.

type Labels

type Labels struct {
	// contains filtered or unexported fields
}

Labels are the visible texts and date formats of the events module, set by the site in the index file's Labels {} block. Every key accepts key_<lang> variants for any language code.

func NewLabels

func NewLabels(node *sml.Node, builtin map[string]map[string]string) Labels

NewLabels returns labels read from node (nil = no Labels {} block) with the given built-in fallback texts, keyed by language and label. Other modules (the blog) use it for their own texts and date formats.

func (Labels) Formatter

func (l Labels) Formatter(lang, defLang string) Formatter

Formatter returns the date formatter for lang.

func (Labels) Get

func (l Labels) Get(key, lang, defLang string) string

Get returns the text for key in lang. Order: key_<lang>; the plain key (the site's own text, written in its default language defLang); the built-in text for lang; the plain key for any other language; English. A key set to "" stays empty, which hides that element.

type ListData

type ListData struct {
	Texts    Texts
	Upcoming []Card
	Past     []Card
	MoreURL  string // set when past events were cut
}

ListData feeds the Events element.

type Texts

type Texts struct {
	Upcoming, Past, More, Empty, Back, Over, Calendar, Details, Link string
}

Texts are the labels of one language, resolved for the templates.

func NewTexts

func NewTexts(l Labels, lang, defLang string) Texts

NewTexts resolves the labels for lang.

Jump to

Keyboard shortcuts

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