sitebuilder

package
v0.0.0-...-bd5a1bd Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectPageTemplateName = "project_page.html.tmpl"
	DefaultTechStackTitle   = "Built with"
)
View Source
const (
	BaseContentDir = "content"
	BaseOutputDir  = "static"

	PageTemplatesDir      = "templates/pages"
	ComponentTemplatesDir = "templates/components"

	IconDir = "img/icons"
)
View Source
const BasicPageTemplateName = "basic_page.html.tmpl"

Variables

View Source
var TemplateFunctions = template.FuncMap{
	"plus1": func(x int) int {
		return x + 1
	},
	"personalInfoTextWrapping": func(infoText string) template.HTML {
		words := strings.Split(infoText, " ")
		wordCount := len(words)
		if wordCount < 3 {
			return template.HTML(infoText)
		}

		var builder strings.Builder

		builder.WriteString(`<span class="whitespace-nowrap">`)

		cutoff := (wordCount - 1) / 2
		for i, word := range words {
			builder.WriteString(word)
			if i == cutoff {
				builder.WriteString("</span>")
			}
			if i != wordCount-1 {
				builder.WriteString(" ")
			}
		}

		return template.HTML(builder.String())
	},
}

Functions

func ExecCommand

func ExecCommand(printOutput bool, commandName string, args ...string) error

func FormatRenderedPages

func FormatRenderedPages() error

func GenerateTailwindCSS

func GenerateTailwindCSS(cssFileName string) error

func NewMarkdownRenderer

func NewMarkdownRenderer(opts ...html.Option) render.NodeRenderer

func RenderPages

func RenderPages(
	contentPaths ContentPaths,
	commonData CommonPageData,
	icons IconMap,
	devMode bool,
) error

Types

type BasicPageMarkdown

type BasicPageMarkdown struct {
	Page `yaml:",inline"`
}

type BasicPageTemplate

type BasicPageTemplate struct {
	Meta    TemplateMetadata
	Content template.HTML
}

type CommonPageData

type CommonPageData struct {
	SiteName         string `validate:"required"`
	SiteDescription  string `validate:"required"`
	BaseURL          string `validate:"required,url"`
	GitHubIssuesLink string `validate:"required,url"`
	// contains filtered or unexported fields
}

func (CommonPageData) GitHubIcon

func (commonData CommonPageData) GitHubIcon() template.HTML

type ContentPaths

type ContentPaths struct {
	IndexPage   string
	ProjectDirs []string
	BasicPages  []string
}

type GoPackage

type GoPackage struct {
	RootName  string `yaml:"rootName"  validate:"required"`
	GitHubURL string `yaml:"githubURL" validate:"required,url"`
}

type IconMap

type IconMap map[string]*struct {
	Icon                  string `validate:"required,filepath"`
	Link                  string `validate:"omitempty,url"`
	IndexPageFallbackIcon string `validate:"omitempty,filepath"`
}

type Image

type Image struct {
	Path   string `yaml:"path"   validate:"required,filepath"`
	Alt    string `yaml:"alt"    validate:"required"`
	Width  int    `yaml:"width"  validate:"required"`
	Height int    `yaml:"height" validate:"required"`
}

type IndexPageBase

type IndexPageBase struct {
	ProfilePictureMobile  Image `yaml:"profilePictureMobile"`
	ProfilePictureDesktop Image `yaml:"profilePictureDesktop"`
}

type IndexPageMarkdown

type IndexPageMarkdown struct {
	IndexPageBase `                       yaml:",inline"`
	Page          `                       yaml:",inline"`
	PersonalInfo  PersonalInfoMarkdown   `yaml:"personalInfo"`
	ProjectGroups []ProjectGroupMarkdown `yaml:"projectGroups,flow" validate:"required,dive"`
}

type IndexPageTemplate

type IndexPageTemplate struct {
	IndexPageBase
	Meta          TemplateMetadata
	AboutMe       template.HTML
	PersonalInfo  []LinkItem // May omit Link field.
	ProjectGroups []ProjectGroupTemplate
}

type LinkGroup

type LinkGroup struct {
	Title string `yaml:"title"`
	// May omit Icon field.
	Links []LinkItem `yaml:"links,flow"`
}

type LinkItem

type LinkItem struct {
	Text string        `yaml:"text" validate:"required"`
	Link string        `yaml:"link" validate:"omitempty,url"`
	Icon template.HTML `yaml:"icon" validate:"omitempty,filepath"`
}

type MarkdownRenderer

type MarkdownRenderer struct {
	html.Config
}

Custom markdown renderer which:

  • adds class="break-words" to all links, and target="_blank" to all external links
  • adds stand-alone images as <figure>, with alt text in a <figcaption>

Rendering implementations are based on the originals from Goldmark: https://github.com/yuin/goldmark/blob/b2df67847ed38c31cf4f9e32483377a8e907a6ae/renderer/html/html.go

func (MarkdownRenderer) RegisterFuncs

func (renderer MarkdownRenderer) RegisterFuncs(registerer render.NodeRendererFuncRegisterer)

func (MarkdownRenderer) RenderImage

func (renderer MarkdownRenderer) RenderImage(
	writer util.BufWriter,
	source []byte,
	node ast.Node,
	entering bool,
) (ast.WalkStatus, error)
func (renderer MarkdownRenderer) RenderLink(
	writer util.BufWriter,
	source []byte,
	node ast.Node,
	entering bool,
) (ast.WalkStatus, error)

func (MarkdownRenderer) RenderParagraph

func (renderer MarkdownRenderer) RenderParagraph(
	writer util.BufWriter,
	source []byte,
	node ast.Node,
	entering bool,
) (ast.WalkStatus, error)

type Page

type Page struct {
	Title        string `yaml:"title"        validate:"required"`
	Path         string `yaml:"path"         validate:"required,startswith=/"`
	TemplateName string `yaml:"templateName" validate:"required,filepath"`
	RedirectPath string `yaml:"redirectPath"` // Optional.

	// Must be set with [Page.SetCanonicalURL] after parsing.
	CanonicalURL string

	// Nil if page does not host a Go package.
	GoPackage *GoPackage `yaml:"goPackage" validate:"omitempty"`
}

func (*Page) SetCanonicalURL

func (page *Page) SetCanonicalURL(baseURL string)

type PageRenderer

type PageRenderer struct {
	// contains filtered or unexported fields
}

func NewPageRenderer

func NewPageRenderer(
	commonData CommonPageData,
	icons IconMap,
	projectCount int,
	basicPageCount int,
	otherPagesCount int,
	devMode bool,
) (PageRenderer, error)

func (*PageRenderer) BuildSitemap

func (renderer *PageRenderer) BuildSitemap() error

func (*PageRenderer) RenderBasicPage

func (renderer *PageRenderer) RenderBasicPage(contentPath string) (err error)

func (*PageRenderer) RenderIcons

func (renderer *PageRenderer) RenderIcons() (err error)

func (*PageRenderer) RenderIndexPage

func (renderer *PageRenderer) RenderIndexPage(contentPath string) (err error)

func (*PageRenderer) RenderProjectPage

func (renderer *PageRenderer) RenderProjectPage(projectFile ProjectContentFile) (err error)

type ParsedProject

type ParsedProject struct {
	ProjectTemplate
	Page       Page
	ContentDir string
}

type ParsedProjectGroup

type ParsedProjectGroup struct {
	ProjectGroupTemplate
	// contains filtered or unexported fields
}

type ParsedProjectGroups

type ParsedProjectGroups struct {
	// contains filtered or unexported fields
}

func (*ParsedProjectGroups) AddIfIncluded

func (groups *ParsedProjectGroups) AddIfIncluded(project ParsedProject) error

func (*ParsedProjectGroups) IsFull

func (groups *ParsedProjectGroups) IsFull() bool

func (*ParsedProjectGroups) ToSlice

func (groups *ParsedProjectGroups) ToSlice() []ProjectGroupTemplate

type PersonalInfoMarkdown

type PersonalInfoMarkdown struct {
	Birthday    string `yaml:"birthday"    validate:"required"`
	Location    string `yaml:"location"    validate:"required"`
	GitHubURL   string `yaml:"githubURL"   validate:"required,url"`
	LinkedInURL string `yaml:"linkedinURL" validate:"required,url"`
}

type ProjectBase

type ProjectBase struct {
	ProjectProfile `yaml:",inline"`
	// Optional, defaults to DefaultTechStackTitle when TechStack is not empty.
	TechStackTitle string        `yaml:"techStackTitle"`
	LinkGroups     []LinkGroup   `yaml:"linkGroups,flow"` // Optional.
	Footnote       template.HTML `yaml:"footnote"`        // Optional.
}

type ProjectContentFile

type ProjectContentFile struct {
	// contains filtered or unexported fields
}

type ProjectGroupMarkdown

type ProjectGroupMarkdown struct {
	Title        string   `yaml:"title"             validate:"required"`
	ProjectPaths []string `yaml:"projectPaths,flow" validate:"required,dive"`
	ContentDir   string   `yaml:"contentDir"        validate:"required"`
}

type ProjectGroupTemplate

type ProjectGroupTemplate struct {
	Title    string
	Projects []ProjectProfile
}

type ProjectMarkdown

type ProjectMarkdown struct {
	ProjectBase `                        yaml:",inline"`
	TechStack   []TechStackItemMarkdown `yaml:"techStack,flow"` // Optional.
}

type ProjectPageTemplate

type ProjectPageTemplate struct {
	Meta    TemplateMetadata
	Project ProjectTemplate
}

type ProjectProfile

type ProjectProfile struct {
	Page    `yaml:",inline"`
	Name    string `yaml:"name"    validate:"required"`
	TagLine string `yaml:"tagLine" validate:"required"`
	Logo struct {
		Path    string `yaml:"path" validate:"omitempty,filepath"`
		AltText string `yaml:"altText"`
	} `yaml:"logo"`
	IndexPageFallbackIcon template.HTML
}

type ProjectTemplate

type ProjectTemplate struct {
	ProjectBase
	Description template.HTML
	TechStack   []TechStackItemTemplate
}

type TechStackItemMarkdown

type TechStackItemMarkdown struct {
	Tech     string   `yaml:"tech"          validate:"required"`
	UsedFor  string   `yaml:"usedFor"`       // Optional.
	UsedWith []string `yaml:"usedWith,flow"` // Optional.
}

type TechStackItemTemplate

type TechStackItemTemplate struct {
	LinkItem
	UsedFor  string
	UsedWith []LinkItem
}

type TemplateMetadata

type TemplateMetadata struct {
	Common CommonPageData
	Page   Page
}

Jump to

Keyboard shortcuts

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