site

package
v0.0.0-...-698b8a8 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package site compiles the playlist hub into a static, navigable web site: one page per playlist embedding <byom-player>, a tree mirroring the hub's subdirectories, a shared nav index, Open Graph metadata, and an RSS feed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(opts Options) error

Build compiles the hub at opts.HubDir into a static site at opts.OutDir.

func CopyArt

func CopyArt(hubDir, outDir string) error

CopyArt copies the hub's downloaded cover-art store (<hubDir>/art) into <outDir>/art so the static site can serve it. A missing art dir is a no-op.

func GenerateMosaics

func GenerateMosaics(hubDir, outDir string, root *Node) error

GenerateMosaics builds a representative cover mosaic for each playlist that has no explicit hero image, writes it to <outDir>/art/mosaic/<slug>.jpg, and sets the in-memory Playlist.ImageFile so the existing hero precedence carries it into the JSPF and og:image. The mosaic filename is the playlist's slug path (predictable + stable across rebuilds). Generation is skipped when the mosaic already exists and is at least as new as the playlist's source YAML, so unchanged playlists don't pay the cover-read + render cost. Playlists with an explicit hero, or with no downloaded covers, are left untouched.

func WriteAssets

func WriteAssets(outDir string) error

WriteAssets copies the embedded assets/ directory into outDir/assets/.

func WriteCNAME

func WriteCNAME(outDir, baseURL string) error

WriteCNAME writes a GitHub Pages CNAME file with the host from baseURL. It is a no-op when baseURL is empty or has no host.

func WriteFeed

func WriteFeed(outDir string, site SiteMeta, root *Node) error

WriteFeed writes an RSS feed of playlists, newest first by DateCreated and capped at site.FeedItemLimit.

Nodes are collected and sorted before any item body is built: each body embeds a full tracklist and is stored twice (description and content:encoded), so rendering playlists that the cap discards would be the bulk of the work.

func WriteIndexJSON

func WriteIndexJSON(outDir string, root *Node) error

WriteIndexJSON writes the featured list and the nav tree (root's children) to site-index.json.

func WriteJSPF

func WriteJSPF(outDir string, root *Node, baseURL string) error

WriteJSPF writes a playlist.jspf.json next to each playlist page, reusing the tested JSPF exporter. baseURL is passed through as art_base so the exporter can point image_file entries at the deployed local art.

Types

type ContentPage

type ContentPage struct {
	Slug  string
	Title string
	Order int
	Desc  string
	Body  template.HTML
}

ContentPage is a render-ready standalone markdown page.

func LoadPages

func LoadPages(dir string) ([]ContentPage, error)

LoadPages reads every *.md in dir into a sorted slice of ContentPages. A missing directory yields (nil, nil) — content pages are opt-in.

type Crumb

type Crumb struct {
	Label string
	Href  string
}

Crumb is one breadcrumb link (Href empty → plain text, i.e. current page).

type IndexNode

type IndexNode struct {
	Name     string      `json:"name"`
	Title    string      `json:"title"`
	Path     string      `json:"path"`
	IsDir    bool        `json:"isDir"`
	Meta     string      `json:"meta,omitempty"`  // playlist summary line (leaves only)
	Image    string      `json:"image,omitempty"` // resolved cover href (leaves only)
	Year     int         `json:"year,omitempty"`
	Children []IndexNode `json:"children,omitempty"`
}

IndexNode is the nav projection of a Node serialized into site-index.json (no track data beyond the summary Meta line). It appears both in the nav tree and in the flat featured list. Path is absolute-from-root with leading + trailing slashes.

type Node

type Node struct {
	Name     string
	Title    string
	Path     string
	IsDir    bool
	IntroMD  string // raw markdown from the folder's README.md (root and subdirs)
	Playlist *playlist.Playlist
	Children []*Node
}

Node is one entry in the site tree: either a directory (IsDir) with Children, or a playlist leaf carrying its loaded Playlist. Path is the slash-joined slug path from the hub root ("" for the root itself).

func BuildTree

func BuildTree(hubDir string) (*Node, error)

BuildTree walks hubDir recursively and returns the root node.

type Options

type Options struct {
	HubDir   string
	OutDir   string
	PagesDir string
	Site     SiteMeta

	// Logger narrates build phases; nil → a default logrus logger.
	Logger logrus.FieldLogger
}

Options configures a site build.

type PageLink struct {
	Title string
	Href  string
}

PageLink is a content page's entry in the site header nav.

type Renderer

type Renderer struct {
	Site SiteMeta
	// contains filtered or unexported fields
}

Renderer holds the parsed template set and site settings.

func NewRenderer

func NewRenderer(site SiteMeta) (*Renderer, error)

NewRenderer parses the embedded templates.

func (*Renderer) RenderPages

func (r *Renderer) RenderPages(outDir string, pages []ContentPage) error

RenderPages writes one HTML page per content page at <outDir>/pages/<slug>/index.html.

func (*Renderer) RenderSite

func (r *Renderer) RenderSite(outDir string, root *Node) error

RenderSite renders the landing page plus every folder and playlist page.

type SiteIndex

type SiteIndex struct {
	Featured []IndexNode `json:"featured,omitempty"`
	Children []IndexNode `json:"children"`
}

SiteIndex is the payload of site-index.json: the flat Featured list plus the nav tree. Featured is sorted here rather than client-side because Go has the full playlist dates and IndexNode only carries the year.

type SiteMeta

type SiteMeta struct {
	Title                 string
	BaseURL               string
	PlayerSrc             string
	Provider              string
	Providers             []string
	YouTubeSearchEndpoint string
	SpotifyClientID       string
	Pages                 []PageLink
	// FeedTrackLimit caps how many tracks each RSS item lists. A value > 0
	// truncates and adds an "…and N more" link; <= 0 lists every track.
	FeedTrackLimit int
	// FeedItemLimit caps how many playlists the RSS feed carries, newest first.
	// A value > 0 truncates; <= 0 includes every playlist.
	FeedItemLimit int
}

SiteMeta carries site-wide settings baked into every page.

type YearGroup

type YearGroup struct {
	Label     string
	Playlists []*Node
}

YearGroup is a run of playlists sharing a DateUpdated year (or the undated group), for year-separated rendering.

Jump to

Keyboard shortcuts

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