common

package
v0.0.0-...-5439d4c Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package common contains constants and functions shared by other packages.

Index

Constants

View Source
const (
	AddURLPath     = "add"
	ArchiveURLPath = "archive"
	AuthURLPath    = "auth"
	KindleURLPath  = "kindle"
	PagesURLPath   = "pages"
	StaticURLPath  = "static"

	AppCSSFile    = "app.css"
	CommonCSSFile = "common.css"
	PageCSSFile   = "page.css"

	// Query parameter names for HTTP requests.
	AddKindleParam = "k"
	AddURLParam    = "u"
	ArchiveParam   = "a"
	IDParam        = "i"
	RedirectParam  = "r"
	TokenParam     = "t"
)

Variables

This section is empty.

Functions

func GetHost

func GetHost(urlStr string) string

func LocalImageFilename

func LocalImageFilename(url string) string

func ReadJSONFile

func ReadJSONFile(path string, out interface{}) error

func SHA1String

func SHA1String(input string) string

func WriteHeader

func WriteHeader(w io.Writer, cfg *Config, stylesheets []string, title, favicon, author string)

WriteHeader writes everything up to the closing </head> tag.

func WriteTemplate

func WriteTemplate(w io.Writer, cfg *Config, t string, d interface{}, fm template.FuncMap) error

Types

type Config

type Config struct {
	// ParserPath contains the path to the mercury-parser executable,
	// e.g. "/home/user/.node/bin/mercury-parser". See installation instructions
	// at https://github.com/postlight/mercury-parser.
	ParserPath string `json:"parserPath"`
	// KindlegenPath contains the path to the kindlegen executable,
	// e.g. "/usr/local/bin/kindlegen". kindlegen is available from
	// https://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211.
	KindlegenPath string `json:"kindlegenPath"`
	// BaseURL contains the base URL at which the site is served,
	// e.g. "https://example.org/aread".
	BaseURL string `json:"baseUrl"`
	// StaticDir is the path to this repository's static/ directory,
	// e.g. "/home/user/aread/static".
	StaticDir string `json:"staticDir"`
	// PageDir is the directory under which pages will be saved,
	// e.g. "/var/lib/aread/pages".
	PageDir string `json:"pageDir"`
	// URLPatternsFile is the path to a file containing URL rewrite patterns,
	// e.g. "/var/lib/aread/url_patterns.json". The file consists of a JSON
	// array containing 2-element arrays with the source regular expression and
	// replacement pattern. For example:
	//
	//   [
	//     ["^(https?://)mobile\\.nytimes\\.com/", "${1}nytimes.com/"],
	//     ["([./]nytimes\\.com/.*)\\?.*$", "$1"]
	//   ]
	URLPatternsFile string `json:"urlPatternsFile"`
	// BadContentFile is the path to a file containing patterns used to
	// detect bad (e.g. paywalled) content. The file consists of a JSON array
	// containing 2-element arrays with a URL regular expresion and a string to
	// search for. For example:
	//
	//   [
	//     ["[./]nytimes\\.com/", "To save articles or get newsletters, alerts or recommendations"],
	//     ["[./]forbes\\.com/", "<span class=\"dynamic-css\">false</span>"],
	//     ["[./]time\\.com/", "One of the main ways we cover our costs is through advertising"]
	//   ]
	BadContentFile string `json:"badContentFile"`
	// HiddenTagsFile is the path to a file listing tags to strip out from
	// pages. The file consists of a JSON object, where keys are URL wildcards
	// and values are arrays of element.class patterns. For example:
	//   {
	//     "*": [
	//       "*.jp-relatedposts-headline",
	//       "div.articleOptions",
	//       "div.sharedaddy",
	//       "p.jp-relatedposts",
	//       "span.print-link"
	//     ],
	//     "adage.com": [
	//       "figcaption.*"
	//     ]
	//   }
	HiddenTagsFile string `json:"hiddenTagsFile"`
	// Database is the path to the SQLite database containing page information,
	// e.g. "/var/lib/aread/data/aread.db".
	Database string `json:"database"`
	// MailServer contains the SMTP server used to mail documents to Kindle
	// devices as "hostname:port", e.g. "localhost:25".
	MailServer string `json:"mailServer"`
	// Recipient contains the email address where documents should be mailed,
	// e.g. "my-name_123@kindle.com".
	Recipient string `json:"recipient"`
	// Sender contains the sender email address used when mailing documents,
	// e.g. "user@example.org".
	Sender string `json:"sender"`
	// Username contains a basic HTTP authentication username.
	Username string `json:"username"`
	// Password contains a basic HTTP authentication password.
	Password          string `json:"password"`
	FriendBaseURL     string `json:"friendBaseUrl"`
	FriendRemoteToken string `json:"friendRemoteToken"`
	FriendLocalToken  string `json:"friendLocalToken"`
	FriendTitlePrefix string `json:"friendTitlePrefix"`
	// DownloadImages controls whether a page's images should be downloaded.
	// It is true by default.
	DownloadImages bool `json:"downloadImages"`
	// MaxImageWidth contains the maximum width in pixels of downloaded images.
	// It defaults to 1024.
	MaxImageWidth int `json:"maxImageWidth"`
	// MaxImageHeight contains the maximum height in pixels of downloaded images.
	// It defaults to 768.
	MaxImageHeight int `json:"maxImageHeight"`
	// MaxImageBytes contains the maximum size of downloaded images.
	// Images larger than this after resizing will be deleted.
	MaxImageBytes int64 `json:"maxImageBytes"`
	// JPEGQuality contains the quality (up to 100) to use when saving JPEG
	// images after resizing them. It defaults to 85.
	JPEGQuality int `json:"jpegQuality"`
	// MaxImageProcs contains the maximum number of images to process
	// simultaneously. It defaults to 3.
	MaxImageProcs int `json:"maxImageProcs"`
	// DownloadFavicons controls whether pages' favicon images are saved.
	// It defaults to false.
	DownloadFavicons bool `json:"downloadFavicons"`
	// MaxListSize contains the maximum number of pages to list on the website.
	// It defaults to 50.
	MaxListSize int `json:"maxListSize"`
	// Verbose controls whether verbose logs are written.
	Verbose bool `json:"verbose"`
	// Logger is used to log messages.
	Logger *log.Logger `json:"-"`
}

Config contains the server's configuration.

func ReadConfig

func ReadConfig(p string, lg *log.Logger) (*Config, error)

ReadConfig returns a new Config based on the JSON file at p.

func (*Config) GetPath

func (cfg *Config) GetPath(p ...string) string

type PageInfo

type PageInfo struct {
	Id          string
	OriginalURL string
	Title       string
	TimeAdded   int64 // time_t
	Token       string
	FromFriend  bool
}

Jump to

Keyboard shortcuts

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