all repos — vite @ cf6acc3b2905bd905bd44805a159e4bb3b6072e6

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:"-"`
 33        Author          struct {
 34            Name  string `yaml:"name"`
 35            Email string `yaml:"email"`
 36        } `yaml:"author"`
 37        URL       string   `yaml:"url"`
 38        PreBuild  []string `yaml:"preBuild"`
 39        PostBuild []string `yaml:"postBuild"`
 40    }
 41
 42Example config: https://git.icyphox.sh/site/tree/config.yaml
 43
 44
 45SYNTAX HIGHLIGHTING
 46
 47vite uses chroma (https://github.com/alecthomas/chroma) for syntax
 48highlighting. Note that CSS is not provided, and will have to be
 49included by the user in the templates. A sample style can be generated
 50by running:
 51
 52    go run contrib/style.go > syntax.css
 53
 54
 55TEMPLATING
 56
 57Non-index templates have access to the below objects:
 58• Cfg: object of ConfigYaml
 59• Meta: map[string]string of the page's frontmatter metadata
 60• Body: Contains the HTML
 61
 62
 63Index templates have access to everything above, and an Extra object,
 64which is a slice of types.Post containing Body and Meta. This is useful
 65for iterating through to generate an index page.
 66Example: https://git.icyphox.sh/site/tree/templates/index.html
 67
 68Templates are written as standard Go templates (ref:
 69https://godocs.io/text/template), and can be loaded recursively.
 70Consider the below template structure:
 71
 72    templates/
 73    |-- blog.html
 74    |-- index.html
 75    |-- project/
 76        |-- index.html
 77        `-- project.html
 78
 79The templates under project/ are referenced as project/index.html.
 80This deserves mention because Go templates don't recurse into
 81subdirectories by default (template.ParseGlob uses filepath.Glob, and
 82doesn't support deep-matching, i.e. **).
 83
 84vite also supports templating generic YAML files. Take for instance,
 85pages/reading.yaml (https://git.icyphox.sh/site/blob/master/pages/reading.yaml):
 86
 87    meta:
 88      template: reading.html
 89      title: reading
 90      subtitle: Tracking my reading.
 91      description: I use this page to track my reading.
 92
 93    books:
 94      - 2024:
 95        - name: Dune Messiah
 96          link: https://en.wikipedia.org/wiki/Dune_Messiah
 97          author: Frank Herbert
 98          status: now reading
 99      - 2023:
100        - name: Dune
101          link: https://en.wikipedia.org/wiki/Dune_(novel)
102          author: Frank Herbert
103          status: finished
104
105vite will look for a 'meta' key in the YAML file, and use the 'template'
106specified to render the page. The rest of the YAML file is available to
107you in the template as a map[string]interface{} called Yaml.
108
109
110More templating examples can be found at:
111https://git.icyphox.sh/site/tree/templates
112
113
114FEEDS
115
116Atom feeds are generated for all directories under pages/. So
117pages/foo will have a Atom feed at build/foo/feed.xml.
118
119
120FILE TREE
121
122    .
123    |-- build/
124    |-- config.yaml
125    |-- pages/
126    |-- static/
127    |-- templates/
128
129The entire static/ directory gets copied over to build/, and can be
130used to reference static assets -- css, images, etc. pages/ supports
131only nesting one directory deep; for example: pages/blog/*.md will
132render, but pages/blog/foo/*.md will not.
133
134
135BUGS
136
137Or rather, (undocumented) features. There's probably a couple. If you are
138actually using this, feel free to reach out and I can try to help.