types

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package types provides common data types used across all Betula, all conveniently collected in a single box for resolving import cycles nicely.

Index

Constants

View Source
const ActivityType = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
View Source
const OtherActivityType = "application/activity+json"
View Source
const (
	PostsPerPage uint = 64
)
View Source
const TimeLayout = "2006-01-02 15:04:05"

TimeLayout is the time layout used across Betula.

Variables

This section is empty.

Functions

func CanonicalTagName added in v0.8.0

func CanonicalTagName(rawName string) string
func CleanerLink(a string) string

Same as CleanerLinkParts, but merges the parts back into one url.

func CleanerLinkParts added in v1.2.0

func CleanerLinkParts(a string) (string, string)

CleanerLinkParts returns the link a with https:// or http:// prefix and the / suffix, percent-encoding reversed and Punycode decoded.

Link is returned in two parts: scheme + authority and the rest (path, query, fragment).

func JoinTags added in v0.8.0

func JoinTags(tags []Tag) string

Types

type Actor added in v1.2.0

type Actor struct {
	ID                string `json:"id"`
	Inbox             string `json:"inbox"`
	PreferredUsername string `json:"preferredUsername"`
	DisplayedName     string `json:"name"`
	Summary           string `json:"summary,omitempty"`
	PublicKey         struct {
		ID           string `json:"id"`
		Owner        string `json:"owner"`
		PublicKeyPEM string `json:"publicKeyPem"`
	} `json:"publicKey,omitempty"`

	SubscriptionStatus SubscriptionRelation `json:"-"` // Set manually
	Domain             string               `json:"-"` // Set manually
}

func (Actor) Acct added in v1.2.0

func (a Actor) Acct() string

func (*Actor) Valid added in v1.2.0

func (a *Actor) Valid() bool

type Page added in v1.0.0

type Page struct {
	Number    uint
	URL       string
	IsCurrent bool
	IsPrev    bool
	IsNext    bool
}

func PaginatorFromURL added in v1.0.0

func PaginatorFromURL(url *url.URL, currentPage uint, totalPosts uint) (pages []Page)

type Post

type Post struct {
	// ID is a unique identifier of the post. Do not set this field by yourself.
	ID int
	// CreationTime is like 2006-01-02 15:04:05.
	CreationTime string
	// Tags are the tags this post has. Do not set this field by yourself.
	Tags []Tag

	// URL is a URL with any protocol.
	URL string
	// Title is a name for the link.
	Title string
	// Description is a Mycomarkup-formatted document. Currently, just unescaped plain text.
	Description string
	// Visibility sets who can see the post.
	Visibility Visibility
	// RepostOf is URL of the post reposted. Nil if this is an original post.
	RepostOf *string
}

Post is a link, along with some data.

type PostGroup added in v1.2.0

type PostGroup struct {
	Date  string
	Posts []Post
}

func GroupPostsByDate added in v1.2.0

func GroupPostsByDate(ungroupedPosts []Post) (groupedPosts []PostGroup)

GroupPostsByDate groups the posts by date. The dates are strings like 2024-01-10. This function expects the input posts to be sorted by date.

type RepostInfo added in v1.1.0

type RepostInfo struct {
	Timestamp time.Time
	URL       string
	Name      string
}

type Settings added in v0.7.0

type Settings struct {
	NetworkHost string
	NetworkPort uint
	// SiteName is a plaintext name of the site.
	SiteName string
	// SiteTitle is a hypertext title shown in the top left corner, in a <h1>.
	SiteTitle                 template.HTML
	SiteDescriptionMycomarkup string
	SiteURL                   string
	CustomCSS                 string
	FederationEnabled         bool
}

type SubscriptionRelation added in v1.2.0

type SubscriptionRelation string
const (
	SubscriptionNone          SubscriptionRelation = ""
	SubscriptionTheyFollow    SubscriptionRelation = "follower"
	SubscriptionIFollow       SubscriptionRelation = "following"
	SubscriptionMutual        SubscriptionRelation = "mutual"
	SubscriptionPending       SubscriptionRelation = "pending"
	SubscriptionPendingMutual SubscriptionRelation = "pending mutual" // yours pending, theirs accepted
)

func (SubscriptionRelation) IsPending added in v1.2.0

func (sr SubscriptionRelation) IsPending() bool

func (SubscriptionRelation) TheyFollowUs added in v1.2.0

func (sr SubscriptionRelation) TheyFollowUs() bool

type Tag added in v0.8.0

type Tag struct {
	Name        string
	Description string
	PostCount   uint
}

func SplitTags added in v0.8.0

func SplitTags(commaSeparated string) []Tag

func TagsFromStringSlice added in v1.1.0

func TagsFromStringSlice(ss []string) []Tag

type Visibility

type Visibility int

Visibility determines where the post is seen.

const (
	// Private posts are only seen by the author.
	Private Visibility = iota
	// Public posts are seen by everyone, and are federated.
	Public
)

func VisibilityFromString

func VisibilityFromString(s string) Visibility

VisibilityFromString turns a string into a Visbility.

Jump to

Keyboard shortcuts

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