bcontent

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

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

This section is empty.

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

	// 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
}

Page represents the metadata for a single page of content.

func NewPage

func NewPage(source fs.FS, filename string) (*Page, error)

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) ReadContent

func (pg *Page) ReadContent(pagesByCategory map[string][]*Page) ([]byte, error)

ReadContent returns the page content with any front matter removed. It also applies [Page.categoryLinks].

func (*Page) ReadMetadata

func (pg *Page) ReadMetadata() error

ReadMetadata reads the page metadata from the front matter of the page file, if there is any.

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.

Jump to

Keyboard shortcuts

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