diff --git a/.github/workflows/build-css.yaml b/.github/workflows/build-css.yaml new file mode 100644 index 0000000..a95cddc --- /dev/null +++ b/.github/workflows/build-css.yaml @@ -0,0 +1,37 @@ +name: Build Tailwind CSS + +on: + push: + paths: + - "handlers/form.html" + workflow_dispatch: + +jobs: + tailwindbuilder: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + - + name: Build Tailwind CSS + run: pnpm build + - + name: Commit generated stylesheet + run: | + if git diff --quiet; then + echo "No changes to commit." + exit 0 + else + echo "Changes detected, committing..." + git config --global user.name "Github action" + git config --global user.email "username@users.noreply.github.com" + git add cmd + git commit -m "Generated stylesheet" + git push + fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index fdf1127..27ff4d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ # dev binary ladder -VERSION \ No newline at end of file +VERSION +output.css +styles.css \ No newline at end of file diff --git a/README.md b/README.md index 7d5e14a..9d30f15 100644 --- a/README.md +++ b/README.md @@ -170,3 +170,13 @@ See in [ruleset.yaml](ruleset.yaml) for an example. - match: ^ # regex to match part of path replace: /amp/ # (modify the url from https://www.demo.com/article/ to https://www.demo.de/amp/article/) ``` + +## Development + +To run a development server at http://localhost:8080: + +```bash +RULETSET='RULESET="./ruleset.yaml" go run cmd/main.go' +``` + +This project uses [pnpm](https://pnpm.io/) to build a stylesheet with the [Tailwind CSS](https://tailwindcss.com/) classes. For local development, if you modify styles in `form.html`, run `pnpm build` to generate a new stylesheet. diff --git a/cmd/main.go b/cmd/main.go index 832e848..7b6138f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,7 +1,7 @@ package main import ( - _ "embed" + "embed" "fmt" "log" "os" @@ -17,6 +17,8 @@ import ( //go:embed favicon.ico var faviconData string +//go:embed styles.css +var cssData embed.FS func main() { parser := argparse.NewParser("ladder", "Every Wall needs a Ladder") @@ -75,6 +77,14 @@ func main() { } app.Get("/", handlers.Form) + app.Get("/styles.css", func(c *fiber.Ctx) error { + cssData, err := cssData.ReadFile("styles.css") + if err != nil { + return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") + } + c.Set("Content-Type", "text/css") + return c.Send(cssData) + }) app.Get("ruleset", handlers.Ruleset) app.Get("raw/*", handlers.Raw) diff --git a/handlers/form.html b/handlers/form.html index 52ea39f..a14f420 100644 --- a/handlers/form.html +++ b/handlers/form.html @@ -5,7 +5,7 @@ ladder - + @@ -20,12 +20,12 @@
-
-