<commit_before># static [![Build Status](https://travis-ci.org/leighmcculloch/static.svg?branch=master)](https://travis-ci.org/leighmcculloch/static)

A library for generating static websites from any Go web app that uses `net/http`. It helps you use build static websites that are dynamically generated from sources like RSS feeds, databases, APIs, etc by calling each handler registered and saving the output as files.

## Install

```bash
go get github.com/leighmcculloch/static
```

## Usage

Coming soon.

## Simple Example

Coming soon.

## Typical Example

See [github.com/leighmcculloch/readprayrepeat.com](https://github.com/leighmcculloch/readprayrepeat.com).

## Others

Inspired by [middleman](https://middlemanapp.com/), which is a much easier to use and has many more features.

If your static website needs don't require writing code, checkout [Hugo](https://gohugo.io).<commit_msg>Added example and usage to README.<commit_after># static [![Build Status](https://travis-ci.org/leighmcculloch/static.svg?branch=master)](https://travis-ci.org/leighmcculloch/static)

A library for generating static websites from any Go web app that uses `net/http`. It helps you use build static websites that are dynamically generated from sources like RSS feeds, databases, APIs, etc by calling each handler registered and saving the output as files.

## Install

```bash
go get github.com/leighmcculloch/static
```

## Usage

### With defaults

Call `Build` with a `http.Handler`, a `[]string` of paths to build to static files, and a callback for printing progress and errors which are communicated via events. The event handler can be `nil` but it's the only way you'll find out if there's an error building a path.

```go
static.Build(handler, paths, func (e static.Event) {
  log.Println(e)
})
```

### With more customization

Call `BuildOptions` in the same way as `Build`, with an extra parameter `static.Options`.

## Simple Example

Fire up the sample below. Running the Hello World web server is as you'd expect `go run *.go`, and then building the static version is as simple as `go run *.go -build`.

```go
package main

import (
  "net/http"
  "github.com/leighmcculloch/static"
)

var build bool

func init() {
  flag.BoolVar(&build, "build", false, "Build the website to static files rather than run the web server.")
  flag.Parse()
}

func main() {
  handler := http.NewServeMux()
  paths := []string{}

  paths = append(paths, "/")
  handler.HandleFunc("/", func(w http.ResponseWriter, r *http.Requests) {
    fmt.Fprintf(w, "Hello %s!", r.URL.Path)
  })

  if build {
    static.Build(handler, paths, func (e static.Event) {
      log.Println(e)
    })
  } else {
    s := &http.Server{Addr: ":8080", Handler: handler}
    log.Fatal(s.ListenAndServe())
  }
}
```

## Typical Example

See [github.com/leighmcculloch/readprayrepeat.com](https://github.com/leighmcculloch/readprayrepeat.com).

## Others

Inspired by [middleman](https://middlemanapp.com/), which is a much easier to use and has many more features.

If your static website needs don't require writing code, checkout [Hugo](https://gohugo.io).
{'fraction_non_alphanumeric': 0.1203585147247119, 'fraction_numerical': 0.0012804097311139564, 'mean_word_length': 4.332764505119454, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '29885', 'n_tokens_mistral': 1000, 'n_tokens_neox': 943, 'n_words': 346}