shorteners

package
v0.0.0-...-3e27f85 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package shorteners provides utilities for retrieving information about URL shortening websites.

Index

Constants

This section is empty.

Variables

View Source
var Allst = &Shortener{
	Name:     "a-ll-st",
	Host:     "a.ll.st",
	Prefix:   "http://a.ll.st/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",

	Pattern: regexp.MustCompile(`^[0-9A-Za-z_]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {
		if strings.HasPrefix(shortcode, "scmf/") {
			shortcode = shortcode[strings.LastIndexByte(shortcode, '/')+1:]
		}
		return shortcode
	},
	IsVanityFunc: func(shortcode string) bool {
		return len(shortcode) != 6 || strings.ContainsRune(shortcode, '_')
	},
	HasVanity: true,
}

Allst describes the Allstate a.ll.st link shortener.

View Source
var Bfytw = &Shortener{
	Name:     "bfy-tw",
	Host:     "bfy.tw",
	Prefix:   "https://bfy.tw/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	Pattern:  regexp.MustCompile(`^[0-9A-Za-z]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {
		return bfytwTrailing.ReplaceAllLiteralString(shortcode, "")
	},
	HasVanity: false,
}

Bfytw describes the bfy.tw link shortener. All URLs redirect to https://lmgtfy.app/?q=<query>

View Source
var Debli = &Shortener{
	Name:     "deb-li",
	Host:     "deb.li",
	Prefix:   "https://deb.li/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	Pattern:  regexp.MustCompile(`^[0-9A-Za-z]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {

		if strings.ContainsRune(shortcode, '@') {
			return ""
		}

		shortcode = strings.TrimPrefix(shortcode, "p/")

		if strings.ContainsRune(shortcode, '/') || strings.ContainsRune(shortcode, '.') {
			return ""
		}
		return shortcode
	},
	HasVanity: true,
}

Debli describes the Debian deb.li link shortener.

View Source
var GoHawaiiEdu = &Shortener{
	Name:     "go-hawaii-edu",
	Host:     "go.hawaii.edu",
	Prefix:   "https://go.hawaii.edu/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	Pattern:  regexp.MustCompile(`^[0-9A-Za-z]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {
		if strings.ContainsRune(shortcode, '/') {
			return ""
		}
		switch shortcode {
		case "admin", "submit":
			return ""
		}

		return strings.TrimSuffix(shortcode, "+")
	},
	HasVanity: false,
}

GoHawaiiEdu describes the University of Hawaii go.hawaii.edu link shortener.

View Source
var Lookup = make(map[string]*Shortener)
View Source
var MobyTo = &Shortener{
	Name:     "moby-to",
	Host:     "moby.to",
	Prefix:   "http://moby.to/",
	Alphabet: "0123456789abcdefghijklmnopqrstuvwxyz",
	Pattern:  regexp.MustCompile("^[0-9a-z]+$"),
	CleanFunc: func(shortcode string, u *url.URL) string {
		if strings.ContainsRune(shortcode, '/') {
			return ""
		}

		if i := strings.IndexAny(shortcode, ":-+*."); i != -1 {
			shortcode = shortcode[:i]
		}
		return strings.ToLower(shortcode)
	},
	HasVanity: false,
}

MobyTo describes the Mobypicture moby.to link shortener.

View Source
var Qrcx = &Shortener{
	Name:      "qr-cx",
	Host:      "qr.cx",
	Prefix:    "http://qr.cx/",
	Alphabet:  "123456789ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	Pattern:   regexp.MustCompile(`^[1-9A-HJ-Za-z]+$`),
	CleanFunc: cleanQrcx,
	HasVanity: false,
}

Qrcx describes the qr.cx link shortener.

View Source
var Rbgy = &Shortener{
	Name:     "rb-gy",
	Host:     "rb.gy",
	Prefix:   "https://rb.gy/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	Pattern:  regexp.MustCompile(`^[0-9A-Za-z]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {

		shortcode = trimAfterAny(shortcode, "+/._-:$@◄")

		shortcode = rbgyNonAlpha.ReplaceAllLiteralString(shortcode, "")

		if len(shortcode) > 6 {
			shortcode = shortcode[:6]
		}
		return strings.ToLower(shortcode)
	},
	HasVanity: false,
}

Rbgy describes the rb-gy link shortener, which is powered by Rebrandly.

View Source
var RedHt = &Shortener{
	Name:     "red-ht",
	Host:     "red.ht",
	Prefix:   "https://red.ht/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",

	Pattern: regexp.MustCompile(`^[0-9A-Za-z\-_]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {

		if strings.ContainsRune(shortcode, '.') {
			return ""
		}

		return trimAfterByte(shortcode, '@')
	},
	IsVanityFunc: func(shortcode string) bool {
		return strings.ContainsAny(shortcode, "-_")
	},
	HasVanity: true,
}

RedHt describes the Red Hat red.ht link shortener.

View Source
var SUconnEdu = &Shortener{
	Name:     "s-uconn-edu",
	Host:     "s.uconn.edu",
	Prefix:   "https://s.uconn.edu/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	Pattern:  regexp.MustCompile(`^[0-9A-Za-z\-_]+$`),
	CleanFunc: func(shortcode string, u *url.URL) string {

		if strings.ContainsRune(shortcode, '/') {
			return ""
		}

		return strings.ToLower(shortcode)
	},
	IsVanityFunc: func(shortcode string) bool {
		return strings.ContainsRune(shortcode, '-')
	},
	HasVanity: true,
}

SUconnEdu describes the University of Connecticut s.uconn.edu link shortener.

View Source
var ShortIm = &Shortener{
	Name:     "short-im",
	Host:     "short.im",
	Prefix:   "http://short.im/",
	Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",

	Pattern:   regexp.MustCompile(`^[0-9A-Za-z\-_]+$`),
	CleanFunc: cleanShortIm,
	HasVanity: true,
}

ShortIm describes the Short.i'm short.im link shortener.

Functions

This section is empty.

Types

type CleanFunc

type CleanFunc func(shortcode string, u *url.URL) string

type IsVanityFunc

type IsVanityFunc func(shortcode string) bool

type Shortener

type Shortener struct {
	Name         string
	Host         string
	Prefix       string
	Alphabet     string
	Pattern      *regexp.Regexp
	CleanFunc    CleanFunc
	IsVanityFunc IsVanityFunc
	HasVanity    bool
}

func (*Shortener) Clean

func (s *Shortener) Clean(shortURL string) (string, error)

Clean extracts the shortcode from a URL. An empty string is returned when no shortcode can be found.

func (*Shortener) CleanURL

func (s *Shortener) CleanURL(u *url.URL) (string, error)

CleanURL extracts the shortcode from a URL. An empty string is returned when no shortcode can be found.

func (*Shortener) CleanURLs

func (s *Shortener) CleanURLs(urls []string) ([]string, error)

CleanURLs extracts, deduplicates, and sorts the shortcodes in slice of URLs.

func (*Shortener) GetIAShortcodes

func (s *Shortener) GetIAShortcodes() ([]string, error)

GetIAShortcodes queries all the shortcodes that have been archived on the Internet Archive.

func (*Shortener) IsVanity

func (s *Shortener) IsVanity(shortcode string) bool

IsVanity returns true when a shortcode is a vanity code. There are many false negatives for vanity codes that are programmatically indistinguishable from generated codes.

func (*Shortener) Sort

func (s *Shortener) Sort(shortcodes []string)

Sort sorts shorter codes first and generated codes before vanity codes.

Directories

Path Synopsis
Package bitly handles the bit.ly link shortener and its aliases.
Package bitly handles the bit.ly link shortener and its aliases.
Package wwiki handles the Wikimedia w.wiki link shortener.
Package wwiki handles the Wikimedia w.wiki link shortener.

Jump to

Keyboard shortcuts

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