https://github.com/nirokay/websitegenerator
Basic library for generating static html/css written in Nim.
https://github.com/nirokay/websitegenerator
css-generator html-generator static-site-generator website website-development website-generation
Last synced: about 1 year ago
JSON representation
Basic library for generating static html/css written in Nim.
- Host: GitHub
- URL: https://github.com/nirokay/websitegenerator
- Owner: nirokay
- License: gpl-3.0
- Created: 2023-08-14T11:48:59.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T10:07:27.000Z (about 2 years ago)
- Last Synced: 2024-04-10T11:26:45.038Z (about 2 years ago)
- Topics: css-generator, html-generator, static-site-generator, website, website-development, website-generation
- Language: Nim
- Homepage: https://nirokay.github.io/nim-docs/websitegenerator/websitegenerator.html
- Size: 244 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WebsiteGenerator
## About
**websitegenerator** is a library that lets you generate static HTML and CSS files using Nim code.
## Documentation
See [here](https://nirokay.github.io/nim-docs/websitegenerator/websitegenerator.html) for in-depth
code documentation.
## Use cases
### Static site generation
Generating static sites is the primary focus of **websitegenerator**, especially if you have repetitive layouts
with only the inserted data changing across them.
### On-the-fly generation (for small projects)
You can use procs to template a HTML page or element and respond to HTTP requests with an HTTP-server.
For example [TheDictionary](https://github.com/nirokay/TheDictionary/), my attempt at an urban-dictionary
webserver clone, uses **websitegenerator** to send back data with very little client-side javascript.
## Examples
Some basic examples are located in [the examples directory](./examples/), so you can quickly know, if you want to use
this or not.
Another larger example with explanations is a runnable example viewable in
[the docs](https://nirokay.github.io/nim-docs/websitegenerator/websitegenerator.html)!
List of projects/sites using **websitegenerator**:
* [my homepage](https://nirokay.com/) ([source](https://github.com/src.nirokay.com/))
* [HzgShowAround](https://nirokay.com/HzgShowAround/) ([source](https://github.com/nirokay/HzgShowAround/))
* TheDictionary ([source](https://github.com/nirokay/TheDictionary/))
If you use this software to create a project/website: feel free to create a PR with the edited
`README.md` or message me somewhere, so you project can be included here.
## Flexible syntax
```nim
import websitegenerator
var
document: HtmlDocument = newHtmlDocument("index.html")
stylesheet: CssStyleSheet = newCssStyleSheet("styles.css")
# CSS: --------------------------------
stylesheet.add(
# CSS-like (sugar) syntax:
"h1"{
"text-align" := "center"
},
# Funky syntax:
newCssElement("p",
["color", $Red]
),
# Semi-funky syntax:
newCssClass("some-class",
color(rgb(69, 69, 69)),
backgroundColor($BlueViolet)
),
# Can be used together (but why would you want that?):
".another-class"{
textAlign("center"),
"color" := $Black,
["background-color", $White]
}
)
stylesheet.writeFile() # Writes file to disk
# HTML: -------------------------------
document.setStylesheet(stylesheet) # Adds "styles.css" to HTML head
document.addToHead(
title("Crazy Page!")
)
document.add( # `document.add` and `document.addToBody` are equivalent
h1("Hello world!"),
newHtmlElement("p", "This is some text"),
p(
"Elements are joined with " & $code(escapeHtmlText "
") & " in " & $code("p") & " tags.",
"Every newline\nas well!"
),
img("image.png", "Could not load image"), # Some procs have attributes available as args
p("More text").addattr("id", "id-more-text"), # But you can add attributes manually if needed
p("Ugly block")
.setId("id-ugly-block") # Procs for HTML attributes also available
.addStyle( # Inline CSS is supported
"color" := $White,
"background-color" := $Pink
)
)
document.writeFile() # Writes file to disk
```
## Installation
`nimble install websitegenerator`
## Licence
This projects codebase is distributed under the [GPL-3.0 licence](https://www.gnu.org/licenses/gpl-3.0.html).
However you may use any output from your project (generated HTML and CSS files) according to the MIT licence - basically
without any limitations on source distribution.