boondoggle

package module
v0.0.0-...-dd6dd12 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 24 Imported by: 0

README

   ___                    __               __
  / _ )___  ___  ___  ___/ /__  ___  ___  / /__
 / _  / _ \/ _ \/ _ \/ _  / _ \/ _ \/ _ \/ / -_)
/____/\___/\___/_//_/\___/\___/\_, /\_, /_/\__/
                              /___//___/

A static site generator written in Go.

Built solely for my personal website; you should probably use Hugo instead.

Time you enjoy wasting is not wasted time.

  • Marthe Troly-Curtin

Documentation

Overview

Copyright 2013 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Package slug transforms strings into a normalized form well suited for use in URLs.

Index

Constants

View Source
const (
	MarkdownExt = ".md" // MarkdownExt is the common markdown file ending
	HTMLExt     = ".html"
)
View Source
const (
	FrontMatterBlock = "---"
	CodeFence        = "```"
	NewLine          = "\n"
	Space            = " "
	TagsPrefix       = "<!-- tags:"    // TODO Rather unfriendly
	PreviewPrefix    = "<!-- preview:" // TODO Rather unfriendly
	ClosingComment   = "-->"
	TitleAtx         = "#"
	TitleSetext      = "="
)

All tokens that will be used by ad-hoc transformations

View Source
const ISO8601Date = "2006-01-02"

Variables

View Source
var ExampleArticleTemplate = template.Must(template.New("article").Parse(`<!DOCTYPE html>
<html>
  <head>
    <title>{{ .Title }}</title>
  </head>
  <body>
    <h1>{{ .Title }}</h1>
    <h4>{{ .Date.Format "Monday, January 2, 2006" }}<h4>
    {{ .HTML }}
  </body>
</html>
`))

Example Templates

View Source
var ExampleIndexTemplate = template.Must(template.New("index").Parse(`<!DOCTYPE html>
<html>
  <head>
    <title>My Site</title>
  </head>
  <body>
    {{ range $article := .Articles }}
    <article>
      <h1>{{ $article.Title }}</h1>
    </article>
    {{ end }}
  </body>
    }
</html>
`))
View Source
var ExampleTagsTemplate = template.Must(template.New("tags").Parse(`<!DOCTYPE html>
<html>
  <head>
    <title>Tags</title>
  </head>
  <body>
    <ul>
    {{ range $tag := .Tags }}
      <li>{{ $tag }}</li>
	  {{ end }}
	</ul>
  </body>
</html>
`))

Functions

func CauseError

func CauseError(article *Article) error

CauseError is an example Transformer that returns an error

func ChromaCode

func ChromaCode(article *Article) error

func ExtractFrontMatter

func ExtractFrontMatter(article *Article) (err error)

ExtractFrontMatter will parse and remove any Front Matter (https://jekyllrb.com/docs/frontmatter/) metadata tags from the raw markdown. For front matter to be parsed, the first line of the markdown must start with "---"

func ExtractPreview

func ExtractPreview(article *Article) (err error)

ExtractPreview will parse and remove a preview from raw markdown. The preview markdown will be converted to HTML after parsing.

func ExtractTags

func ExtractTags(article *Article) (err error)

ExtractTags will parse and remove the tags from the raw markdown. The Tags will be converted to slugs after parsing.

func ExtractTitle

func ExtractTitle(article *Article) (err error)

ExtractTitle will parse and remove an atx or setext H1 title from the first line (and second if setext) of the markdown file. TODO ExtractTitle will add a newline - it shouldn'y

func HumanizeBytes

func HumanizeBytes(size int) string

func IsSlugAscii

func IsSlugAscii(s string) bool

IsSlugAscii returns true only if SlugAscii(s) == s.

func MarkdownToHTML

func MarkdownToHTML(article *Article) (err error)

MarkdownToHTML will convert the raw markdown bytes to an HTML template.

func Noop

func Noop(article *Article) error

Noop is an example no-operation Transformer

func ParseFilename

func ParseFilename(article *Article) (err error)

ParseFilename will parse the filename for the slug and date. The filename must be in the format YYYY-MM-DD_title.md

func PygmentizeCode

func PygmentizeCode(article *Article) error

func Slug

func Slug(s string) string

Slug replaces each run of characters which are not unicode letters or numbers with a single hyphen, except for leading or trailing runs. Letters will be stripped of diacritical marks and lowercased. Letter or number codepoints that do not have combining marks or a lower-cased variant will be passed through unaltered.

func SlugAscii

func SlugAscii(s string) string

SlugAscii is identical to Slug, except that runs of one or more unicode letters or numbers that still fall outside the ASCII range will have their UTF-8 representation hex encoded and delimited by hyphens. As with Slug, in no case will hyphens appear at either end of the returned string.

func Slugify

func Slugify(input string) string

func SplitFilename

func SplitFilename(input string) (string, string)

Split a date and title from the given input

func UnSnakeCase

func UnSnakeCase(input string) string

Types

type Article

type Article struct {
	// Content
	Title    string
	Slug     string
	Date     time.Time
	Subtitle string
	Byline   string
	HTML     template.HTML

	// Meta
	Preview         template.HTML
	WordCount       uint64
	TableOfContents Section
	LinesOfCode     uint64
	Tags            []string
	Metadata        Attrs
	Now             time.Time
	Links           Links

	// Parsing
	ParseStart time.Time
	ParseEnd   time.Time

	Filename string
	Raw      []byte // The entire raw file
}

Article is a single article

func NewArticle

func NewArticle(filename string) Article

NewArticle creates a new article

func (Article) ParseDuration

func (article Article) ParseDuration() time.Duration

func (Article) RenderWith

func (article Article) RenderWith(tmpl *template.Template) ([]byte, error)

RenderWith renders the Article with the given Template

func (Article) SaveAs

func (article Article) SaveAs() string

SaveAs returns the filename for the output HTML file

func (Article) String

func (article Article) String() string

String returns the Article Title, or the Filename if there is no Title

func (*Article) Transform

func (article *Article) Transform(steps ...Transformer) error

Transform modifies the given Article, for instance by converting its markdown to HTML, or performing syntax highlighting

func (Article) URL

func (article Article) URL() string

URL returns the URL of the article

type Articles

type Articles []Article

Articles is a slice of articles

func (Articles) Len

func (a Articles) Len() int

Len returns the number of articles

func (Articles) SortMostRecentArticlesFirst

func (a Articles) SortMostRecentArticlesFirst()

SortMostRecentArticlesFirst will sort the articles by Date

func (Articles) Swap

func (a Articles) Swap(i, j int)

Swap is used to sort articles

type Attrs

type Attrs map[string]interface{}

func (Attrs) Merge

func (a Attrs) Merge(b map[string]interface{})

type Boondoggle

type Boondoggle struct {
	Links    Links // Writes URLs
	Articles Articles

	ByTitle map[string]Article
	ByTag   map[string]Articles

	Metadata  Attrs
	BuildTime time.Time
}

Boondoggle builds .html files from a directory of markdown files.

func New

func New() *Boondoggle

New creates a new Boondoggle. The New method does not need to be used directly - use ParseDirectory instead

func ParseDirectory

func ParseDirectory(path string, steps ...Transformer) (*Boondoggle, error)

ParseDirectory will parse all markdown files in the given directory

func (*Boondoggle) ReadDirectory

func (bd *Boondoggle) ReadDirectory(path string) error

func (Boondoggle) Tags

func (bd Boondoggle) Tags() (tags []string)

Tags returns tags in alphabetical order

type ByDate

type ByDate struct {
	Articles
}

ByDate will sort articles by timestamp

func (ByDate) Less

func (a ByDate) Less(i, j int) bool

type ByTitle

type ByTitle struct {
	Articles
}

ByTitle will sort the articles by slug

type Links interface {
	ForArticle(Article) string
}

type Section

type Section struct {
	Name     string
	Children []Section
}

Section is used to build the table of contents. It is a tree.

type Templates

type Templates map[string]*template.Template

func ParseTemplates

func ParseTemplates(path string) (Templates, error)

type Transformer

type Transformer func(*Article) error

Transformer is the type signature of functions that modify Article types

func Preview

func Preview(minLength int) Transformer

func TruncatedTagPreview

func TruncatedTagPreview(minLength int) Transformer

func (Transformer) String

func (t Transformer) String() string

String returns the name of the transformer function

type UseDefault

type UseDefault struct{}

func (UseDefault) ForArticle

func (links UseDefault) ForArticle(article Article) string

type UseSlugs

type UseSlugs struct{}

func (UseSlugs) ForArticle

func (links UseSlugs) ForArticle(article Article) string

Directories

Path Synopsis
cmd
Package syntax contains components to perform syntax highlighting
Package syntax contains components to perform syntax highlighting

Jump to

Keyboard shortcuts

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