view

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: LGPL-2.1 Imports: 22 Imported by: 0

README

mod/view

mod/view contains typed view models, templates, CSS, and generated visual assets for the HTML interface. It is a rendering package: server and webui builders prepare data, then mod/view turns it into HTML, PNG, or small static assets.

Place in the Runtime

flowchart LR
  webui["server/webui builders"] --> view["mod/view"]
  view --> templates["HTML templates"]
  view --> css["embedded CSS"]
  view --> png["logos and OG images"]
  templates --> response["HTML response"]
  png --> response

Responsibilities

  • Define view models for catalog, key, version, metrics, and shared context.
  • Render HTML templates with embedded CSS and small scripts.
  • Render built-in logos and Open Graph PNG banners.
  • Keep HTML escaping and Markdown rendering boundaries clear.
  • Keep UI text consistent across web entry and Yggdrasil entry.

Contracts

  • View models should already contain display-ready facts. Templates should not query storage or state.
  • Release notes Markdown is sanitized before rendering.
  • PNG generation must be deterministic for the same input.
  • CSS and HTML should avoid layout assumptions that break long keys, versions, hashes, or Yggdrasil addresses.

Important Files

  • *.go: view models and render helpers.
  • templates/: HTML templates and stylesheet.
  • logo.go, media.go: generated images and media helpers.
  • markdown integration is handled before release notes reach templates.

Operational Notes

The UI is operational rather than marketing-oriented. It should favor dense, readable package information, stable navigation, copyable hashes, and install snippets over decorative content.

Documentation

Index

Constants

View Source
const (
	OGBannerWidth  = 1200
	OGBannerHeight = 630

	// OGBannerGenVersion invalidates cached OG-banner ETags on any change in renderer output.
	OGBannerGenVersion = "2"
)

Variables

This section is empty.

Functions

func IconICO

func IconICO() ([]byte, error)

IconICO assembles the favicon from several PNG layers without SVG rendering.

func LogoPNG

func LogoPNG(edge int) ([]byte, error)

LogoPNG returns a square PNG with a transparent background.

func OGKeyBannerPNG

func OGKeyBannerPNG(key string, latest string, versionCount uint64, overlayArr []string, bottomText string) ([]byte, error)

OGKeyBannerPNG returns the module banner: the key large, latest/count/overlays sub-line, date/domain at the bottom.

func OGNodeBannerPNG

func OGNodeBannerPNG(moduleCount int, versionCount uint64, tagline string, bottomText string) ([]byte, error)

OGNodeBannerPNG returns the node banner: counters large, the tagline as sub-line, date/domain at the bottom.

func OGVersionBannerPNG

func OGVersionBannerPNG(key string, version string, sizeBytes uint64, overlayArr []string, bottomText string) ([]byte, error)

OGVersionBannerPNG returns the version banner: the key large, version/size/overlays sub-line, date/domain at the bottom.

Types

type ActionObj

type ActionObj struct {
	Label  string
	Detail string
	URL    string
	Kind   string
}

ActionObj describes a route, page action, or alternate entry link.

type AlternateObj

type AlternateObj struct {
	Channel  string
	Scheme   string
	Host     string
	CopyHost string
}

AlternateObj describes the opposite entry channel when both web and ygg are configured. Host is used for links; CopyHost is used for copy-paste commands such as .pk.ygg.

type ArtifactEntryObj

type ArtifactEntryObj struct {
	Name      string
	Kind      string
	SizeBytes uint64
	Hashes    []ArtifactHashObj
	URL       string
	GoModule  bool
}

ArtifactEntryObj describes one downloadable artifact in the version page input. Kind is the plain archive format; Go module archives are separated by GoModule.

type ArtifactHashObj

type ArtifactHashObj struct {
	Algo string
	Sum  []byte
}

ArtifactHashObj is one stored digest of an artifact body.

type CatalogEntryObj

type CatalogEntryObj struct {
	Key           string
	LatestVersion string
	Source        SourceObj
	// Go and Composer mark ecosystems serving this key's latest version.
	Go       bool
	Composer bool
}

CatalogEntryObj describes one package key in the catalog input.

type CatalogObj

type CatalogObj struct {
	Context ContextObj
	Keys    []CatalogEntryObj
}

CatalogObj is the external input for catalog.html.

type ClientObj

type ClientObj struct {
	Channel string
	Scheme  string
	Host    string
}

ClientObj describes the listener that served the current page.

type CodeSnippetObj

type CodeSnippetObj struct {
	Label string
	Body  string
}

CodeSnippetObj describes a command or install recipe supplied by the caller.

type ContactGroupObj

type ContactGroupObj struct {
	Name   string
	Values []string
}

ContactGroupObj is one public contact group from the node info card.

type ContextObj

type ContextObj struct {
	Service    ServiceObj
	Client     ClientObj
	Alternate  AlternateObj
	Navigation []ActionObj
}

ContextObj contains request and service data shared by all page inputs.

type KeyObj

type KeyObj struct {
	Context       ContextObj
	Key           string
	LatestVersion string
	Source        SourceObj
	Overlays      []string
	Install       []CodeSnippetObj
	AltInstall    []CodeSnippetObj
	Versions      []VersionEntryObj
	Page          PageObj
}

KeyObj is the external input for key.html.

type MetricsObj

type MetricsObj struct {
	Context         ContextObj
	Endpoints       []ActionObj
	RefreshInterval time.Duration
}

MetricsObj is the external input for metrics.html.

type PageObj

type PageObj struct {
	Total       uint64
	Newest      bool
	NewerCursor string
	OlderCursor string
}

PageObj carries the version count and the two keyset pager cursors. An empty cursor hides that direction's link; Newest gates the "released" date line.

type RendererObj

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

RendererObj holds parsed templates and embedded CSS; build it once with New. It is safe for concurrent reads because html/template.Execute is concurrent-safe.

func New

func New() (*RendererObj, error)

New parses all templates and caches embedded CSS for application startup.

func (*RendererObj) Catalog

func (obj *RendererObj) Catalog(inputObj CatalogObj) ([]byte, error)

Catalog renders the key catalog page.

func (*RendererObj) Key

func (obj *RendererObj) Key(inputObj KeyObj) ([]byte, error)

Key renders one key page with versions, pagination, and install snippets.

func (*RendererObj) MetricsIndex

func (obj *RendererObj) MetricsIndex(inputObj MetricsObj) ([]byte, error)

MetricsIndex renders the metric group list page.

func (*RendererObj) Version

func (obj *RendererObj) Version(inputObj VersionObj) ([]byte, error)

Version renders one version page with integrity, downloads, install snippets, notes, and history navigation.

type ServiceObj

type ServiceObj struct {
	Name        string
	Tagline     string
	HomeURL     string
	InfoName    string
	Description string
	Location    string
	Contacts    []ContactGroupObj
	// BuildVersion and BuildDate come from target/meta_gen for the footer.
	BuildVersion string
	BuildDate    string
}

ServiceObj describes the public service identity, extended by the config info card when set.

type SourceObj

type SourceObj struct {
	URL            string
	Status         string
	Classification string
	// Label is the rendered badge text; git labels prefer the concrete forge host.
	Label string
}

SourceObj describes upstream availability and origin metadata.

type VersionEntryObj

type VersionEntryObj struct {
	Version         string
	IngestedAt      time.Time
	SourceSizeBytes uint64
	// Go and Composer mark whether this exact version is served in that ecosystem.
	Go       bool
	Composer bool
}

VersionEntryObj describes one version row in the key page input.

type VersionHistoryObj

type VersionHistoryObj struct {
	NewerVersion string
	OlderVersion string
}

VersionHistoryObj describes neighboring versions for the version page.

type VersionObj

type VersionObj struct {
	Context              ContextObj
	Key                  string
	Version              string
	SourceSizeBytes      uint64
	UpstreamDeleted      bool
	IngestedAt           time.Time
	VerifiedAt           time.Time
	Detected             []string
	Source               SourceObj
	Overlays             []string
	Degraded             []string
	Downloads            []ArtifactEntryObj
	Install              []CodeSnippetObj
	AltInstall           []CodeSnippetObj
	ReleaseNotesMarkdown string
	History              VersionHistoryObj
}

VersionObj is the external input for version.html.

Jump to

Keyboard shortcuts

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