baja

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: MIT Imports: 17 Imported by: 0

README

baja

A minimal static site generator

Concept

Baja simply looks at a directory and find file recursive and render individual page in a layout plus an index page of each directory.

To look up the template for render, if it's a single page, it use themes/name/node.html. If it's an index, it used list.html.

Plus, if it has an index.html page, that template are used to render index of whole site. otherwise it used list.html.

Getting started

The API is similar to git

# First time, bootstrap
baja new

# Add a post
baja add directory/post/

# Import from Gist or Evernote
baja import url

# Spit out static file
baja build

# You need to have 
baja deploy s3

# of if you're using Github page
baja deploy github

Why the name

When my daughter started to speak, baja was one the word she kept saying for no reason. No one in family know what it means. It remains unknow nowsaday and she eventually stop saying when she know more words

But the word baja light up my days a lot.

Release

  • 2019/02/09: 0.0.2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build() int

Build executes template and content to generate our real static conent

func BuildIndex

func BuildIndex(dir string, nodes []*Node, current *Current)

func Clean

func Clean()

func CompileAsset added in v0.0.2

func CompileAsset(config *Config)

CompileAsset copy asset from theme or static into public and also generate a hash version of those file

func CompileNodes added in v0.0.2

func CompileNodes(db *NodeDB)

func CreateNode

func CreateNode(dir, title string) error

func FuncMaps added in v0.0.4

func FuncMaps() template.FuncMap

func Run

func Run(addr, public string)

func Serve

func Serve(addr, directory string) int

Build execute template and content to generate our real static conent

func Setup

func Setup(name string) error

Initalize a new blog directory

func Watch added in v0.0.3

func Watch(dir string) (*fsnotify.Watcher, error)

Types

type Config

type Config struct {
	Theme string `"yaml":theme`
	Site  string `"yaml":site`
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() *Config

func NewConfig

func NewConfig(path string) *Config

func (*Config) WriteFile

func (c *Config) WriteFile()

type Current added in v0.0.2

type Current struct {
	IsHome bool
	IsDir  bool
	IsTag  bool
	IsList bool

	CompiledAt time.Time
}

Current is a struct about various current state we pass to template to help us do some business logic depend on a context

type ListPage added in v0.0.2

type ListPage struct {
	Current   *Current
	Title     string
	Permalink string
	Nodes     []map[string]interface{}
}

ListPage is an index page, it isn't constructed from a markdown file but from a list of related markdown such as tag or category

type Node

type Node struct {
	Meta *NodeMeta
	Body template.HTML
	Name string // the filename without extension

	Raw           string
	Path          string
	BaseDirectory string // the directory without /content part
	// contains filtered or unexported fields
}

Node hold information of a specifc page we are rendering

func NewNode

func NewNode(path string) *Node

NewNode creates a *Node object from a path

func (*Node) Compile

func (n *Node) Compile()

func (*Node) FindTheme

func (n *Node) FindTheme(c *Config)

func (*Node) IsPage

func (n *Node) IsPage() bool

func (*Node) Parse

func (n *Node) Parse()

Parse reads the markdown and parse metadata and generate html

func (n *Node) Permalink() string

type NodeDB

type NodeDB struct {
	NodeList      []*Node
	DirectoryList []string
	Total         int
}

NodeDB is the in-memory database of all the page

func BuildDB added in v0.0.2

func BuildDB(config *Config) *NodeDB

func (*NodeDB) Append added in v0.0.2

func (db *NodeDB) Append(n *Node)

func (*NodeDB) ByCategory added in v0.0.2

func (db *NodeDB) ByCategory() map[string][]*Node

ByTag category groups node by category(category is the directoy name)

func (*NodeDB) ByTag added in v0.0.2

func (db *NodeDB) ByTag() map[string][]*Node

ByTag groups node by tag

func (*NodeDB) Publishable added in v0.0.2

func (db *NodeDB) Publishable() []*Node

Publishable returns a list of node that can be publish, as in non-draft mode or non page

type NodeMeta

type NodeMeta struct {
	Title         string
	Draft         bool
	Date          time.Time
	DateFormatted string
	Tags          []string
	Category      string
	Type          string
}

NodeMeta is meta data of a node, usually map directly to node toml metadata section

type Server

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

type Site

type Site struct {
	Name    string
	Author  string
	BaseUrl string

	Config *SiteConfig
}

Site stores information of this static site and various meta data

type SiteConfig

type SiteConfig struct {
	Name    string `"yaml":name`
	Author  string `"yaml":author`
	BaseURL string `"yaml":baseURL`
}

type Theme added in v0.0.4

type Theme struct {
	Name string
	// contains filtered or unexported fields
}

func GetTheme added in v0.0.4

func GetTheme(config *Config) *Theme

func (*Theme) FindTheme added in v0.0.4

func (t *Theme) FindTheme(n *Node)

func (*Theme) LayoutPath added in v0.0.4

func (t *Theme) LayoutPath(name string) string

func (*Theme) NodePath added in v0.0.4

func (t *Theme) NodePath(node string) string

func (*Theme) Path added in v0.0.4

func (t *Theme) Path() string

func (*Theme) SubPath added in v0.0.4

func (t *Theme) SubPath(subpath string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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