Documentation
¶
Overview ¶
Package bcontent ("base content") provides base types and functions shared by both content and the core build tool for content. This is necessary to ensure that the core build tool does not import GUI packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SpecialName ¶
SpecialName extracts a special element type name from given element name, defined as the part before the first underscore _ character.
func SpecialToKebab ¶
SpecialToKebab does strcase.ToKebab on parts after specialName if present.
Types ¶
type Page ¶
type Page struct {
// Source is the filesystem that the page is stored in.
Source fs.FS `toml:"-" json:"-"`
// Filename is the name of the file in [Page.FS] that the content is stored in.
Filename string `toml:"-" json:"-"`
// Name is the user-friendly name of the page, defaulting to the
// [strcase.ToSentence] of the [Page.Filename] without its extension.
Name string
// URL is the URL of the page relative to the root of the app, without
// any leading slash. It defaults to [Page.Name] in kebab-case
// (ex: "home" or "text-fields"). A blank URL ("") manually
// specified in the front matter indicates that this the root page.
URL string
// Title is the title displayed at the top of the page. It defaults to [Page.Name].
// Note that [Page.Name] is still used for the stage title and other such things; this
// is only for the actual title widget.
Title string
// Date is the optional date that the page was published.
Date time.Time `toml:"-"`
// DateString is only used for parsing the date from the TOML front matter.
DateString string `toml:"Date" json:"-"`
// Authors are the optional authors of the page.
Authors []string
// Draft indicates that the page is a draft and should not be visible on the web.
Draft bool
// Categories are the categories that the page belongs to.
Categories []string
// Specials are special content elements for each page
// that have names with an underscore-delimited key name,
// such as figure_, table_, sim_ etc, and can be referred
// to using the #id component of a wikilink. They are rendered
// using the index of each such element (e.g., Figure 1) in the link.
Specials map[string][]string
}
Page represents the metadata for a single page of content.
func NewPage ¶
NewPage makes a new page in the given filesystem with the given filename, sets default values, and reads metadata from the front matter of the page file.
func (*Page) Defaults ¶
func (pg *Page) Defaults()
Defaults sets default values for the page based on its filename.
func (*Page) ParseSpecials ¶
ParseSpecials manually parses specials before rendering md because they are needed in advance of generating from md file, e.g., for wikilinks.
func (*Page) ReadContent ¶
ReadContent returns the page content with any front matter removed. It also applies [Page.categoryLinks].
func (*Page) ReadMetadata ¶
ReadMetadata reads the page metadata from the front matter of the page file, if there is any.
func (*Page) SpecialLabel ¶
SpecialLabel returns the label for given special element, using the index of the element in the list of specials, e.g., "Figure 1"
type PreRenderPage ¶
type PreRenderPage struct {
Page
// Description is the automatic page description.
Description string
// HTML is the pre-rendered HTML for the page.
HTML string
}
PreRenderPage contains the data for each page printed in JSON by a content app run with the generatehtml tag, which is then handled by the core build tool.