bookmark

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package bookmark contains the bookmark record.

Index

Constants

View Source
const DefaultTag = "notag"

Variables

View Source
var (
	ErrBookmarkDuplicate       = errors.New("bookmark already exists")
	ErrBookmarkInvalidID       = errors.New("invalid bookmark id")
	ErrBookmarkNotFound        = errors.New("no bookmark found")
	ErrBookmarkTagsEmpty       = errors.New("tags cannot be empty")
	ErrBookmarkURLEmpty        = errors.New("URL cannot be empty")
	ErrBookmarkTitleRequired   = errors.New("title is required")
	ErrBookmarkUnknownField    = errors.New("bookmark field unknown")
	ErrBookmarkInvalidChecksum = errors.New("invalid checksum")
)

Functions

func ParseTags

func ParseTags(tags string) string

ParseTags normalizes a string of tags by separating them by commas, sorting them and ensuring that the final string ends with a comma.

from: "tag1, tag2, tag3 tag"
to: "tag,tag1,tag2,tag3,"

func UniqueTags added in v0.1.23

func UniqueTags(t []string) []string

UniqueTags returns a slice of unique tags.

func Validate

func Validate(b *Bookmark) error

Validate validates the bookmark.

func ValidateChecksumJSON added in v0.1.30

func ValidateChecksumJSON(b *BookmarkJSON) bool

Types

type Bookmark

type Bookmark struct {
	ID                int    `db:"id"                json:"id"`
	URL               string `db:"url"               json:"url"`               // URL of the bookmark.
	Tags              string `db:"tags"              json:"tags"`              // Tags for the bookmark, stored as a comma-separated string.
	Title             string `db:"title"             json:"title"`             // Title of the bookmark, retrieved from the website's metadata.
	Desc              string `db:"desc"              json:"desc"`              // Description of the bookmark.
	Notes             string `db:"notes"             json:"notes"`             // Notes
	CreatedAt         string `db:"created_at"        json:"created_at"`        // Timestamp when the bookmark was created.
	LastVisit         string `db:"last_visit"        json:"last_visit"`        // Timestamp of the last time the bookmark was visited.
	UpdatedAt         string `db:"updated_at"        json:"updated_at"`        // Timestamp of the last time the bookmark record was updated.
	VisitCount        int    `db:"visit_count"       json:"visit_count"`       // The number of times the bookmark has been visited.
	Favorite          bool   `db:"favorite"          json:"favorite"`          // Boolean indicating if the bookmark is marked as a favorite.
	FaviconURL        string `db:"favicon_url"       json:"favicon_url"`       // URL for the bookmark's favicon.
	FaviconLocal      string `db:"favicon_local"     json:"favicon_local"`     // Local path to the cached favicon file.
	Checksum          string `db:"checksum"          json:"checksum"`          // Checksum or hash (URL, Title, Description and Tags)
	ArchiveURL        string `db:"archive_url"       json:"archive_url"`       // Internet Archive URL
	ArchiveTimestamp  string `db:"archive_timestamp" json:"archive_timestamp"` // Internet Archive timestamp
	LastStatusChecked string `db:"last_checked"      json:"last_checked"`      // Last checked timestamp.
	HTTPStatusCode    int    `db:"status_code"       json:"status_code"`       // HTTP status code (200, 404, etc.)
	HTTPStatusText    string `db:"status_text"       json:"status_text"`       // OK, Not Found, etc
	IsActive          bool   `db:"is_active"         json:"is_active"`         // true if the URL is active (200-299)
}

Bookmark represents a bookmark.

func New

func New() *Bookmark

New creates a new bookmark.

func NewFromBuffer

func NewFromBuffer(buf []byte) (*Bookmark, error)

func NewFromJSON

func NewFromJSON(j *BookmarkJSON) *Bookmark

func (*Bookmark) Buffer

func (b *Bookmark) Buffer() []byte

func (*Bookmark) BufferNotes added in v0.1.29

func (b *Bookmark) BufferNotes() []byte

func (*Bookmark) Bytes

func (b *Bookmark) Bytes() []byte

func (*Bookmark) CheckStatus added in v0.1.22

func (b *Bookmark) CheckStatus(ctx context.Context) error

CheckStatus updates the bookmark's status fields.

func (*Bookmark) Domain

func (b *Bookmark) Domain() (string, error)

Domain returns the domain of a bookmark.

func (*Bookmark) Equals

func (b *Bookmark) Equals(o *Bookmark) bool

Equals reports whether b and o have the same URL, Tags, Title and Desc.

func (*Bookmark) Field

func (b *Bookmark) Field(f string) (string, error)

Field returns the value of a field.

func (*Bookmark) GPGPath

func (b *Bookmark) GPGPath(ext string) (string, error)

GPGPath returns the path to the GPG file.

domainHash -> urlHash.gpg

func (*Bookmark) GenChecksum added in v0.1.19

func (b *Bookmark) GenChecksum()

GenChecksum generates a checksum for the bookmark.

It uses the URL, Title, Description and Tags.

func (*Bookmark) HashDomain added in v0.1.21

func (b *Bookmark) HashDomain() (string, error)

HashDomain returns the hash domain of a bookmark.

func (*Bookmark) HashPath

func (b *Bookmark) HashPath() (string, error)

HashPath returns the hash path of a bookmark.

hashDomain + Checksum

func (*Bookmark) HashURL

func (b *Bookmark) HashURL() string

HashURL returns the hash of a bookmark URL.

func (*Bookmark) JSON

func (b *Bookmark) JSON() *BookmarkJSON

func (*Bookmark) JSONPath

func (b *Bookmark) JSONPath() (string, error)

JSONPath returns the path to the JSON file.

domain -> urlHash.json

type BookmarkJSON

type BookmarkJSON struct {
	// FIX: remove this struct
	ID                int      `json:"id"`
	URL               string   `json:"url"`
	Tags              []string `json:"tags"`
	Title             string   `json:"title"`
	Desc              string   `json:"desc"`
	Notes             string   `json:"notes"`
	CreatedAt         string   `json:"created_at"`
	LastVisit         string   `json:"last_visit"`
	UpdatedAt         string   `json:"updated_at"`
	VisitCount        int      `json:"visit_count"`
	Favorite          bool     `json:"favorite"`
	FaviconURL        string   `json:"favicon_url"`
	FaviconLocal      string   `json:"favicon_local"`
	Checksum          string   `json:"checksum"`
	ArchiveURL        string   `json:"archive_url"`       // Internet Archive URL
	ArchiveTimestamp  string   `json:"archive_timestamp"` // Internet Archive timestamp
	LastStatusChecked string   `json:"last_checked"`      // Last checked timestamp.
	HTTPStatusCode    int      `json:"status_code"`       // HTTP status code (200, 404, etc.)
	HTTPStatusText    string   `json:"status_text"`       // OK, Not Found, etc
	IsActive          bool     `json:"is_active"`         // true if the URL is active (200-299)
}

func NewJSON

func NewJSON() *BookmarkJSON

Jump to

Keyboard shortcuts

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