Go!
This commit is contained in:
parent
2076202e3b
commit
4fb28d9c26
44 changed files with 54 additions and 1145 deletions
|
@ -6,7 +6,7 @@ tmp_dir = "tmp"
|
|||
args_bin = ["-ip", "127.0.0.1", "-port", "3000"]
|
||||
bin = "./tmp/main"
|
||||
pre_cmd = []
|
||||
cmd = "go build -o ./tmp/main . & cd lib/stylegen && ./gen.sh -e html -d ../../pages/templates -o ../../public/css"
|
||||
cmd = "cd lib/stylegen && ./gen.sh -e html -d ../../pages/templates -o ../../public/css && cd ../.. && go build -o ./tmp/main ."
|
||||
delay = 1000
|
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "lib/stylegen"]
|
||||
exclude_file = []
|
||||
|
@ -15,7 +15,7 @@ tmp_dir = "tmp"
|
|||
follow_symlink = false
|
||||
full_bin = ""
|
||||
include_dir = []
|
||||
include_ext = ["go", "tpl", "tmpl", "html", "css"]
|
||||
include_ext = ["go", "tpl", "tmpl", "html"]
|
||||
include_file = []
|
||||
kill_delay = "0s"
|
||||
log = "build-errors.log"
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
**/atri.dad
|
||||
**/pollo
|
||||
**/.env
|
||||
**/airbin
|
||||
**/tmp
|
||||
**/*.rdb
|
||||
stylegen
|
||||
fly.toml
|
||||
tailwind.config.*.js
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
|||
atri.dad
|
||||
pollo
|
||||
main
|
||||
.env
|
||||
airbin
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# atri.dad
|
||||
This is my personal website!
|
||||
# Pollo
|
||||
|
||||
## Stack:
|
||||
- Backend: Golang + Echo
|
||||
|
@ -20,5 +19,5 @@ This is my personal website!
|
|||
_Note that on MacOS, you need to right click and open the appropriate tailwind executable before you can run StyleGen. This is a limitation of running unsigned binaries in MacOS. Blame Tim Apple._
|
||||
|
||||
## Tests
|
||||
Without Coverage: `go test atri.dad/lib`
|
||||
With Coverage: `go test atri.dad/lib -cover`
|
||||
Without Coverage: `go test pollo/lib`
|
||||
With Coverage: `go test pollo/lib -cover`
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/clerkinc/clerk-sdk-go/clerk"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func Authed(c echo.Context) error {
|
||||
apiKey := os.Getenv("CLERK_SECRET_KEY")
|
||||
|
||||
client, err := clerk.NewClient(apiKey)
|
||||
if err != nil {
|
||||
// handle error
|
||||
println(err.Error())
|
||||
}
|
||||
|
||||
// get session token from Authorization header
|
||||
sessionToken := c.Request().Header.Get("Authorization")
|
||||
sessionToken = strings.TrimPrefix(sessionToken, "Bearer ")
|
||||
|
||||
println(sessionToken)
|
||||
|
||||
// verify the session
|
||||
sessClaims, err := client.VerifyToken(sessionToken)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return c.String(http.StatusUnauthorized, "Unauthorized!")
|
||||
}
|
||||
|
||||
// get the user, and say welcome!
|
||||
user, err := client.Users().Read(sessClaims.Claims.Subject)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return c.String(http.StatusOK, "Welcome "+*user.FirstName)
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func PostCopy(c echo.Context) error {
|
||||
return c.String(http.StatusOK, `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`)
|
||||
}
|
54
api/rss.go
54
api/rss.go
|
@ -1,54 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
contentfs "atri.dad/content"
|
||||
"atri.dad/lib"
|
||||
"github.com/gorilla/feeds"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func RSSFeedHandler(c echo.Context) error {
|
||||
files, err := fs.ReadDir(contentfs.FS, ".")
|
||||
|
||||
protocol := "http"
|
||||
if c.Request().TLS != nil {
|
||||
protocol = "https"
|
||||
}
|
||||
|
||||
feed := &feeds.Feed{
|
||||
Title: "Atridad Lahiji's Blog",
|
||||
Link: &feeds.Link{Href: protocol + "://" + c.Request().Host + "/api/rss"},
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if !file.IsDir() && strings.HasSuffix(file.Name(), ".md") {
|
||||
|
||||
frontMatter, err := lib.ExtractFrontMatter(file, contentfs.FS)
|
||||
if err != nil {
|
||||
http.Error(c.Response().Writer, "There was an issue rendering the posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
date, _ := time.Parse("January 2 2006", frontMatter.Date)
|
||||
|
||||
feed.Add(&feeds.Item{
|
||||
Title: frontMatter.Name,
|
||||
Link: &feeds.Link{Href: protocol + "://" + c.Request().Host + "/post/" + strings.TrimSuffix(file.Name(), ".md")},
|
||||
Created: date,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
rss, _ := feed.ToRss()
|
||||
return c.Blob(http.StatusOK, "application/rss+xml", []byte(rss))
|
||||
}
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
"pollo/lib"
|
||||
)
|
||||
|
||||
func SSE(c echo.Context) error {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type PayRequest struct {
|
||||
SuccessUrl string `json:"successUrl"`
|
||||
CancelUrl string `json:"cancelUrl"`
|
||||
PriceId string `json:"priceId"`
|
||||
}
|
||||
|
||||
func Pay(c echo.Context) error {
|
||||
payReq := new(PayRequest)
|
||||
|
||||
if err := c.Bind(payReq); err != nil {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
lib.CreateCheckoutSession(c.Response().Writer, c.Request(), payReq.SuccessUrl, payReq.CancelUrl, payReq.PriceId)
|
||||
|
||||
return c.String(http.StatusOK, "Checkout session created")
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func ResizeHandler(c echo.Context) error {
|
||||
|
||||
// Extract file from request
|
||||
file, _, err := c.Request().FormFile("image")
|
||||
if err != nil {
|
||||
return c.String(http.StatusBadRequest, "Error getting image file")
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Get dimensions from form data parameters
|
||||
widthStr := c.FormValue("width")
|
||||
heightStr := c.FormValue("height")
|
||||
|
||||
// Validate and convert dimensions to integers
|
||||
width, err := strconv.Atoi(widthStr)
|
||||
if err != nil {
|
||||
return c.String(http.StatusBadRequest, "Invalid width parameter")
|
||||
}
|
||||
|
||||
height, err := strconv.Atoi(heightStr)
|
||||
if err != nil {
|
||||
return c.String(http.StatusBadRequest, "Invalid height parameter")
|
||||
}
|
||||
|
||||
fileBlob, err := lib.ResizeImg(file, width, height)
|
||||
|
||||
if err != nil {
|
||||
return c.String(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
c.Response().Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "resized.png"))
|
||||
|
||||
return c.Blob(http.StatusOK, "image/png", fileBlob)
|
||||
}
|
|
@ -3,8 +3,8 @@ package api
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
"pollo/lib"
|
||||
)
|
||||
|
||||
func SSEDemoSend(c echo.Context) error {
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
svix "github.com/svix/svix-webhooks/go"
|
||||
"pollo/lib"
|
||||
)
|
||||
|
||||
// Types
|
||||
|
@ -28,11 +28,11 @@ type ClerkEvent struct {
|
|||
// Event Handlers
|
||||
func userCreatedHandler(event ClerkEvent) {
|
||||
welcomeEmail := `
|
||||
<h1>Thank you for making an atri.dad account!</h1>
|
||||
<h1>Thank you for making an pollo account!</h1>
|
||||
<h2>There are a number of apps this account give you access to!</h2>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Pollo: https://pollo.atri.dad/</li>
|
||||
<li>Pollo: https://pollo.pollo/</li>
|
||||
</ul>
|
||||
`
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
---
|
||||
name: "Thoughts on Cognitive Load and Programming Language Syntax"
|
||||
date: "February 07 2024"
|
||||
tags: ["thoughts"]
|
||||
---
|
||||
Recently, I started to pick up a new language in my spare time: Go. Was it partially influenced by the surge in HTMX popularity and how often Go is used alongside it? Almost certainly. But at some point along this journey, I noticed something: This is _so_ much more fun and _so_ much less draining. This whole post won't be me gushing about how much I love Go as a language, not directly. I started to notice a few things...
|
||||
|
||||
# Oh, what fun...
|
||||
I come from the JavaScript and TypeScript world with frameworks like Remix and Next.js. And the DX (Developer Experience) for these is lovely! For reasons I could not quite pin down, I was having much more fun with Go + HTMX despite the hacks to get close to the same DX. It came down to how darn easily I could pull off things I had previously relied on services for. Need a message queue to run on the edge? Easy, write a wrapper over Redis to use its PubSub. Need real-time updates to the UI? No problem, write a basic Server-Sent Events system with subscriptions and channels. Anything I wanted, I could build. That, and the way concurrency _"just works"_, and I could make anything I wanted happen. This brings a level of satisfaction that is hard to convey in an article.
|
||||
|
||||
# What changed?
|
||||
So this isn't meant to be a post to bash JavaScript, as much as I do have my reservations about the language. That being said, JS makes basic things like concurrency an afterthought. Go's lightweight threads, called goroutines, make it easy to write concurrent programs without worrying about the overhead of heavyweight threads. Even better, Go has channels that provide a simple and effective way of synchronizing communication between goroutines, making it easier to write concurrent programs free from race conditions. Similar concepts are present in Java, Rust (Tokio), C#, etc. Even better, error handling! Now, this is controversial, but forcing errors to be valued and allowing functions to assert that there _may_ be errors is a game changer for writing safer code. All of this amounts to a much lower cognitive load. I am less worried that my code is inefficient, error-prone, etc. I can just _write_.
|
||||
|
||||
# What does this mean?
|
||||
As a field, we can and should investigate and identify key points in programming languages that increase or decrease the mental load or overhead for developers. Imagine if we could identify these points and work to reduce the overhead. This has been on my mind as I reflect on my experience learning Go. I want to dive deeper into the details of what we can do to reduce this overhead and get back to writing good software without unnecessary restrictions.
|
||||
|
||||
# Thanks!
|
||||
Do you have any thoughts on this? Do you want to have a chat about the topic? Feel free to reach out by email at [me@atri.dad](mailto:me@atri.dad). Until next time! 🫡
|
|
@ -1,6 +0,0 @@
|
|||
package contentfs
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed *
|
||||
var FS embed.FS
|
|
@ -1,15 +0,0 @@
|
|||
---
|
||||
name: "Editor Setup 2024"
|
||||
date: "April 24 2024"
|
||||
tags: ["thoughts", "dev"]
|
||||
---
|
||||
Another quick one folks! I have made huge changes to my setup lately, and wanted to document it here for those who may be looking for something simpler. I like _simple_ software. VSCode and even Zed do _not_ check that box. Zed is riddled with collaboration features I don't need and VSCode is famously cluttered and loves to horde as much RAM as possible. What happened to simple code editors? Nothing!
|
||||
|
||||
# It's Sublime Time!
|
||||
Sublime Text is a gem among the chaotic landscape of editors fighting for space in your HDD/SSD. It is just plain **fast**! I cannot stress enough by how much too! Opening large projects takes no time at all, and scrolling is so incredibly smooth. It doesn't stop there, as the packages are incredible. For instance, the LSP package is so darn fast. I don't seem to have the same crashing issues I had with VSCode in a large TypeScript codebase either!
|
||||
|
||||
# Don't you Git it?!
|
||||
The developers also made an equally performant and clean Git client called Sublime Merge, and its the same story! It is fast, feature rich, and has a clean UI! I've played around with tools like Github Desktop and Kraken, and I keep coming back to Sublime Merge for its simplicity. My favourite feature: every Git action you take in the UI has a corresponding Git command the app _shows you in the UI_. This is huge for learning Git commands, and just for transparency for what the app is doing. And the icing on top? It integrates with Sublime Text.
|
||||
|
||||
# Give it a shot!
|
||||
I whole heartedly recommend giving them a try! The links can be found [here](https://www.sublimetext.com/) and [here](https://www.sublimemerge.com/). Did you try it? Do you enjoy it? Feel free to reach out by email at [me@atri.dad](mailto:me@atri.dad). Until next time! 🫡
|
|
@ -1,78 +0,0 @@
|
|||
---
|
||||
name: "Introducing the GOTH Stack"
|
||||
date: "January 08 2024"
|
||||
tags: ["article","golang"]
|
||||
---
|
||||
# Enter the GOTH Stack!
|
||||
The GOTH stack is something I've been trying to get to for a while now. It's not a specific repository with a fancy command that can scaffold a project for you. It's more like a set of pillars for building excellent, pleasant, full-stack web applications.
|
||||
|
||||
# The first pillar: Go
|
||||
Go is something I learned to love later on in my career. I was mainly writing JavaScript, building on serverless platforms and growing frustrated at the performance and limitations. Go changed all of that.
|
||||
|
||||
What makes Go good?:
|
||||
- Static types
|
||||
- Incredibly easy concurrency
|
||||
- Errors as values
|
||||
- Incredible runtime and build time performance
|
||||
- Tiny memory footprint
|
||||
|
||||
The tl;dr is that it is challenging to write Go code that is _not_ performant.
|
||||
|
||||
# The second pillar: Templates... well... Go templates
|
||||
Go templates surprised me, to be completely honest. They offer just enough to get me going and perform exceptionally well. Sure, it's not as simple as a basic JSX file in Next.js since you need to make a route handler, but it works pretty well and supports basic control flow. I am interested in looking into alternatives such as TEMPL (which reads much like JSX for Go), but I need to find a real reason to move from the standard library here.
|
||||
|
||||
Here is an example of a route handler passing a slice over to a template for rendering:
|
||||
```go
|
||||
package pages
|
||||
|
||||
import (
|
||||
"HTML/template"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"goth.stack/lib"
|
||||
)
|
||||
|
||||
type HomeProps struct {
|
||||
Socials []lib.IconLink
|
||||
Tech []lib.IconLink
|
||||
ContractLink string
|
||||
ResumeURL string
|
||||
SupportLink string
|
||||
}
|
||||
|
||||
func Home(c echo.Context) error {
|
||||
socials := []lib.IconLink{
|
||||
{
|
||||
Name: "Email",
|
||||
Href: "mailto:example@site.com",
|
||||
Icon: template.HTML(`<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z"/></svg>`),
|
||||
},
|
||||
}
|
||||
|
||||
props := HomeProps{
|
||||
Socials: socials,
|
||||
Tech: tech,
|
||||
ContractLink: "mailto:example@site.com",
|
||||
ResumeURL: "https://srv.goth.stack/Atridad_Lahiji_Resume.pdf",
|
||||
SupportLink: "https://donate.stripe.com/8wMeVF25c78L0V2288",
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
||||
```
|
||||
As you can see, it really isn't that bad! It also comes with many of the benefits of Go and the flexibility of components!
|
||||
|
||||
# The third pillar: HTMX
|
||||
So, up to this point, you may have been thinking: "Gee Atri... you can't do anything reactive here". Before HTMX, you would have been right. HTMX offers a more backend-centric developer a way to build complex reactivity to their front end through basic templating languages. It is one file you import in your template, and it enables anything from basic HTML swapping to WebSocket and Server-Sent Event support. It is really, really powerful and worth looking at all together.
|
||||
|
||||
With Go managing route handlers and API routes, the template language running the UI, and HTMX governing interactivity on the front end, you can effectively write a fully dynamic full-stack application without writing a line of JavaScript code. It even runs quite a bit faster than some of the JS world's frameworks (Astro, for instance). It is actually what powers this site right now! The fundamentals are essential here and come together for a clean and enjoyable developer experience. I encourage everyone in the JS world to give it a shot! Perhaps it is not your thing, and that's okay! But you might also just fall in love with it!
|
||||
|
||||
# Giving It A Shot
|
||||
I have a [repository](https://github.com/atridadl/goth.stack) as well as a [demo](https://goth-stack.fly.dev/) ready to go with everything you need to start!
|
||||
|
||||
# Thanks!
|
||||
If you found this helpful, please let me know by email at [me@atri.dad](mailto:me@atri.dad). Until next time!
|
|
@ -1,28 +0,0 @@
|
|||
---
|
||||
name: "Build Scalable Real-time Applications on Fly.io + Remix!"
|
||||
date: "December 04 2023"
|
||||
tags: ["remix.js", "fly.io", "article"]
|
||||
---
|
||||
|
||||
# Scalability... what is it?
|
||||
|
||||
You often think of vertical scaling for something to scale, adding more resources to whatever issue you encounter (CPU, RAM, etc.). While this is the simplest way to scale an application or service, it can only get you so far. Horizontal scaling involves adding more machines or "nodes" running the same application. These nodes sit behind a load balancer responsible for directing client traffic to the appropriate machine to optimize load. This will work well if the application is meant to do simple CRUD operations for individual users. What if you need collaboration in real time? This complicates things...
|
||||
|
||||
# The real-time problem:
|
||||
|
||||
Real-time applications require a pub/sub or publish and subscribe model. A client will send a request to the application to perform an operation. Once done, the server will broadcast an event to all subscribing clients to trigger a re-fetch of data. In the case of a multi-node application, you need to use a service outside of your nodes to synchronize messages across all nodes.
|
||||
|
||||
# The stack:
|
||||
|
||||
For this stack, I chose Remix for its close adherence to web standards and easy support for server-sent events. These web socket connections work one way: from server to client. Next, we must synchronize all Server Sent events across different requests to a single node. For this, Node.js has its own Event Emitter API, which we can use. Now, we can use something like Redis and its Pub/Sub commands for multi-node setups to broadcast across nodes.
|
||||
|
||||
This is what it would look like:
|
||||

|
||||
|
||||
# How does it work?
|
||||
|
||||
Once a client connects to a page with real-time enabled, a persistent connection via EventStreams is made. The client would request to make a real-time update. Once the endpoint completes the request, it triggers a Node.js event, which the EventStreams endpoint listens to. Once received, the application sends an event down to the client via a server-sent event while also passing that request on to Redis pub/sub. Every node listens to this Redis event stream, so every node will receive the event and trigger the event using Node.js events, which then start server-sent events.
|
||||
|
||||
As you can see, there are many moving parts here, and it can get quite complicated. I have a repo called Atash, which acts as a template to get started. You can check it out [here](https://atash.atri.dad)!
|
||||
|
||||
If you found this helpful, please let me know by email at [me@atri.dad](mailto:me@atri.dad). Until next time!
|
|
@ -1,18 +0,0 @@
|
|||
---
|
||||
name: "Thoughts on AI"
|
||||
date: "April 09 2024"
|
||||
tags: ["thoughts", "ai"]
|
||||
---
|
||||
I'm a bit late to the party, but AI has definitely taken off lately. Every product we use now seems to have some sort of AI integration or feature baked in to capture some of the hype. How do I feel about it? Well… thats complicated...
|
||||
|
||||
# Memes
|
||||
If you dig around my GitHub you'll surely stuble upon Himbot, my Discord bot project. This is where I used to enjoy AI. For memes. I had two commands: "ask" and "pic" which generated text and images respectively. Now, I didn't write some complex algorithm for this. It used Replicate to access open source models. As it turns out, this made the bot quite fun. Have an unhinged discord conversation that needs image replies? All you had to do was throw some no-context nonsense into "/pic" and see what happens! It was amazing! This honeymoon period didn't last long...
|
||||
|
||||
# Capitalism
|
||||
Capitalism ruins all things. Including AI. Now what could be a useful and fun technology is rammed into every product ever at the _expense_ of its users just to check a box for shareholders. Notion? It has AI now. Snapchat? Yup… an AI assistant there too. Want to use windows? I hope you aren't planning to ignore Microsoft's new OS level AI Copilot! There is no escape it seems. Even DuckDuckGo and Brave Browser are using it now (although given Brave still clings to the trash that is Web3 I am less surprised there). My point is, there is definitely going to be AI fatigue, if there is not already. Capitalism won't let us forget about this though, since it seems to line the pockets of the ultra-rich anyways. Want to make a game but don't want to pay an artist? Just pay for some compute and generate images with **prompt engineering**! How did that model get the data to learn to do this? No need to worry your little heads over that detail if its making you money! All of this and more is enabled by this technology and encouraged by our economic systems.
|
||||
|
||||
# What can we do?
|
||||
What can we do about this? Is there a hope for us trying to escape AI? Honestly, I am not sure. But I am definitely trying. I have removed copilot from my Windows install, and I refuse to use anything that forces me to use AI. Being concious about how you use AI is key. With so many of these models trained on the work of skilled creatives, it is _our_ responsibility as consumers of this technology to ensure that we are _always_ paying professionals for their work, and not using their skills for free via a heartless algorithm. Lastly, be causious of products that add AI for seemingly no reason. There is a good chance your data is being used to train it.
|
||||
|
||||
# Thanks!
|
||||
Do you have any thoughts on AI? Do you use it? If so, how? Feel free to reach out by email at [me@atri.dad](mailto:me@atri.dad). Until next time! 🫡
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module atri.dad
|
||||
module pollo
|
||||
|
||||
go 1.22.0
|
||||
|
||||
|
|
|
@ -108,6 +108,10 @@ echo "module.exports = {
|
|||
}" > tailwind.config.js
|
||||
|
||||
# Run the binary with the generated config
|
||||
#print out the output directory
|
||||
echo "Output Directory: $OUTPUT_DIR"
|
||||
#print out the current directory
|
||||
echo "Current Directory: $PWD"
|
||||
$BINARY build -i ./base.css -c tailwind.config.js -o "${OUTPUT_DIR}/styles.css" --minify
|
||||
|
||||
# Wait for all background processes to finish
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
templatefs "atri.dad/pages/templates"
|
||||
templatefs "pollo/pages/templates"
|
||||
)
|
||||
|
||||
func RenderTemplate(w http.ResponseWriter, layout string, partials []string, props interface{}) error {
|
||||
|
|
26
main.go
26
main.go
|
@ -6,10 +6,10 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"atri.dad/api"
|
||||
"atri.dad/api/webhooks"
|
||||
"atri.dad/lib"
|
||||
"atri.dad/pages"
|
||||
"pollo/api"
|
||||
"pollo/api/webhooks"
|
||||
"pollo/lib"
|
||||
"pollo/pages"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -43,33 +43,15 @@ func main() {
|
|||
|
||||
// Page routes
|
||||
e.GET("/", pages.Home)
|
||||
e.GET("/projects", pages.Projects)
|
||||
e.GET("/talks", pages.Talks)
|
||||
e.GET("/testimonials", pages.Testimonials)
|
||||
e.GET("/blog", pages.Blog)
|
||||
e.GET("/post/:post", pages.Post)
|
||||
e.GET("/tools", pages.Tools)
|
||||
e.GET("/tools/resize", pages.Resize)
|
||||
e.GET("/tools/ssedemo", pages.SSEDemo)
|
||||
|
||||
// API Routes:
|
||||
apiGroup := e.Group("/api")
|
||||
apiGroup.GET("/ping", api.Ping)
|
||||
apiGroup.GET("/authed/ping", api.Authed)
|
||||
apiGroup.POST("/pay", api.Pay)
|
||||
apiGroup.GET("/rss", api.RSSFeedHandler)
|
||||
apiGroup.GET("/post/copy", api.PostCopy)
|
||||
|
||||
apiGroup.GET("/sse", func(c echo.Context) error {
|
||||
return api.SSE(c)
|
||||
})
|
||||
|
||||
apiGroup.POST("/tools/sendsse", func(c echo.Context) error {
|
||||
return api.SSEDemoSend(c)
|
||||
})
|
||||
|
||||
apiGroup.POST("/tools/resize", api.ResizeHandler)
|
||||
|
||||
// Webhook Routes:
|
||||
webhookGroup := e.Group("/webhook")
|
||||
webhookGroup.POST("/clerk", webhooks.ClerkWebhookHandler)
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
contentfs "atri.dad/content"
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type BlogProps struct {
|
||||
Posts []lib.CardLink
|
||||
}
|
||||
|
||||
func Blog(c echo.Context) error {
|
||||
var posts []lib.CardLink
|
||||
|
||||
files, err := fs.ReadDir(contentfs.FS, ".")
|
||||
if err != nil {
|
||||
lib.LogError.Println(err)
|
||||
http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if !file.IsDir() && strings.HasSuffix(file.Name(), ".md") {
|
||||
frontMatter, err := lib.ExtractFrontMatter(file, contentfs.FS)
|
||||
if err != nil {
|
||||
lib.LogError.Println(err)
|
||||
http.Error(c.Response().Writer, "There was an issue rendering the posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
frontMatter.Href = "post/" + strings.TrimSuffix(file.Name(), ".md")
|
||||
frontMatter.Internal = true
|
||||
|
||||
posts = append(posts, frontMatter)
|
||||
}
|
||||
}
|
||||
|
||||
const layout = "January 2 2006"
|
||||
|
||||
sort.Slice(posts, func(i, j int) bool {
|
||||
iDate, err := time.Parse(layout, posts[i].Date)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
jDate, err := time.Parse(layout, posts[j].Date)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return iDate.Before(jDate)
|
||||
})
|
||||
|
||||
props := BlogProps{
|
||||
Posts: posts,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems", "cardlinks"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
"pollo/lib"
|
||||
)
|
||||
|
||||
type ExampleProps struct {
|
||||
|
|
119
pages/home.go
119
pages/home.go
File diff suppressed because one or more lines are too long
|
@ -1,78 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
|
||||
contentfs "atri.dad/content"
|
||||
"atri.dad/lib"
|
||||
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/yuin/goldmark"
|
||||
highlighting "github.com/yuin/goldmark-highlighting/v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type PostProps struct {
|
||||
Content template.HTML
|
||||
Name string
|
||||
Date string
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func Post(c echo.Context) error {
|
||||
postName := c.Param("post")
|
||||
|
||||
filePath := postName + ".md"
|
||||
|
||||
md, err := fs.ReadFile(contentfs.FS, filePath)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
http.Error(c.Response().Writer, "This post does not exist!", http.StatusNotFound)
|
||||
return nil
|
||||
}
|
||||
|
||||
frontmatterBytes, content, err := lib.SplitFrontmatter(md)
|
||||
if err != nil {
|
||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
var frontmatter lib.FrontMatter
|
||||
if err := yaml.Unmarshal(frontmatterBytes, &frontmatter); err != nil {
|
||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
markdown := goldmark.New(
|
||||
goldmark.WithExtensions(
|
||||
highlighting.NewHighlighting(
|
||||
highlighting.WithStyle("fruity"),
|
||||
highlighting.WithFormatOptions(
|
||||
chromahtml.WithLineNumbers(true),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
if err := markdown.Convert(content, &buf); err != nil {
|
||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
props := PostProps{
|
||||
Content: template.HTML(buf.String()),
|
||||
Name: frontmatter.Name,
|
||||
Date: frontmatter.Date,
|
||||
Tags: frontmatter.Tags,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "post", partials, props)
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type ProjectProps struct {
|
||||
Projects []lib.CardLink
|
||||
}
|
||||
|
||||
func Projects(c echo.Context) error {
|
||||
projects := []lib.CardLink{
|
||||
{
|
||||
Name: "Pollo",
|
||||
Description: "A dead-simple real-time voting tool.",
|
||||
Tags: []string{"react", "remix.js", "product"},
|
||||
Href: "https://pollo.atri.dad",
|
||||
},
|
||||
{
|
||||
Name: "GOTH Stack",
|
||||
Description: "🚀 A Web Application Template Powered by HTMX + Go + Tailwind 🚀",
|
||||
Tags: []string{"golang", "htmx", "template"},
|
||||
Href: "https://github.com/atridadl/goth.stack",
|
||||
},
|
||||
{
|
||||
Name: "Himbot",
|
||||
Description: "A discord bot written in Go. Loosly named after my username online (HimbothySwaggins).",
|
||||
Tags: []string{"golang", "bot"},
|
||||
Href: "https://github.com/atridadl/HimBot",
|
||||
},
|
||||
{
|
||||
Name: "loadr",
|
||||
Description: "A lightweight REST load testing tool with robust support for different verbs, token auth, and performance reports.",
|
||||
Tags: []string{"golang", "cli"},
|
||||
Href: "https://github.com/atridadl/loadr",
|
||||
},
|
||||
}
|
||||
|
||||
props := ProjectProps{
|
||||
Projects: projects,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems", "cardlinks"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type TalkProps struct {
|
||||
Talks []lib.CardLink
|
||||
}
|
||||
|
||||
func Talks(c echo.Context) error {
|
||||
talks := []lib.CardLink{
|
||||
{
|
||||
Name: "How to ship less JavaScript",
|
||||
Description: "A talk on building websites while being mindful of the JavaScript we ship. Presented at the Dev Edmonton July 2023 JS/Ruby/Python Meetup",
|
||||
Href: "https://github.com/atridadl/devedmonton-july-2023",
|
||||
Tags: []string{"astro", "ssr"},
|
||||
Date: "July 06, 2023",
|
||||
},
|
||||
{
|
||||
Name: "Hypermedia as the engine of application state - an Introduction",
|
||||
Description: "A talk on building reactive websites using tools like HTMX instead of JSON + JS. Will be presented at the Dev Edmonton Fabruary 2024 JS/Ruby/Python Meetup",
|
||||
Href: lib.GeneratePublicURL("hypermedia_talk_atridad.pdf"),
|
||||
Tags: []string{"golang", "htmx", "ssr"},
|
||||
Date: "February 01, 2024",
|
||||
},
|
||||
}
|
||||
|
||||
props := TalkProps{
|
||||
Talks: talks,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems", "cardlinks"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Blog
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Blog
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<section class="flex flex-row flex-wrap gap-2 justify-center align-middle">
|
||||
{{range .Posts}}
|
||||
{{template "cardlinks" .}}
|
||||
{{end}}
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
|
@ -1,9 +1,9 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Root
|
||||
Pollo // Root
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Root
|
||||
Pollo // Root
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
|
@ -11,38 +11,30 @@ Atridad Lahiji // Root
|
|||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<h1 class="text-4xl font-extrabold text-white sm:text-8xl">
|
||||
Hi, I'm <span
|
||||
class="text-transparent bg-clip-text bg-gradient-to-r from-pink-500 via-purple-500 to-blue-500">Atridad</span>
|
||||
</h1>
|
||||
<div class="flex flex-col text-center items-center justify-center px-4 py-16 gap-4">
|
||||
<h1 class="text-3xl sm:text-6xl font-bold">
|
||||
<span class="bg-gradient-to-r from-primary via-accent to-secondary bg-clip-text text-transparent box-decoration-clone">
|
||||
Pollo
|
||||
</span>
|
||||
</h1>
|
||||
|
||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
||||
I'm a full stack developer who builds cool things for the web.
|
||||
</h2>
|
||||
<h2 class="my-4 text-xl sm:text-3xl font-bold">
|
||||
A <span class="text-primary">dead-simple </span>
|
||||
<span class="text-secondary">real-time </span>
|
||||
<span class="text-accent">voting tool</span>.
|
||||
</h2>
|
||||
|
||||
<span>
|
||||
<h2 class="mb-2 text-xl text-white sm:text-[1.5rem]">Places I exist:</h2>
|
||||
<div class="flex flex-row flex-wrap items-center justify-center gap-4 text-center">
|
||||
{{range .Socials}}
|
||||
{{template "iconlinks" .}}
|
||||
{{end}}
|
||||
<div class="card glass card-compact bg-secondary text-black font-bold text-left">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">Features:</h2>
|
||||
<ul>
|
||||
<li>🚀 Real-time voting!</li>
|
||||
<li>🚀 Customizable room name and vote scale!</li>
|
||||
<li>🚀 CSV Reports for every room!</li>
|
||||
<li>🚀 100% free and open-source... forever!</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<h2 class="mb-2 text-xl text-white sm:text-[1.5rem]">Stuff I Use:</h2>
|
||||
|
||||
<div class="flex flex-row flex-wrap items-center justify-center gap-4 text-center">
|
||||
{{range .Tech}}
|
||||
{{template "iconlinks" .}}
|
||||
{{end}}
|
||||
</div>
|
||||
</span>
|
||||
|
||||
<div class="flex flex-row flex-wrap gap-2 mx-auto justify-center">
|
||||
{{range .ButtonsLinks}}
|
||||
{{template "buttonlinks" .}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
{{define "header"}}
|
||||
<header class="navbar bg-base-100">
|
||||
<div class="navbar-start">
|
||||
<a class="btn btn-ghost normal-case text-lg sm:text-xl text-white" href="/">{{template "headercontent".}}</a>
|
||||
</div>
|
||||
<div class="navbar-end z-50">
|
||||
<div class="dropdown dropdown-end">
|
||||
<label tabindex="0" class="btn btn-sm btn-ghost text-white">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-menu"><line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="18" y2="18"/></svg>
|
||||
</label>
|
||||
<ul
|
||||
tabindex="0"
|
||||
class="menu menu-compact dropdown-content gap-2 mt-3 p-2 shadow bg-base-100 rounded-box"
|
||||
>
|
||||
{{template "navitems" .}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="navbar-start">
|
||||
<a class="btn btn-ghost normal-case text-lg sm:text-xl text-white" href="/">{{template "headercontent".}}</a>
|
||||
</div>
|
||||
</header>
|
||||
{{end}}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
{{define "navitems"}}
|
||||
<li>
|
||||
<a class="no-underline" href="/">
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="no-underline" href="/projects">
|
||||
Projects
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="no-underline" href="/talks">
|
||||
Talks
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="no-underline" href="/testimonials">
|
||||
Testimonials
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="no-underline" href="/tools">
|
||||
Tools
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="no-underline" href="/blog">
|
||||
Blog
|
||||
</a>
|
||||
</li>
|
||||
{{end}}
|
|
@ -1,20 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Post
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Post
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
{{.Content}}
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
<script src="/public/js/htmx.base.js"></script>
|
||||
<script src="/public/js/hyperscript.js"></script>
|
||||
{{end}}
|
|
@ -1,22 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Projects
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Projects
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<section class="flex flex-row flex-wrap gap-2 justify-center align-middle">
|
||||
{{range .Projects}}
|
||||
{{template "cardlinks" .}}
|
||||
{{end}}
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
|
@ -1,22 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Talks
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Talks
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<section class="flex flex-row flex-wrap gap-2 justify-center align-middle">
|
||||
{{range .Talks}}
|
||||
{{template "cardlinks" .}}
|
||||
{{end}}
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
|
@ -1,32 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Testimonials
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Testimonials
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">
|
||||
What <a class="link link-secondary"
|
||||
href="https://steamcommunity.com/app/1230140/reviews/?browsefilter=toprated&snr=1_5_100010_" target="_blank"
|
||||
rel="noreferrer">People</a> Say About Me
|
||||
</h2>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
|
||||
{{range .Images}}
|
||||
<div>
|
||||
<img class="object-cover object-center w-full max-w-full rounded-lg" src={{.}} alt="Review of Atri"
|
||||
loading="lazy" />
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
|
@ -1,22 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Tools
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Tools
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<section class="flex flex-row flex-wrap gap-2 justify-center align-middle">
|
||||
{{range .Tools}}
|
||||
{{template "cardlinks" .}}
|
||||
{{end}}
|
||||
</section>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
|
@ -1,31 +0,0 @@
|
|||
{{define "title"}}
|
||||
Atridad Lahiji // Tools // Resizer
|
||||
{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Tools // Resizer
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">Image Resizer</h2>
|
||||
<form action="/api/tools/resize" method="post" enctype="multipart/form-data" class="flex-col flex gap-4">
|
||||
Select image to resize:
|
||||
<input type="file" name="image" accept=".png,.jpg,.jpeg"
|
||||
class="file-input file-input-bordered file-input-secondary w-full max-w-xs" required />
|
||||
<br>
|
||||
New width (px):
|
||||
<input type="number" id="newWidth" name="width" min="1" class="input input-bordered w-full max-w-xs" required>
|
||||
<br>
|
||||
New height (px):
|
||||
<input type="number" id="newHeight" name="height" min="1" class="input input-bordered w-full max-w-xs" required>
|
||||
<br>
|
||||
<button type="submit" class="btn btn-secondary">Resize Image</button>
|
||||
</form>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
{{end}}
|
|
@ -1,36 +0,0 @@
|
|||
{{define "title"}}Atridad Lahiji // Tools // SSE Demo{{end}}
|
||||
|
||||
{{define "headercontent"}}
|
||||
Atridad Lahiji // Tools // SSE Demo
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<h2 class="text-2xl font-extrabold tracking-tight text-white sm:text-[2rem]">Server Sent Events Demo</h2>
|
||||
|
||||
<p class="text-lg">This page demonstrates the use of the <a href="https://htmx.org/extensions/sse/">HTMX SSE
|
||||
Extention</a> to receive Server Sent Events on the "default" channel.</p>
|
||||
<p class="text-lg">Any events received on the "default" channel will appear below:</p>
|
||||
<div hx-ext="sse" sse-connect="/api/sse" sse-swap="message">
|
||||
Waiting for SSE Message...
|
||||
</div>
|
||||
|
||||
<p class="text-lg">Here you can send messages on the default channel:</p>
|
||||
<form hx-post="/api/tools/sendsse" hx-trigger="submit" hx-swap="none" class="flex-col flex gap-2">
|
||||
<div class="label">
|
||||
<span class="label-text">Message</span>
|
||||
</div>
|
||||
<input type="text" name="message" value="Hello world!" placeholder="Enter your message here"
|
||||
class="input input-bordered input-primary w-full max-w-xs" />
|
||||
|
||||
<button type="submit" class="btn btn-primary">Send Event</button>
|
||||
</form>
|
||||
{{end}}
|
||||
|
||||
{{define "foot"}}
|
||||
<script src="/public/js/htmx.base.js"></script>
|
||||
<script src="/public/js/htmx.sse.js"></script>
|
||||
{{end}}
|
|
@ -1,34 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type TestimonialsProps struct {
|
||||
Images []string
|
||||
}
|
||||
|
||||
func Testimonials(c echo.Context) error {
|
||||
images := []string{
|
||||
"/public/img/testimonials/1.png",
|
||||
"/public/img/testimonials/2.png",
|
||||
"/public/img/testimonials/3.png",
|
||||
"/public/img/testimonials/4.png",
|
||||
"/public/img/testimonials/5.png",
|
||||
"/public/img/testimonials/6.png",
|
||||
"/public/img/testimonials/7.png",
|
||||
"/public/img/testimonials/8.png",
|
||||
"/public/img/testimonials/9.png",
|
||||
}
|
||||
|
||||
props := TestimonialsProps{
|
||||
Images: images,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type ToolsProps struct {
|
||||
Tools []lib.CardLink
|
||||
}
|
||||
|
||||
func Tools(c echo.Context) error {
|
||||
tools := []lib.CardLink{
|
||||
{
|
||||
Name: "Server Sent Events Demo",
|
||||
Description: "Server Sent Events Demo",
|
||||
Href: "/tools/ssedemo",
|
||||
Internal: true,
|
||||
},
|
||||
{
|
||||
Name: "Image Resizer",
|
||||
Description: "Image Resizer Tool",
|
||||
Href: "/tools/resize",
|
||||
Internal: true,
|
||||
},
|
||||
}
|
||||
|
||||
props := ToolsProps{
|
||||
Tools: tools,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems", "cardlinks"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type ResizeProps struct {
|
||||
Talks []lib.CardLink
|
||||
}
|
||||
|
||||
func Resize(c echo.Context) error {
|
||||
talks := []lib.CardLink{
|
||||
{
|
||||
Name: "How to ship less JavaScript",
|
||||
Description: "A talk on building websites while being mindful of the JavaScript we ship. Presented at the Dev Edmonton July 2023 JS/Ruby/Python Meetup",
|
||||
Href: "https://github.com/atridadl/devedmonton-july-2023",
|
||||
Tags: []string{"astro", "ssr"},
|
||||
Date: "July 06, 2023",
|
||||
},
|
||||
{
|
||||
Name: "Hypermedia as the engine of application state - an Introduction",
|
||||
Description: "A talk on building reactive websites using tools like HTMX instead of JSON + JS. Will be presented at the Dev Edmonton Fabruary 2024 JS/Ruby/Python Meetup",
|
||||
Href: lib.GeneratePublicURL("hypermedia_talk_atridad.pdf"),
|
||||
Tags: []string{"golang", "htmx", "ssr"},
|
||||
Date: "February 01, 2024",
|
||||
},
|
||||
}
|
||||
|
||||
props := TalkProps{
|
||||
Talks: talks,
|
||||
}
|
||||
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems", "cardlinks"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"atri.dad/lib"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func SSEDemo(c echo.Context) error {
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, nil)
|
||||
}
|
2
public/css/styles.css
vendored
2
public/css/styles.css
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue