diff --git a/README.md b/README.md index 82cead2..ef7d0b6 100644 --- a/README.md +++ b/README.md @@ -1,119 +1,23 @@ -# hugo-htmx-go-template +# Garbage Speak -Make static Hugo sites dynamic with htmx and go +A fun and useless website -This is a project template combining [Hugo](https://gohugo.io), [htmx](https://htmx.org), and an optional API server written in Go, using `html/template` or [templ](https://github.com/a-h/templ/) for HTML rendering. +## Migrations -## Why? +Migrations required `go-migrate` to be run locally: -Hugo is a fantastic static site building tool, and there are few things about Hugo that can or should be improved. +`go install github.com/golang-migrate/migrate@v4` -The existence of this project template does not suggest that all static sites should be dynamic. If your site _can_ be static, it _should_ be static. +### Adding migrations -Yet there are instances in which one might want to add dynamic functionality to static Hugo sites. That is the purpose of this project template. Not to make all static sites dynamic, but to provide a simple solution to add islands of dynamic behavior to static sites. +`migrate create -ext sql -dir migrations -seq name_of_migration` -This allows us to build fast, easily deployable HTML content, with the added ability of meeting a new class dynamic behavior needs. +### Running migrations -Example use cases include +Migrate up -- Contact forms -- Comment systems -- Up/Down vote systems -- You know ... website stuff +`migrate -database ${POSTGRESQL_URL} -path migrations up` -You shouldn't have to reach for a SaaS product to offer dynamic content on your static sites. - -## About - -**First of all, what is meant by "project template"?** - -This git repository is to be used as a template from which to create Hugo sites. It does not impose any constraints on how you use Hugo. It is, itself, a simple hugo project created with `hugo site new ...`. You can run `hugo serve` from this project's root directory and it will behave like every other Hugo site you've developed. - -**So what _does_ this template provide?** - -This template provides example code and simple developer tooling for running Hugo along with an optional API server, written in Go, using `html/template`. - -**What developer tooling is provided?** - -1. `bin/develop`: This utility both starts the hugo server (`hugo server`) and the API server (`go run server.go`) for development. If the user has `air` installed (https://github.com/cosmtrek/air), API server code will hot-reload when changes to server.go are made. -2. `bin/build`: This utility builds a binary with your entire Hugo site embedded within. This allows Hugo sites to be deployed as a self-contained binary. - -## Getting Started - -**Clone this project template and initialize it**: - -```bash -git clone git@github.com:acaloiaro/hugo-htmx-go-template.git ./my_new_site -cd my_new_site -# The theme 'ananke' is used here because it's the one used by Hugo's quickstart guide: https://gohugo.io/getting-started/quick-start/ -# You can use any theme with this project template, so long as you add htmx to its included scripts: -# fetch-deps.sh does this automatically for the ananke theme -git clone https://github.com/theNewDynamic/gohugo-theme-ananke ./themes/ananke -bin/fetch-deps.sh -go build -o bin/develop internal/cmd/develop/main.go -go build -o bin/build internal/cmd/build/main.go -mkdir public && touch public/.empty -``` - -If you'll be using the API server, it's useful to install `air` to hot redeploy Go code changes when running `bin/develop`: - -```bash -go install github.com/cosmtrek/air@latest -``` - -To make changes to `templ` templates (.templ files), first install `templ`. Using `templ` is optional. The [goodbye world](https://github.com/acaloiaro/hugo-htmx-go-template/blob/main/server.go#L83) example shows `templ` in action. - -```bash -go install github.com/a-h/templ/cmd/templ@latest -``` - -## Run - -To start the development server(s), run `bin/develop` - -Hugo will run on its develop port at [http://localhost:1313](http://localhost:1313) and the API server runs on [http://localhost:1314](http://localhost:1314). - -Example content is available at: [http://localhost:1313/posts/hello-world/](http://localhost:1313/posts/hello-world/) - -`bin/build` can be used to build fat binaries of your Hugo site, which will be available at [http://localhost:1314](http://localhost:1314) after running `build/server`. - -![screenshot](https://user-images.githubusercontent.com/3331648/248586236-1ad03704-4f13-418c-aa9a-3122742c6b8c.png) - -## Changing `templ` templates - -To use `templ` templates, you will need to `templ` installed. The `air` configuration watches for changes to `templ` files and automatically builds them. - -## Deploy - -Hugo sites made from this template project can be deployed in two ways. - -### Traditional deployment - -A traditional deployment is any deployment where Hugo content is deployed to an HTTP server that serves static content. Deploying Hugo content with this project template remains the same as a usual Hugo site. - -However, to use the API server in production, you'll need to tell your static site content where to send HTTP requests. - -Configure this in `config/production/hugo.toml` - -If you've made your API available at `https://api.example.com`, add the following to `hugo.toml`: - -``` -[Params] - apiBaseUrl = 'https://api.example.com' -``` - -The API server binary can be had by using `bin/build` to generate a fat binary, or simply compiling `server.go` directly: `go -o build/server server.go` - -### Fat binary deployment - -Fat binary deployment is made possible by `bin/build`. The `build/server` executable contains both the API server code and Hugo static site content. - -No additional configuration is necessary to deploy a fat binary. Simply copy `build/server` to the system that will run it. - -**Note:** To build fat binaries for different systems/architectures than the system performing the build, use the `GOOS` and `GOARCH` to change system/architecture, e.g. - -Build a fat binary for OpenBSD and AMD64 architecture -```bash -GOOS=openbsd GOARCH=amd64 bin/build -``` +Migrate down +`migrate -database ${POSTGRESQL_URL} -path migrations down` diff --git a/content/dictionary.md b/content/dictionary.md index 644fd0e..9f812e5 100644 --- a/content/dictionary.md +++ b/content/dictionary.md @@ -2,6 +2,6 @@ title: "Dictionary" --- -Solutionizing a dictionary is a heavy lift. We encourage you to come back as your thought leaders have _temporarily_ put a pin in the dictionary initiative. +Solutionizing a dictionary is a heavy lift. We encourage you to return at a later time, as your thought leaders have _temporarily_ put a pin in the dictionary initiative. Many syncs are planned for this section's go-to-market. Rest assured it is coming. diff --git a/content/faq.md b/content/faq.md index 6e83d35..37f70da 100644 --- a/content/faq.md +++ b/content/faq.md @@ -1,7 +1,49 @@ --- title: "FAQ" +toc: true --- +## What is garbage speak? + +Garbage speak is a community of thought leaders solving the world's language asks. + +In this community we share out and collect all the key learnings of our ever-evolving language. + +We are the value drivers, and we are here to futureproof the English language against stagnation. + +We verb nouns and noun adjectives. + +**We speak like our boss' bosses.** + +## Can you show me the science? + +Garbage speak is more feeling than science. While it often adheres to common formulas: nouning verbs, verbing nouns, and nouning adjectives. But truly novel garbage is a complex animal that can't be pinned down. + +With that complexity in mind, the thought leaders have synced and we're happy to share out these garbage speak examples with accompanying analysis to help aspiring thought leaders navigate the garbage space. + +--- + +**Garbage speak**: Is there a solve for this? + +**Analysis**: The speaker has nouned the verb _solve_. They are asking if there is a solution. + +--- + +**Garbage speak** +Can we circle back to the ask here? + +**Analysis** +_Circle back_ is a garbage speak mainstay meaning "return" or "get back on topic". The verb _ask_ has been nouned. + +--- + +**Garbage speak** +We'd like to be intentional about the space we give our employees. + +**Analysis** +This is complex. _Intentional_ is being used not to communicate intention, but to communicate that the speaker is hip to therapy speak -- a sub genre of garbage speak. _Space_ is used in the same way, but it's serving a dual role. Its second role is that of a deeply ambiguous word that fills literal space in a sentence, making the speaker sound more like their boss. Is it physical space, emotional space (therapy speak), or some amalgamation of both (safe space)? It doesn't matter -- anything can be space in garbage speak. + + ## What are the rules for thought leaders posting new garbage speak? You can post any garbage speak seen in the wild, so long as it is not embellished and does not identify any individuals or companies. @@ -12,7 +54,7 @@ If the garbage speak is _not_ proprietary, e.g. an internal company Slack conver ## Do I need to sign up to anything to become a thought leader? -Currently, no. But we may require registration in the future to combat spam / ensure that repeat embellishment offenders don't abuse the system. +Yes. We require registration to combat spam / ensure that repeat embellishment offenders don't abuse the system. ## What's the go-to-market for future features? diff --git a/content/post.md b/content/post.md new file mode 100644 index 0000000..e69de29 diff --git a/content/posts/new.md b/content/posts/new.md new file mode 100644 index 0000000..5cec4b2 --- /dev/null +++ b/content/posts/new.md @@ -0,0 +1,53 @@ +--- +title: New Garbage +--- + +{{< html.inline >}} +
+
+ + + + + + + + + + + +
+
+ +
+
+{{< /html.inline >}} + + + diff --git a/content/users/create.md b/content/users/create.md index 7be3b79..755dfc0 100644 --- a/content/users/create.md +++ b/content/users/create.md @@ -48,7 +48,7 @@ title: Create Account

- + diff --git a/content/users/new.md b/content/users/new.md new file mode 100644 index 0000000..7be3b79 --- /dev/null +++ b/content/users/new.md @@ -0,0 +1,58 @@ +--- +title: Create Account +--- + +{{< html.inline >}} +
+
+
+
+ + + + + + + + + + + + + + + + +
+
+ +
+
+
+
+{{< /html.inline >}} + + diff --git a/content/users/post b/content/users/post new file mode 100644 index 0000000..e69de29 diff --git a/hugo.toml b/hugo.toml index 5054e0f..41a8050 100644 --- a/hugo.toml +++ b/hugo.toml @@ -30,7 +30,7 @@ enableInlineShortcodes = true themeColor = "blue" # if you set this to 0, only submenu trigger will be visible - showMenuItems = 3 + showMenuItems = 5 # show selector to switch language showLanguageSelector = false @@ -85,15 +85,11 @@ enableInlineShortcodes = true logoHomeLink = "/" [languages.en.menu] - [[languages.en.menu.main]] - identifier = "about" - name = "What is Garbage Speak?" - url = "/about/" - [[languages.en.menu.main]] identifier = "garbage" name = "Latest Garbage" url = "/" + weight = 1 [[languages.en.menu.main]] identifier = "dictionary" @@ -104,6 +100,12 @@ enableInlineShortcodes = true identifier = "faq" name = "FAQ" url = "/faq" + weight = 2 + + [[languages.en.menu.main]] + identifier = "submit" + name = "Submit" + url = "/posts/new" [module] # In case you would like to make changes to the theme and keep it locally in you repository, diff --git a/migrations/000005_add_url_to_garbage.down.sql b/migrations/000005_add_url_to_garbage.down.sql new file mode 100644 index 0000000..e69de29 diff --git a/migrations/000005_add_url_to_garbage.up.sql b/migrations/000005_add_url_to_garbage.up.sql new file mode 100644 index 0000000..b8b3336 --- /dev/null +++ b/migrations/000005_add_url_to_garbage.up.sql @@ -0,0 +1 @@ +ALTER TABLE ONLY public.garbages ADD COLUMN url text; diff --git a/partials/nav/non_user_nav_items.html b/partials/nav/non_user_nav_items.html index 0158fc1..bb2c377 100644 --- a/partials/nav/non_user_nav_items.html +++ b/partials/nav/non_user_nav_items.html @@ -1,2 +1,2 @@ -
  • Become thought leader (Create Account)
  • +
  • Create Account
  • Login
  • diff --git a/partials/posts.html b/partials/posts.html index b5590c3..4e5194f 100644 --- a/partials/posts.html +++ b/partials/posts.html @@ -3,23 +3,23 @@

    {{ .Title }}

    - {{- if .CreatedAt -}} - - {{- end -}} - - {{- with .Metadata.author -}} - + {{- with .Username -}} + Submitter:  {{- end -}} {{ if .Metadata.tags }} {{ range .Metadata.tags }} - {{- . -}}  + {{- . -}}, {{ end }} {{ end }} + + {{- with .CreatedAt -}} + + {{- end -}}
    diff --git a/partials/users/create.html b/partials/users/create.html deleted file mode 100644 index 28d5b97..0000000 --- a/partials/users/create.html +++ /dev/null @@ -1,32 +0,0 @@ - - -
    -
    -

    Sign up

    - -
    - - - - - - - -
    -
    -
    diff --git a/partials/users/login.html b/partials/users/login.html deleted file mode 100644 index 09c002f..0000000 --- a/partials/users/login.html +++ /dev/null @@ -1,11 +0,0 @@ -
    -
    -
    - - - - - -
    -
    -
    diff --git a/server.go b/server.go index ac9843d..a74c3fc 100644 --- a/server.go +++ b/server.go @@ -5,6 +5,7 @@ import ( "context" "crypto/tls" "embed" + "errors" "fmt" "log" "net" @@ -39,10 +40,11 @@ import ( // Garbage represents 'garbage' records from the database type Garbage struct { ID uuid.UUID - OwnerID *uuid.UUID + Username string Title string Content string Metadata map[string]any + Url string CreatedAt time.Time } @@ -169,6 +171,9 @@ func main() { r.Get("/logout", logoutHandler) r.Get("/email_verification/{uev_id}", emailVerification) }) + r.Route("/garbage", func(r chi.Router) { + r.Post("/new", createGarbageHandler) + }) fmt.Printf("Starting API server on port 1314\n") if err := http.ListenAndServe("0.0.0.0:1314", r); err != nil { @@ -365,6 +370,53 @@ func emailVerification(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, baseURL(), http.StatusFound) } +func createGarbageHandler(w http.ResponseWriter, r *http.Request) { + + userID := sessions.GetString(r.Context(), "userID") + if userID == "" { + ise(errors.New("not logged in"), w) + return + } + + if err := r.ParseForm(); err != nil { + ise(err, w) + return + } + + title := r.PostForm.Get("title") + garbage := r.PostForm.Get("garbage") + // TODO this is an arbitrary length that will likely need to change + if len(garbage) == 10 { + w.WriteHeader(400) + return + } + + url := r.PostForm.Get("url") + tags := r.Form["tags"] + metadata := map[string]any{ + "tags": tags, + } + + ctx := context.Background() + db.QueryRow(ctx, + "INSERT INTO garbages(title, content, url, metadata, owner_id) VALUES ($1, $2, $3, $4, $5)", + title, + garbage, + url, + metadata, + userID) + + //var buff = bytes.NewBufferString("") + //tmpl := template.Must(template.ParseFiles("partials/users/created.html")) + //err = tmpl.Execute(buff, map[string]any{"Email": email}) + //if err != nil { + //ise(err, w) + //return + //} + + w.Header().Add("hx-location", baseURL()) +} + // createAccount creates new accounts func createAccount(w http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { @@ -460,7 +512,13 @@ func garbageBin(w http.ResponseWriter, r *http.Request) { ctx := context.Background() posts := []*Garbage{} - err := pgxscan.Select(ctx, db, &posts, `SELECT id,owner_id,title, content, metadata, created_at FROM garbages`) + err := pgxscan.Select( + ctx, + db, + &posts, + `SELECT garbages.id, username, title, content, metadata, url, garbages.created_at + FROM garbages + JOIN users ON garbages.owner_id = users.id`) if err != nil { log.Println("error fetching garbage", err) return diff --git a/themes/terminal/assets/css/form.scss b/themes/terminal/assets/css/form.scss index 5a511de..bc4d539 100644 --- a/themes/terminal/assets/css/form.scss +++ b/themes/terminal/assets/css/form.scss @@ -74,3 +74,12 @@ button[disabled]{ background-color: #cccccc; color: #666666; } + + +textarea:invalid { + border: 2px dashed red; +} + +textarea:valid { + border: 2px solid lime; +} diff --git a/themes/terminal/assets/css/menu.scss b/themes/terminal/assets/css/menu.scss index fdd3075..34eed69 100644 --- a/themes/terminal/assets/css/menu.scss +++ b/themes/terminal/assets/css/menu.scss @@ -51,7 +51,12 @@ white-space: nowrap; &:not(:last-of-type) { - margin-right: 20px; + margin-right: 0.5rem; + } + + &:not(:last-of-type):after { + margin-left: 0.5rem; + content: "|"; } } diff --git a/themes/terminal/layouts/partials/menu.html b/themes/terminal/layouts/partials/menu.html index d7449cb..c8d1d9e 100644 --- a/themes/terminal/layouts/partials/menu.html +++ b/themes/terminal/layouts/partials/menu.html @@ -12,7 +12,6 @@