types

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: AGPL-3.0 Imports: 10 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 BookmarksPerPage uint = 64

BookmarksPerPage is the maximum number of bookmarks that fits on one page. It is hardcoded and not configurable by design. 64 was chosen because it is a nice round number. Small enough to keep the web pages reasonable sized. Big enough to rarely use the paginator.

View Source
const OtherActivityType = "application/activity+json"
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

CleanerLink is the 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 Bookmark added in v1.3.0

type Bookmark struct {
	// ID is a unique identifier of the bookmark. 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 bookmark.
	Title string
	// Description is a Mycomarkup-formatted document.
	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
	// OriginalAuthor is ID of the author of the original bookmark. Might be invalid even if RepostOf is not nil
	OriginalAuthor sql.NullString
}

Bookmark is a link, along with some data.

type LocalBookmarkGroup added in v1.3.0

type LocalBookmarkGroup struct {
	Date      string
	Bookmarks []Bookmark
}

func GroupLocalBookmarksByDate added in v1.3.0

func GroupLocalBookmarksByDate(ungroupedBookmarks []Bookmark) (groupedBookmarks []LocalBookmarkGroup)

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

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 RemoteBookmark added in v1.3.0

type RemoteBookmark struct {
	ID       string
	RepostOf sql.NullString
	ActorID  string

	Title                 string
	URL                   string
	DescriptionHTML       template.HTML
	DescriptionMycomarkup sql.NullString
	PublishedAt           string
	UpdatedAt             sql.NullString
	Activity              []byte

	Tags []Tag
}

type RemoteBookmarkGroup added in v1.3.0

type RemoteBookmarkGroup struct {
	Date      string
	Bookmarks []RenderedRemoteBookmark
}

func GroupRemoteBookmarksByDate added in v1.3.0

func GroupRemoteBookmarksByDate(ungroupedBookmarks []RenderedRemoteBookmark) (groupedBookmarks []RemoteBookmarkGroup)

GroupRemoteBookmarksByDate groups the bookmarks by date. The dates are strings like 2006-01-02T15:04:05Z07:00 (ActivityPub-style). This function expects the input bookmarks to be sorted by date.

type RenderedRemoteBookmark added in v1.3.0

type RenderedRemoteBookmark struct {
	ID string

	AuthorAcct          string
	AuthorDisplayedName string
	RepostOf            sql.NullString

	Title       string
	URL         string
	Description template.HTML
	Tags        []Tag
	PublishedAt time.Time
}

type RepostInfo added in v1.1.0

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

type Session added in v1.3.0

type Session struct {
	Token        string
	CreationTime time.Time
	UserAgent    string
	Current      bool
}

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

func (SubscriptionRelation) WeFollowThem added in v1.3.0

func (sr SubscriptionRelation) WeFollowThem() bool

type Tag added in v0.8.0

type Tag struct {
	Name          string
	Description   string
	BookmarkCount 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.

Perhaps in the future Unlisted visibility will also be introduced, see https://todo.sr.ht/~bouncepaw/betula/65

const (
	// Private bookmarks are only seen by the author.
	Private Visibility = iota
	// Public bookmarks 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