https://github.com/shoriwe/static
A simple static frontend generator library in Go.
https://github.com/shoriwe/static
go static website
Last synced: over 1 year ago
JSON representation
A simple static frontend generator library in Go.
- Host: GitHub
- URL: https://github.com/shoriwe/static
- Owner: shoriwe
- License: mit
- Created: 2021-09-27T15:15:17.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-05-28T03:52:39.000Z (about 4 years ago)
- Last Synced: 2025-02-12T17:33:10.680Z (over 1 year ago)
- Topics: go, static, website
- Language: Go
- Homepage:
- Size: 1.4 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# static
A simple static frontend generator library.
## Examples
- [https://shoriwe.github.io/plasma/index.html](https://shoriwe.github.io/plasma/index.html)
## Features
- Go to JavaScript (**Powered by [GopherJS](https://github.com/gopherjs/gopherjs)**)
- Go to WASM (**Powered by the standard library**)
- Templating system
- Templating scripting (**Powered by [gplasma](https://github.com/shoriwe/gplasma)**)
## Important
If you are on **Windows** use the WSL to compile your project. This happens cause **GopherJS** still does not support
this platform.
## Quicklook
For this example we will virtually store our scripts in the root of our project, in a folder called `scripts`. Something
similar with the assets and templates.
`my-project/main.go`
```go
package main
import (
"github.com/shoriwe/static/pkg/engine"
)
func main() {
var (
templates engine.Templates
scripts engine.Scripts
assets engine.Assets
loadError error
)
templates, loadError = engine.LoadTemplates("./templates")
if loadError != nil {
panic(loadError)
}
scripts, loadError = engine.LoadScripts(
"./scripts", // This is the directory where the `Go` to then `JavaScript` scripts will be located
"js", // When the project start to be generated, the compiled JavaScript will be stored in this folder relative to the output one
)
if loadError != nil {
panic(loadError)
}
assets, loadError = engine.LoadAssets(
"./assets", // This is the directory where all static assets will be searched for
"static", // This is the directory where all assets will be stored once the project is generated.
)
if loadError != nil {
panic(loadError)
}
myProjectEngine := engine.NewEngine(
templates,
scripts,
assets,
)
handlingError := myProjectEngine.HandlePath("/index.html", // Define a new path to generate
func(e *engine.Engine) ([]byte, error) {
scriptUrl, getError := e.ScriptURL("hello-world")
if getError != nil {
return nil, getError
}
renderedTemplate, renderError := e.RenderTemplate(
"index.html", // Search for the index.html templates in the specified templates directory
map[string]string{
"url": scriptUrl,
},
)
if renderError != nil {
return nil, renderError
}
return e.MinifyHTML(renderedTemplate)
},
)
if handlingError != nil { // These throws and error when the path was already in use
panic(handlingError)
}
generationError := myProjectEngine.Generate("output/sample-1") // Create the path "output/sample-1" and write to it all assets, scripts and defined paths
if generationError != nil {
panic(generationError)
}
}
```
Finally, to generate the page simply execute in the root of your project
```shell
go run
```
## Documentation
You can find the documentation on the wiki section.