simple

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package simple provides functions for handling string or integer input data.

Index

Constants

View Source
const (
	YYYYMMDD = "2006-Jan-02"
)

Variables

View Source
var (
	ErrLinkType = errors.New("the id value is an invalid type")
	ErrName     = errors.New("name is an empty string")
	ErrNegative = errors.New("value cannot be a negative number")
)

Functions

func AssetSrc

func AssetSrc(abs, dir, unid, ext string) string

AssetSrc returns a URL to an artifact asset with an cache busting hash. The named dir is the directory where the asset is stored, the unid is the unique identifier of the asset, and the ext is the file extension of the expected asset.

func BytesHuman

func BytesHuman(i int64) string

BytesHuman returns the file size for the file record.

func DemozooGetLink(filename, filesize, demozoo, unid any) template.HTML

DemozooGetLink returns a HTML link to the Demozoo download links. The filename and filesize are used to determine if the file exists. The demozoo is the ID for the production on Demozoo. The unid is the unique identifier for the file record.

func DownloadB

func DownloadB(i any) template.HTML

DownloadB returns a human readable string of the file size. The i value must be an integer or a null.Int64.

func ImageSample

func ImageSample(unid, previewDir string) template.HTML

ImageSample returns a HTML image tag for the given unid. The previewDir is the directory where the preview images are stored.

func ImageSampleStat

func ImageSampleStat(unid, previewDir string) bool

ImageSampleStat returns true if the image sample file exists and is not a 0 byte file. The previewDir is the directory where the preview images are stored.

func ImageXY

func ImageXY(name string) [2]string

ImageXY returns the named image filesize and dimensions.

func LinkID

func LinkID(id any, elem string) (string, error)

LinkID creates a URL to link to the record. The id is obfuscated to prevent direct linking. The elem is the element to link to, such as 'f' for file or 'd' for download.

func LinkPreviewTip

func LinkPreviewTip(name, platform string) string

LinkPreviewTip returns a tooltip to describe the preview link. The name is the filename of the file to preview and does not require path information. The platform is the platform or format of the file.

func LinkRelations

func LinkRelations(val string) template.HTML

LinkRelations returns a collection of HTML anchor links that point to artifacts.

The val string is a list of artifact descriptions and their URL ID separated by a semicolon ";". Multiple artifact entries are separated by a pipe "|".

For example, "NFO;9f1c2|Intro;a92116e".

func LinkRelr

func LinkRelr(name string) (string, error)

LinkRelr returns a link to the named group page.

Providing the name "a group" will return "/g/a-group".

func LinkSites

func LinkSites(val string) template.HTML

LinkSites returns a collection of HTML anchor links that point to websites.

The val string is a list of website descriptions and their URL ID separated by a semicolon ";". Multiple website entries are separated by a pipe "|".

For example, "Site;example.com|Documentation;example.com/doc".

func MIME

func MIME(name string) string

MIME returns the MIME type for the named file.

func MagicAsTitle

func MagicAsTitle(name string) string

MagicAsTitle returns the magic number description for the named file.

func MakeLink(name, class string, performant bool) (string, error)

MakeLink returns a HTML anchor link to the named group page. When the performant flag is false, the link will apply additional typography to the group name. But this should not be used for large lists of links as it will significantly slow down the page rendering.

For example supplying the name "tport"

  • with performant false will return a link displaying "tPORt"
  • with performant true will return a link displaying "Tport"

func MkContent

func MkContent(src string) string

MkContent makes and/or returns a distinct directory path in the temp directory that is used to extract the contents of the content of the file download archive. To make the directory distinct it is prefixed with the basename of the src file.

The returned path should be removed after use.

func ReleaserPair

func ReleaserPair(a, b any) [2]string

ReleaserPair returns the primary and secondary releaser groups as two strings.

func Releasers

func Releasers(prime, second string, magazine bool) template.HTML

Releasers returns a HTML links for the primary and secondary group names.

func Screenshot

func Screenshot(unid, desc, previewDir string) template.HTML

Screenshot returns a image elment with screenshots for the given unid. If a webp or avif image is available, and a legacy png or jpg image is available, a picture element is used to provide multiple sources for the image. Otherwise, a single img element is used.

The unid is the filename of the screenshot image without an extension. The desc is the description of the image used for the alt attribute in the img tag. The previewDir is the directory where the preview images are stored.

Supported formats are webp, png, jpg and avif.

func StatHumanize

func StatHumanize(name string) (string, string, string)

StatHumanize returns the last modified date, size in bytes and size formatted of the named file. If the file does not exist, the string "file not found" is returned.

An example of the returned values are:

"2024-Sep-03", "4,163", "4.2 kB"

func Thumb

func Thumb(unid, desc, thumbDir string, bottom bool) template.HTML

Thumb returns a HTML image tag or picture element for the given unid. The unid is the filename of the thumbnail image without an extension. The desc is the description of the image. The thumbDir is the directory where the thumbnail images are stored. The bottom flag is true if the image should be displayed at the bottom of the container element.

func ThumbSample

func ThumbSample(unid, thumbDir string) template.HTML

ThumbSample returns a HTML image tag for the given unid. The unid is the filename of the thumbnail image without an extension. The thumbDir is the directory where the thumbnail images are stored.

func Updated

func Updated(t any, s string) string

Updated returns a string of the time since the given time t. If the time is not valid, an empty string is returned. An example of the returned string is:

"Time 1 day ago"

Types

This section is empty.

Jump to

Keyboard shortcuts

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