Documentation
¶
Index ¶
- Constants
- Variables
- func ClassifyPageType(mode ViewMode, view ViewType) string
- func FormatRelativeTimeSince(t time.Time) string
- func RenderBreadcrumbComponent(w io.Writer, data BreadcrumbData) error
- type AnalyticsData
- type ArticleData
- type BannerData
- type BreadcrumbData
- type BreadcrumbPart
- type CommandData
- type Component
- type DirData
- type DirLinkType
- type FilesLinks
- type FooterData
- type FooterLink
- type FooterSection
- type FullFileLink
- type HeadData
- type HeaderData
- type HeaderLink
- type HeaderLinks
- type HelpData
- type HelpFunction
- type HelpTocData
- type HelpTocItem
- type IndexData
- type QueryParam
- type RealmData
- type RealmTOCData
- type RedirectData
- type SourceData
- type SourceTocData
- type SourceTocItem
- type StatusData
- type TemplateComponent
- type TocItem
- type UserContribution
- type UserContributionType
- type UserData
- type UserLink
- type UserLinkType
- type View
- func DirectoryView(pkgPath string, files []string, fileCounter int, linkType DirLinkType, ...) *View
- func HelpView(data HelpData) *View
- func NewTemplateView(typ ViewType, name string, data any) *View
- func RealmView(data RealmData) *View
- func RedirectView(data RedirectData) *View
- func SourceView(data SourceData) *View
- func StatusErrorComponent(message string) *View
- func StatusNoRenderComponent(pkgPath string) *View
- func UserView(data UserData) *View
- type ViewMode
- type ViewType
Constants ¶
const ( OutboundDocs = "docs" OutboundFaucet = "faucet" OutboundStatus = "status" OutboundGitHub = "github" OutboundTwitter = "twitter" OutboundDiscord = "discord" OutboundYouTube = "youtube" )
Outbound* labels are emitted as data-outbound on tagged links so the SimpleAnalytics auto-events script fires outbound_<label> events. The set must stay in sync with the enum in frontend/js/analytics.ts and the values documented in SIMPLEANALYTICS.md.
const ( SourceViewType ViewType = "source-view" ReadmeFileName string = "README.md" )
const ( UserContributionTypeRealm = iota UserContributionTypePackage )
const MaxBannerLength = 400
MaxBannerLength is the maximum character length for banner markdown source.
const RedirectViewType = "redirect-view"
Variables ¶
var ReLicenseFileName *regexp.Regexp = regexp.MustCompile(`(?i)^licen[cs]e(.md|.txt)?$`)
Functions ¶
func ClassifyPageType ¶
ClassifyPageType returns the page-type label for a given mode and view. View type takes precedence over mode: a Source view inside a Realm mode is classified as "source", not "realm", so the analytics label matches the rendered surface rather than the containing layout mode.
func FormatRelativeTimeSince ¶
func RenderBreadcrumbComponent ¶
func RenderBreadcrumbComponent(w io.Writer, data BreadcrumbData) error
Types ¶
type AnalyticsData ¶
type AnalyticsData struct {
Enabled bool
PageType string
// Path is the analytics pageview path (see analyticsPath) rendered as
// data-sa-path; the client reports it to SimpleAnalytics in place of the
// raw pathname.
Path string
ChainId string
AssetsPath string
BuildTime string
// Hostname, when non-empty, is rendered as data-hostname on the
// SimpleAnalytics script tag to override the hostname SA reports.
// Set this when the site listens on a host SA would otherwise report
// incorrectly (for example a non-default port in local development).
Hostname string
}
AnalyticsData holds the SimpleAnalytics metadata rendered into the page.
type ArticleData ¶
type BannerData ¶
type BannerData struct {
// contains filtered or unexported fields
}
BannerData holds pre-rendered inline HTML from markdown.
func NewBannerData ¶
func NewBannerData(markdown, globalURL string) (BannerData, error)
NewBannerData parses inline markdown into a BannerData with pre-rendered HTML. Content after the first newline is discarded. Content is truncated to MaxBannerLength runes. If globalURL is non-empty (http/https only), the banner acts as a single clickable link and any inline markdown links are unwrapped to plain text.
func (BannerData) Enabled ¶
func (b BannerData) Enabled() bool
func (BannerData) HasURL ¶
func (b BannerData) HasURL() bool
func (BannerData) URL ¶
func (b BannerData) URL() string
type BreadcrumbData ¶
type BreadcrumbData struct {
Parts []BreadcrumbPart
ArgParts []BreadcrumbPart
Queries []QueryParam
}
type BreadcrumbPart ¶
type CommandData ¶
type DirData ¶
type DirData struct {
PkgPath string
FileCounter int
FilesLinks FilesLinks
Mode ViewMode
Readme Component
}
type DirLinkType ¶
type DirLinkType int
const ( DirLinkTypeSource DirLinkType = iota DirLinkTypeFile )
func (DirLinkType) LinkPrefix ¶
func (d DirLinkType) LinkPrefix(pkgPath string) string
LinkPrefix returns the prefixed link depending on link type
type FooterData ¶
type FooterData struct {
}
func EnrichFooterData ¶
func EnrichFooterData(data FooterData) FooterData
type FooterLink ¶
type FooterLink struct {
// data-outbound on the link so SimpleAnalytics fires a named
// outbound_<label> event instead of an anonymous outbound click.
Outbound string
}
type FooterSection ¶
type FooterSection struct {
}
type FullFileLink ¶
FullFileLink represents a package entry in the directory listing.
type HeaderData ¶
type HeaderData struct {
RealmPath string
RealmURL weburl.GnoURL
Breadcrumb BreadcrumbData
Links HeaderLinks
ChainId string
Remote string
Mode ViewMode
Static bool
}
func EnrichHeaderData ¶
func EnrichHeaderData(data HeaderData, mode ViewMode) HeaderData
type HeaderLink ¶
type HeaderLink struct {
Label string
URL string
Icon string
IsActive bool
// Outbound, when set to one of the Outbound* constants, is rendered as
// data-outbound on the link so SimpleAnalytics fires a named
// outbound_<label> event instead of an anonymous outbound click.
Outbound string
}
func StaticHeaderDevLinks ¶
func StaticHeaderDevLinks(u weburl.GnoURL, mode ViewMode, static bool) []HeaderLink
func StaticHeaderGeneralLinks ¶
func StaticHeaderGeneralLinks() []HeaderLink
type HeaderLinks ¶
type HeaderLinks struct {
General []HeaderLink
Dev []HeaderLink
}
type HelpData ¶
type HelpData struct {
// Selected function
SelectedFunc string
SelectedArgs map[string]string
SelectedSend string
RealmName string
Functions []HelpFunction
ChainId string
Remote string
PkgPath string
PkgFullPath string
Doc Component
Domain string
Origin string // request scheme+host; makes help URLs shareable
}
type HelpFunction ¶
HelpFunction pairs a doc.JSONFunc with its documentation already rendered as an HTML Component, so the template can embed it via `{{ render . }}`.
type HelpTocData ¶
type HelpTocData struct {
Icon string
Items []HelpTocItem
}
type HelpTocItem ¶
type IndexData ¶
type IndexData struct {
HeadData
HeaderData
BodyView *View
Mode ViewMode
Theme string
Banner BannerData
}
type QueryParam ¶
type RealmData ¶
type RealmData struct {
ComponentContent Component
TocItems *RealmTOCData
}
type RealmTOCData ¶
type RealmTOCData struct {
Items []*TocItem
}
type RedirectData ¶
type RedirectData struct {
To string
Analytics AnalyticsData
}
type SourceData ¶
type SourceData struct {
PkgPath string
Files []string
FileName string
FileSize string
FileLines int
FileCounter int
FileDownload string
FileSource Component
}
SourceData holds data for rendering a source code view.
func (SourceData) ArticleClasses ¶
func (d SourceData) ArticleClasses() string
ArticleClasses returns the CSS classes based on file type.
func (SourceData) WrappedSource ¶
func (d SourceData) WrappedSource() Component
WrappedSource returns a Component: raw for README.md, or code_wrapper otherwise.
type SourceTocData ¶
type SourceTocData struct {
Icon string
ReadmeFile SourceTocItem
LicenseFile SourceTocItem
GnoFiles []SourceTocItem
GnoTestFiles []SourceTocItem
TomlFiles []SourceTocItem
}
type SourceTocItem ¶
SourceTocItem represents an item in the source view table of contents.
type StatusData ¶
StatusData holds the dynamic fields for the "status" template
type TemplateComponent ¶
type TemplateComponent struct {
// contains filtered or unexported fields
}
type UserContribution ¶
type UserContributionType ¶
type UserContributionType int
func (UserContributionType) String ¶
func (typ UserContributionType) String() string
type UserData ¶
type UserData struct {
Username string
Handlename string
Bio string
Teams []struct{}
Links []UserLink
Contributions []UserContribution
PackageCount int
RealmCount int
PureCount int
Content Component
}
UserData contains data for the user view
type UserLink ¶
type UserLink struct {
Type UserLinkType
URL string
Title string
}
type UserLinkType ¶
type UserLinkType string
const ( UserLinkTypeGithub UserLinkType = "github" UserLinkTypeTwitter UserLinkType = "twitter" UserLinkTypeDiscord UserLinkType = "discord" UserLinkTypeTelegram UserLinkType = "telegram" UserLinkTypeLink UserLinkType = "link" )
type View ¶
View represents a UI component with a type and underlying component.
func DirectoryView ¶
func DirectoryView(pkgPath string, files []string, fileCounter int, linkType DirLinkType, mode ViewMode, readme ...Component) *View
DirectoryView creates a directory view
func NewTemplateView ¶
NewTemplateView creates a new View with a template component and data.
func RedirectView ¶
func RedirectView(data RedirectData) *View
func SourceView ¶
func SourceView(data SourceData) *View
SourceView creates a new View for displaying source code and its table of contents.
func StatusErrorComponent ¶
StatusErrorComponent returns a view for error scenarios with a message.
func StatusNoRenderComponent ¶
StatusNoRenderComponent returns a view for non-error notifications when Render() is not implemented.
type ViewMode ¶
type ViewMode int
ViewMode represents the current view mode of the application It affects the layout, navigation, and display of content
func (ViewMode) ShouldShowDevTools ¶
ShouldShowDevTools returns whether dev tools should be shown for this mode
func (ViewMode) ShouldShowGeneralLinks ¶
ShouldShowGeneralLinks returns whether general navigation links should be shown
type ViewType ¶
type ViewType string
ViewType represents the type of a view component.
const DirectoryViewType ViewType = "dir-view"
const HelpViewType ViewType = "help-view"
const RealmViewType ViewType = "realm-view"
const StatusViewType ViewType = "status-view"
const UserViewType ViewType = "user-view"