all repos — vite @ bce0b549b8c10271ee7df30d6d7c78af2675cf6c

a fast (this time, actually) and minimal static site generator

readme (view raw)

  1vite
  2----
  3
  4A fast (this time, actually) and minimal static site generator.
  5
  6INSTALLING
  7
  8    go install git.icyphox.sh/vite@latest
  9
 10
 11USAGE
 12
 13    usage: vite [options]
 14
 15    A simple and minimal static site generator.
 16
 17    options:
 18        init PATH                   create vite project at PATH
 19        build                       builds the current project
 20        new PATH                    create a new markdown post
 21        serve [HOST:PORT]           serves the 'build' directory
 22
 23
 24CONFIG
 25
 26The configuration is unmarshalled from a config.yaml file, into the
 27below struct:
 28
 29    type ConfigYaml struct {
 30        Title           string `yaml:"title"`
 31        Desc            string `yaml:"description"`
 32        DefaultTemplate string `yaml:"default-template"`
 33        Author          struct {
 34            Name  string `yaml:"name"`
 35            Email string `yaml:"email"`
 36        } `yaml:"author"`
 37        URL string `yaml:"url"`
 38    }
 39
 40Example config: https://git.icyphox.sh/site/tree/config.yaml
 41
 42
 43SYNTAX HIGHLIGHTING
 44
 45vite uses chroma (https://github.com/alecthomas/chroma) for syntax
 46highlighting. Note that CSS is not provided, and will have to be
 47included by the user in the templates. A sample style can be generated
 48by running:
 49
 50    go run contrib/style.go > syntax.css
 51
 52
 53TEMPLATING
 54
 55Non-index templates have access to the below objects:
 56• Cfg: object of ConfigYaml
 57• Meta: map[string]string of the page's frontmatter metadata
 58• Body: Contains the HTML
 59
 60Index templates have access to everything above, and a Posts object,
 61which is a slice containing HTML and Meta. This is useful for iterating
 62through to generate an index page.
 63Example: https://git.icyphox.sh/site/tree/templates/index.html
 64
 65Templates are written as standard Go templates (ref:
 66https://godocs.io/text/template), and can be loaded recursively.
 67Consider the below template structure:
 68
 69    templates/
 70    |-- blog.html
 71    |-- index.html
 72    |-- project/
 73        |-- index.html
 74        `-- project.html
 75
 76The templates under project/ are referenced as project/index.html.
 77This deserves mention because Go templates don't recurse into
 78subdirectories by default (template.ParseGlob uses filepath.Glob, and
 79doesn't support deep-matching, i.e. **).
 80
 81vite also supports templating generic YAML files. Take for instance,
 82pages/reading.yaml (https://git.icyphox.sh/site/blob/master/pages/reading.yaml):
 83
 84    meta:
 85      template: reading.html
 86      title: reading
 87      subtitle: Tracking my reading.
 88      description: I use this page to track my reading. 
 89
 90    books:
 91      - 2024:
 92        - name: Dune Messiah
 93          link: https://en.wikipedia.org/wiki/Dune_Messiah
 94          author: Frank Herbert
 95          status: now reading
 96      - 2023:
 97        - name: Dune
 98          link: https://en.wikipedia.org/wiki/Dune_(novel)
 99          author: Frank Herbert
100          status: finished
101
102vite will look for a 'meta' key in the YAML file, and use the 'template'
103specified to render the page. The rest of the YAML file is available to
104you in the template as a map[string]interface{} called Yaml.
105
106
107More templating examples can be found at:
108https://git.icyphox.sh/site/tree/templates
109
110
111FEEDS
112
113Atom feeds are generated for all directories under pages/. So
114pages/foo will have a Atom feed at build/foo/feed.xml.
115
116
117FILE TREE
118
119    .
120    |-- build/
121    |-- config.yaml
122    |-- pages/
123    |-- static/
124    |-- templates/
125
126The entire static/ directory gets copied over to build/, and can be
127used to reference static assets -- css, images, etc. pages/ supports
128only nesting one directory deep; for example: pages/blog/*.md will
129render, but pages/blog/foo/*.md will not.