|
1 | | -# coho |
| 1 | +# <img src="https://raw.githubusercontent.com/sockeye-d/coho/refs/heads/main/coho.svg" style="height: 1em; width: 1em"> coho |
2 | 2 |
|
| 3 | +Coho is a static website generator. |
| 4 | +The entire thing is built around the Kotlin scripting engine using a custom Kotlin DSL as a build script. |
| 5 | +This makes it significantly more flexible than existing solutions, since you basically get to build your own |
| 6 | +mini-framework on top of a coho. |
3 | 7 |
|
4 | | -Hallucinated API: |
| 8 | +Here's a rough list of features it has: |
5 | 9 |
|
6 | | -```kotlin |
7 | | -val source = FileSource("/path/to/source") |
| 10 | +* Kotlin DSL-based buildscript |
| 11 | +* Flexible Kotlin-powered templated HTML files (like PHP) |
| 12 | +* Live-reloading web server |
| 13 | +* Build-time syntax highlighting |
| 14 | +* [XML Kotlin DSL](https://fishies.dev/posts/new-xml-dsl) (that's right, *nested* DSLs) |
8 | 15 |
|
9 | | -root { |
10 | | - page("a") { |
11 | | - markdown(source.file("file.md")) |
12 | | - html(source.file("html-file.html")) |
13 | | - } |
14 | | -} |
| 16 | +For more information on why I made it, you can read my [webpage on it](https://fishies.dev/projects/coho), or |
| 17 | +my [blog post](https://fishies.dev/posts/coho). |
15 | 18 |
|
16 | | -// results in this file tree |
17 | | -// build/ |
18 | | -// build/a/file.html |
19 | | -// build/a/html-file.html |
| 19 | +## Getting started |
| 20 | + |
| 21 | +First, make sure you've got a Java Runtime Environment installed. |
| 22 | +I use Java 21, and you *might* get compatibility issues with lower versions because I haven't tested it. |
| 23 | + |
| 24 | +Next, go to the |
| 25 | +[Build gradle artifact](https://github.com/sockeye-d/coho/actions/workflows/gradle-artifact.yml) |
| 26 | +page, click the latest CI deployment, scroll to the bottom, and download the coho.jar artifact (you need to be |
| 27 | +signed in to do this — this is a GitHub requirement, not mine). |
| 28 | + |
| 29 | +Once you have the artifact downloaded, extract it and copy the `cli-all.jar` file somewhere. |
| 30 | + |
| 31 | +And then that's it! |
| 32 | + |
| 33 | +> You might want to add a script like this somewhere on your PATH: |
| 34 | +> ```bash |
| 35 | +> java -jar /path/to/cli-all.jar "$@" |
| 36 | +> ``` |
| 37 | +
|
| 38 | +> You can run `coho --print-shell-completions shell`, where `shell` is `nu` or `zsh`, and pipe that into wherever |
| 39 | +> your shell completions are stored. |
| 40 | +
|
| 41 | +## Creating your first project |
| 42 | +
|
| 43 | +In an empty directory (or non-empty), run |
| 44 | +
|
| 45 | +```bash |
| 46 | +coho --create serve |
| 47 | +``` |
| 48 | +
|
| 49 | +That'll create a template `main.coho.kts` file, an `index.md` file with some documentation, a Markdown template, and a |
| 50 | +stylesheet. From there, you can edit the files. |
| 51 | + |
| 52 | +`coho serve` will serve a live-updating web server. |
| 53 | +If you just want to build the website, run `coho`. |
| 54 | + |
| 55 | +> If your main coho script is not called `main.coho.kts`, you can do |
| 56 | +> ```bash |
| 57 | +> coho custom.coho.kts |
| 58 | +> ``` |
| 59 | +
|
| 60 | +### Debugging websites |
| 61 | +
|
| 62 | +You can run coho with extra debug information: |
| 63 | +
|
| 64 | +```bash |
| 65 | +coho --verbose |
| 66 | +``` |
| 67 | +
|
| 68 | +For debugging build performance, you can use the `--show-execution-times` flag: |
| 69 | + |
| 70 | +```bash |
| 71 | +coho --show-execution-times |
| 72 | +``` |
| 73 | + |
| 74 | +It'll print the output tree of the website along with how much time each element took to generate. |
| 75 | + |
| 76 | +## Example websites |
| 77 | + |
| 78 | +[My website](https://fishies.dev) is built using coho. You can view the entire source for it at |
| 79 | +[sockeye-d/sockeye-d.github.io](https://github.com/sockeye-d/sockeye-d.github.io). |
| 80 | + |
| 81 | +## Building coho |
| 82 | + |
| 83 | +If you want to build coho from source, make sure you've got an entire JDK (not just a JRE), then run |
| 84 | + |
| 85 | +```bash |
| 86 | +./gradlew shadowJar |
| 87 | +``` |
| 88 | + |
| 89 | +The built JAR file will be in `cli/build/libs/cli-all.jar`. |
| 90 | +You can run the `coho` script to run the freshly built JAR file. |
| 91 | + |
| 92 | +## Extra stuff |
| 93 | + |
| 94 | +Here's a random [ksyntaxhighlighter6](https://invent.kde.org/frameworks/syntax-highlighting/) definition for Kate |
| 95 | +for the templated HTML files: |
| 96 | + |
| 97 | +```xml |
| 98 | +<?xml version="1.0" encoding="UTF-8"?> |
| 99 | +<language name="Kotlin HTML" version="20" kateversion="5.79" section="Markup" extensions="*.html" mimetype="text/html" |
| 100 | + author="fishnpotatoes (me@fishies.dev)" license="LGPL" priority="11"> |
| 101 | + |
| 102 | + <highlighting> |
| 103 | + <contexts> |
| 104 | + |
| 105 | + <context name="Start" attribute="Normal Text" lineEndContext="#stay"> |
| 106 | + <StringDetect attribute="Preprocessor" context="Kotlin Inner" String="<?kt" /> |
| 107 | + <IncludeRules context="FindText##HTML" includeAttrib="true" /> |
| 108 | + <IncludeRules context="FindHTML##HTML" includeAttrib="true" /> |
| 109 | + </context> |
| 110 | + |
| 111 | + <context name="Kotlin Inner" attribute="Preprocessor" lineEndContext="#stay"> |
| 112 | + <Detect2Chars attribute="Preprocessor" char="?" char1=">" context="#pop"/> |
| 113 | + <IncludeRules context="Normal##Kotlin" includeAttrib="true" /> |
| 114 | + </context> |
| 115 | + |
| 116 | + </contexts> |
| 117 | + |
| 118 | + <itemDatas> |
| 119 | + <itemData name="Normal Text" defStyleNum="dsNormal" /> |
| 120 | + <itemData name="Preprocessor" defStyleNum="dsPreprocessor" bold="1" spellChecking="false" /> |
| 121 | + </itemDatas> |
| 122 | + |
| 123 | + </highlighting> |
| 124 | + |
| 125 | + <general> |
| 126 | + <comments> |
| 127 | + <comment name="multiLine" start="<!--" end="-->" region="comment" /> |
| 128 | + </comments> |
| 129 | + </general> |
| 130 | + |
| 131 | +</language> |
| 132 | +<!-- kate: replace-tabs on; tab-width 2; indent-width 2; --> |
20 | 133 | ``` |
0 commit comments