sitebuilder

package
v0.0.0-...-e24f8fb Latest Latest
Warning

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

Go to latest
Published: Mar 17, 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) error

Types

type BasicPageMarkdown

type BasicPageMarkdown struct {
	Page Page `yaml:"page"`
}

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          Page                   `yaml:"page"`
	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"`
	TemplateName string `yaml:"templateName" validate:"required,filepath"`
	RedirectURL  string `yaml:"redirectURL"` // Optional.

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

type PageRenderer

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

func NewPageRenderer

func NewPageRenderer(
	commonData CommonPageData,
	icons IconMap,
	projectCount int,
	basicPageCount int,
	otherPagesCount int,
) (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"`
	ProjectSlugs []string `yaml:"projectSlugs,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.
	// Optional if project page only needs Title, Path and TemplateName (these are set
	// automatically). Other fields can be set here, e.g. if project page should host a Go package.
	Page Page `yaml:"page"`
}

type ProjectPageTemplate

type ProjectPageTemplate struct {
	Meta    TemplateMetadata
	Project ProjectTemplate
}

type ProjectProfile

type ProjectProfile struct {
	Name    string `yaml:"name"     validate:"required"`
	Slug    string `yaml:"slug"     validate:"required"`
	TagLine string `yaml:"tagLine"  validate:"required"`
	// Optional if not included in index page.
	LogoPath              string `yaml:"logoPath" validate:"omitempty,filepath"`
	LogoAlt               string `yaml:"logoAlt"`
	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