render

package
v0.0.0-...-742e7c9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// Extensions for non-AMP and AMP pages.
	HTMLExt = ".html"
	AMPExt  = ".amp.html"

	IndexPage = indexFileBase + HTMLExt

	// FeedFile is the filename for the site's Atom feed.
	FeedFile = "atom.xml"
)
View Source
const IframeOutDir = "iframes"

IframeOutDir is the subdirectory under the output dir for generated iframe pages.

View Source
const (

	// WebPExt is the extension for generated WebP image files.
	WebPExt = ".webp"
)

Variables

This section is empty.

Functions

func Iframe

func Iframe(si SiteInfo, yb []byte) ([]byte, error)

Iframe renders and returns the framed page described by the supplied YAML data.

func Thumb

func Thumb(p string, width, height int) (string, error)

Thumb reads an image from p, scales it down to the supplied dimensions, and returns base64-encoded GIF data.

Types

type NavItem struct {
	// Name contains the short, human-readable name for the item that is displayed in the menu.
	Name string `yaml:"name"`
	// URL contains the non-root-relative URL for the item, e.g. "page.html" or "page.html#frag".
	// It may also be e.g. a "mailto:" link, or an empty string for the site's index page.
	URL string `yaml:"url"`
	// ID corresponds to the ID specified in the page linked to by the item.
	// It may be empty if the item doesn't correspond to the top of a page
	// (e.g. if it contains a fragment).
	ID string `yaml:"id"`
	// OmitFromMenu indicates that the item should not be displayed in the menu (unless the
	// described page itself is currently active).
	OmitFromMenu bool `yaml:"omit_from_menu"`
	// Children contains items nested under this one in the menu.
	Children []*NavItem `yaml:"children"`
}

NavItem describes a single item displayed in the site navigation menu.

func (n *NavItem) AMPURL() string

AMPURL returns the the AMP version of n.URL, e.g. "page.html#frag" becomes "page.amp.html#frag". If n does not represent a page, n.URL is returned unchanged.

func (n *NavItem) FindID(id string) *NavItem

FindID returns the item with the supplied ID (possibly n itself) rooted at n. Returns nil if the item is not found.

func (n *NavItem) HasID(id string) bool

HasID returns true if n has the supplied ID.

func (n *NavItem) IsBarePage() bool

IsBarePage returns true if n.URL represents a bare page without a fragment, e.g. "foo.html". If n does not represent a bare page, an empty string is returned.

func (n *NavItem) IsIndex() bool

IsIndex returns true if this item represents the site's index page.

func (n *NavItem) VisibleChildren() []*NavItem

VisibleChildren returns children that have not been explicitly omitted from the navigation menu.

type PageFeedInfo

type PageFeedInfo struct {
	Title   string
	Desc    string
	AbsURL  string
	Created time.Time
}

PageFeedInfo contains metadata about a page that is needed to generate an Atom feed.

func Page

func Page(si SiteInfo, id string, markdown []byte, amp bool) ([]byte, *PageFeedInfo, error)

Page renders and returns the page described by the supplied Markdown data. The id parameter specifies the page's default ID, although this can be overriden in the page block. The amp parameter specifies whether the AMP or non-AMP version of the page should be rendered. The returned feed info is nil if the page should not be included in the Atom feed.

type SiteInfo

type SiteInfo struct {
	// BaseURL is the base site URL with a trailing slash, e.g. "https://www.example.org/".
	BaseURL string `yaml:"base_url"`
	// TitleSuffix is appended to page titles that don't explicitly forbid it.
	TitleSuffix string `yaml:"title_suffix"`
	// DefaultDesc is used as the default meta description for pages.
	DefaultDesc string `yaml:"default_desc"`
	// ManifestPath contains the path to the web manifest file, e.g. "site.webmanifest".
	ManifestPath string `yaml:"manifest_path"`
	// FaviconPaths contains paths to favicon images in the order they should be listed.
	// See https://dev.to/masakudamatsu/favicon-nightmare-how-to-maintain-sanity-3al7.
	FaviconPaths []string `yaml:"favicon_paths"`
	// AppleTouchIconPath is the path to the apple-touch-icon image.
	// Per https://realfavicongenerator.net/faq, this should be a 180x180 PNG named "apple-touch-icon.png".
	AppleTouchIconPath string `yaml:"apple_touch_icon_path"`
	// NavText is displayed near the logo in the navigation area.
	NavText string `yaml:"nav_text"`
	// FeedTitle is used as the title for the RSS (Atom) feed.
	FeedTitle string `yaml:"feed_title"`
	// FeedDesc is used as the description for the RSS (Atom) feed.
	FeedDesc string `yaml:"feed_desc"`

	// LogoPathHTML is the image at the top of the page for non-AMP, e.g. "resources/logo-*.png".
	// The image's intrinsic dimensions for larger displays come from the smallest image.
	// The second-smallest image is used for mobile if it isn't a 2x version of the smallest image.
	LogoPathHTML string `yaml:"logo_path_html"`
	// LogoWidthHTML contains LogoPathHTML's width in pixels. Only needed for SVG.
	LogoWidthHTML int `yaml:"logo_width_html"`
	// LogoHeightHTML contains LogoPathHTML's height in pixels. Only needed for SVG.
	LogoHeightHTML int `yaml:"logo_height_html"`
	// LogoPathAMP is the AMP analogue to LogoPathHTML.
	LogoPathAMP string `yaml:"logo_path_amp"`
	// LogoWidthAMP contains LogoPathAMP's width in pixels. Only needed for SVG.
	LogoWidthAMP int `yaml:"logo_width_amp"`
	// LogoHeightAMP contains LogoPathAMP's height in pixels. Only needed for SVG.
	LogoHeightAMP int `yaml:"logo_height_amp"`
	// LogoAlt contains the alt text for the logo image.
	LogoAlt string `yaml:"logo_alt"`

	// NavTogglePath is the image used to expand or collapse the navbox on non-AMP mobile.
	NavTogglePath string `yaml:"nav_toggle_path"`
	// NavToggleWidth contains NavTogglePath's width in pixels. Only needed for SVG.
	NavToggleWidth int `yaml:"nav_toggle_width"`
	// NavToggleHeight contains NavTogglePath's height in pixels. Only needed for SVG.
	NavToggleHeight int `yaml:"nav_toggle_height"`

	// MenuButtonPath is the image used to show the menu on AMP.
	MenuButtonPath string `yaml:"menu_button_path"`
	// MenuButtonWidth contains MenuButtonPath's width in pixels. Only needed for SVG.
	MenuButtonWidth int `yaml:"menu_button_width"`
	// MenuButtonHeight contains MenuButtonPath's height in pixels. Only needed for SVG.
	MenuButtonHeight int `yaml:"menu_button_height"`

	// DarkButtonPath is the image used to toggle between light and dark mode.
	DarkButtonPath string `yaml:"dark_button_path"`
	// DarkButtonWidth contains DarkButtonPath's width in pixels. Only needed for SVG.
	DarkButtonWidth int `yaml:"dark_button_width"`
	// DarkButtonHeight contains DarkButtonPath's height in pixels. Only needed for SVG.
	DarkButtonHeight int `yaml:"dark_button_height"`

	// The following fields are used in structured data.
	AuthorName        string `yaml:"author_name"`
	AuthorEmail       string `yaml:"author_email"`
	PublisherName     string `yaml:"publisher_name"`
	PublisherLogoPath string `yaml:"publisher_logo_path"`

	// GoogleAnalyticsCode uniquely identifies the site, e.g. "UA-123456-1".
	// Google Analytics is only used for the AMP version of the page (typically served from a CDN),
	// and only if this field is non-empty.
	GoogleAnalyticsCode string `yaml:"google_analytics_code"`
	// GoogleMapsAPIKey is used for Google Maps API billing.
	// It is only needed if maps are embedded in the site.
	GoogleMapsAPIKey string `yaml:"google_maps_api_key"`
	// CloudflareAnalyticsToken identifies the site for Cloudflare Web Analytics,
	// e.g. "4d65822107fcfd524d65822107fcfd52". This is only used for the non-AMP version of the page,
	// and only if this field is non-empty.
	CloudflareAnalyticsToken string `yaml:"cloudflare_analytics_token"`
	// D3ScriptURL is the URL of the minified d3.js to use for graphs.
	// The CDN-hosted version of the file is used by default.
	D3ScriptURL string `yaml:"d3_script_url"`
	// ExtraStaticDirs contains extra dirs to copy into the output dir.
	// Keys are paths relative to the site dir and values are paths relative to the output dir.
	ExtraStaticDirs map[string]string `yaml:"extra_static_dirs"`

	// CodeStyleLight contains the Chroma style to use when highlighting code in the light theme.
	// See https://xyproto.github.io/splash/docs/all.html for available styles.
	CodeStyleLight string `yaml:"code_style_light"`
	// CodeStyleDark is like CodeStyleLight, but used for the dark theme.
	CodeStyleDark string `yaml:"code_style_dark"`
	// CodeForcePlain indicates that bold, italic, and underline formatting should be removed from
	// Chroma styles.
	CodeForcePlain bool `yaml:"code_force_plain"`

	// NavItems specifies the site's navigation hierarchy.
	NavItems []*NavItem `yaml:"nav_items"`

	// LinkTags is automatically generated from ManifestPath, FaviconPaths, and AppleTouchIconPath.
	LinkTags []linkTagInfo `yaml:"-"`

	// CloudflareAnalyticsScriptURL is sourced for Cloudflare Web Analytics.
	CloudflareAnalyticsScriptURL string `yaml:"-"`
	// CloudflareAnalyticsConnectPattern is a CSP connect-src pattern matching connections
	// made by CloudflareAnalyticsScriptURL.
	CloudflareAnalyticsConnectPattern string `yaml:"-"`

	// CompressPages specifies whether a .html.gz, gzip-compressed file should be generated
	// alongside every .html file. This is useful for web hosts that don't automatically compress
	// pages when they are being served.
	CompressPages bool `yaml:"compress_pages"`
	// contains filtered or unexported fields
}

SiteInfo specifies high-level information about the site.

func NewSiteInfo

func NewSiteInfo(p string) (*SiteInfo, error)

NewSiteInfo constructs a new SiteInfo from the YAML file at p.

func (*SiteInfo) AbsURL

func (si *SiteInfo) AbsURL(u string) (string, error)

AbsURL converts the supplied string into an absolute URL by appending it to si.BaseURL. Returns the unchanged string if it's already absolute. Returns an error if the URL is absolute but not prefixed by si.BaseURL.

func (*SiteInfo) CheckStatic

func (si *SiteInfo) CheckStatic(p string) error

CheckStatic returns an error if p (e.g. "foo/bar.png") doesn't exist in si.StaticDir, si.StaticGenDir, or in the matching si.ExtraStaticDirs source dir.

func (*SiteInfo) IframeDir

func (si *SiteInfo) IframeDir() string

func (*SiteInfo) InlineDir

func (si *SiteInfo) InlineDir() string

func (*SiteInfo) InlineGenDir

func (si *SiteInfo) InlineGenDir() string

func (*SiteInfo) PageDir

func (si *SiteInfo) PageDir() string

func (*SiteInfo) ReadInline

func (si *SiteInfo) ReadInline(fn string) string

ReadInline reads and returns the contents of the named file in si.InlineDir or si.InlineGenDir. It returns an empty string if the file does not exist and panics if the file cannot be read.

func (*SiteInfo) StaticDir

func (si *SiteInfo) StaticDir() string

func (*SiteInfo) StaticGenDir

func (si *SiteInfo) StaticGenDir() string

func (*SiteInfo) TemplateDir

func (si *SiteInfo) TemplateDir() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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