From 0df3d16dda4ce16cd5eb37da334eb4aeb6c8d181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20M=C3=A5rdbrink?= Date: Wed, 12 Feb 2025 00:09:21 +0100 Subject: [PATCH] First release --- .air.toml | 4 ++-- .dockerignore | 5 ++++ .gitignore | 2 +- Dockerfile | 22 +++++++++++++++++ README.md | 4 ++++ css/index.css | 43 +++++++++++++++++---------------- database/data.db | Bin 16384 -> 0 bytes database/database.go | 44 ---------------------------------- database/seed.sql | 7 ------ internal/handlers/handlers.go | 3 +-- cmd/main.go => main.go | 8 ++----- resources/button-arrow.svg | 3 +++ views/articles.html | 6 ++--- views/common.html | 2 +- views/projects.html | 16 +++++-------- 15 files changed, 71 insertions(+), 98 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.md delete mode 100644 database/data.db delete mode 100644 database/database.go delete mode 100644 database/seed.sql rename cmd/main.go => main.go (80%) create mode 100644 resources/button-arrow.svg diff --git a/.air.toml b/.air.toml index 19e78f3..3ea51b9 100644 --- a/.air.toml +++ b/.air.toml @@ -5,7 +5,7 @@ tmp_dir = "tmp" [build] args_bin = [] bin = "./tmp/main" - cmd = "go build -o ./tmp/main cmd/main.go" + cmd = "go build -o ./tmp/main main.go" delay = 0 exclude_dir = ["node_modules", "assets", "tmp", "vendor", "testdata"] exclude_file = [] @@ -13,7 +13,7 @@ tmp_dir = "tmp" exclude_unchanged = false follow_symlink = false full_bin = "" - include_dir = ["cmd", "internal", "views", "pkg"] + include_dir = ["internal", "views", "pkg"] include_ext = ["go", "html"] include_file = [] kill_delay = "0s" diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d48d7d5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# flyctl launch added from .gitignore +tmp +views/**/*.go + +fly.toml diff --git a/.gitignore b/.gitignore index d85e7b8..fc7869e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /tmp/ /views/**/*.go - +fly.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..55e0c48 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.22.3-alpine AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main . + +# Runtime image +FROM alpine:latest + +WORKDIR /app + +COPY --from=builder /app/main . +COPY views views/ +COPY css css/ +COPY resources resources/ + +CMD ["./main"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..b833ead --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +## Run locally +``` +air +``` diff --git a/css/index.css b/css/index.css index 4a8715a..67e2e59 100644 --- a/css/index.css +++ b/css/index.css @@ -55,6 +55,14 @@ html, body { z-index: 100000; } +.page { + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; + height: 100%; +} + .main-container { display: flex; flex-direction: column; @@ -62,25 +70,18 @@ html, body { align-items: center; height: 100%; gap: 2rem; -} - -.home-padding { - margin-top: 5rem; - - @media screen and (max-width: 1000px) { - margin-top: 2rem; - } + margin-top: -2rem; } .title-container { - margin-top: 2rem; display: flex; flex-direction: column; justify-content: center; align-items: center; + gap: 1rem; @media screen and (max-width: 1000px) { - margin-bottom: -3rem; + gap: 0.5rem; } } @@ -94,8 +95,15 @@ html, body { } } +.title-offset { + margin-top: 2rem; + + @media screen and (max-width: 1000px) { + margin-top: 1rem; + } +} + .menu-container { - margin-top: 3rem; display: flex; flex-direction: row; justify-content: center; @@ -104,7 +112,7 @@ html, body { width: 100%; @media screen and (max-width: 1000px) { - margin-top: 7.5rem; + margin-top: 1.5rem; gap: 1.5rem; flex-direction: column; } @@ -142,11 +150,10 @@ html, body { flex-direction: column; justify-content: center; align-items: center; - height: 100%; - gap: 2.5rem; + gap: 5rem; @media screen and (max-width: 1000px) { - gap: 0.75rem; + gap: 3rem; } } @@ -175,7 +182,6 @@ html, body { width: 22.5rem; border: 0.4rem solid var(--dark-text); box-shadow: 0.5rem 0.5rem 0 0.1rem var(--dark-text); - margin-top: 5rem; @media screen and (max-width: 1000px) { display: none; @@ -245,7 +251,6 @@ html, body { width: 28rem; border: 0.4rem solid var(--dark-text); box-shadow: 0.5rem 0.5rem 0 0.1rem var(--dark-text); - margin-top: 5rem; @media screen and (max-width: 1000px) { width: 18rem; @@ -320,8 +325,6 @@ html, body { content: ""; } } - - } .project-info-link-right:hover, .project-info-link-left:hover { @@ -340,7 +343,6 @@ html, body { width: 22.5rem; border: 0.4rem solid var(--dark-text); box-shadow: 0.5rem 0.5rem 0 0.1rem var(--dark-text); - margin-top: 5rem; @media screen and (max-width: 1000px) { display: none; @@ -452,7 +454,6 @@ html, body { width: 22.5rem; border: 0.4rem solid var(--dark-text); box-shadow: 0.5rem 0.5rem 0 0.1rem var(--dark-text); - margin-top: 5rem; @media screen and (max-width: 1000px) { display: none; diff --git a/database/data.db b/database/data.db deleted file mode 100644 index 9af47c3f4b330f9034c670f9581b15288ab179b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCV6qZm1S)51sj@JRFavTlUfX;nNW;{i9*dS$}cT}n4=I7 zkI5_46t-QcF^c^r5{VU1LW`KTpBfC%-5)S0S^Y zxHMNGB|j&>NTE2hL?JOZwL}Nhi!4q}E=esZEmBBK$t=h$PR`6rS4hptEYVX4PEAqB zNlh*(Emp`+$;{VLC`rvN$S+bzEmg?PR4B_VNlevING>fZE-hBb&Cf|KF3C()$N|}= zr{GtblarXMP?lJfSz4@+m{*bt)?HexP*Pe{kXfvdmRgjXnpaYqtD{hynxc@Kn3Gyu znwXNPkXoUTnv)8V)6>&)&d)0W^&j)o6rf&HFg7wUGSxLO(lszuFfz0>42NAv7-9(tE>QoUe-8uyEB?#;dxmNrA9eR=2#kin zXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-R~z-w+UEHe|#c(_+RdY{VqWY{-eB+7LAV x&mb^-!)VlJqaiRF0;3@?8UmvsFd71*Aut*OqaiRF0;3@?8UmvsFd7033;<3$oudE% diff --git a/database/database.go b/database/database.go deleted file mode 100644 index 404e145..0000000 --- a/database/database.go +++ /dev/null @@ -1,44 +0,0 @@ -package database - -import ( - "database/sql" - "log" - "os" - - _ "github.com/mattn/go-sqlite3" - - "hugo.mardbrink.se/internal/config" -) - -func InitDB() *sql.DB { - db, err := sql.Open("sqlite3", config.DatabaseFile) - if err != nil { - log.Fatal(err) - } - - if err := initSchema(db); err != nil { - log.Fatal(err) - } - - return db -} - -func initSchema(db *sql.DB) error { - content, err := os.ReadFile(config.SeedFile) - if err != nil { - return err - } - - _, err = db.Exec(string(content)) - if err != nil { - return err - } - - return nil -} - -func CloseDB(db *sql.DB) { - db.Close() -} - - diff --git a/database/seed.sql b/database/seed.sql deleted file mode 100644 index e958beb..0000000 --- a/database/seed.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE IF NOT EXISTS articles ( - route TEXT PRIMARY KEY, - title TEXT, - description TEXT, - content TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 7e73102..971b0b6 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -1,7 +1,6 @@ package handlers import ( - "database/sql" "net/http" "github.com/labstack/echo/v4" @@ -9,7 +8,7 @@ import ( "hugo.mardbrink.se/internal/models" ) -func RegisterRoutes(e *echo.Echo, db *sql.DB) { +func RegisterRoutes(e *echo.Echo,) { e.GET("/", homePageHandler()) e.GET("/projects", projectsPageHandler()) e.GET("/articles", articlesPageHandler()) diff --git a/cmd/main.go b/main.go similarity index 80% rename from cmd/main.go rename to main.go index 7879cac..fcf7b0d 100644 --- a/cmd/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" - "hugo.mardbrink.se/database" "hugo.mardbrink.se/internal/handlers" ) @@ -34,10 +33,7 @@ func main() { e.Static("/resources", "resources") e.Static("/css", "css") - db := database.InitDB() - defer database.CloseDB(db) + handlers.RegisterRoutes(e) - handlers.RegisterRoutes(e, db) - - e.Logger.Fatal(e.Start(":8080")) + e.Logger.Fatal(e.Start("0.0.0.0:8080")) } diff --git a/resources/button-arrow.svg b/resources/button-arrow.svg new file mode 100644 index 0000000..437edbe --- /dev/null +++ b/resources/button-arrow.svg @@ -0,0 +1,3 @@ + + + diff --git a/views/articles.html b/views/articles.html index 764ee75..3b83f8a 100644 --- a/views/articles.html +++ b/views/articles.html @@ -12,10 +12,8 @@ {{ block "articles.content" . }} -
-
- ARTICLES -
+
+ ARTICLES
{{ end }} diff --git a/views/common.html b/views/common.html index 0d45761..e0078e4 100644 --- a/views/common.html +++ b/views/common.html @@ -27,7 +27,7 @@ Grainy background {{ template "breadcrumb" . }} -
+
{{ end }} {{ block "base.end" . }} diff --git a/views/projects.html b/views/projects.html index 0e6cff1..3e1432f 100644 --- a/views/projects.html +++ b/views/projects.html @@ -12,16 +12,12 @@ {{ block "projects.content" . }} -
-
-
- PROJECTS -
- {{ template "projects.skal" . }} - {{ template "projects.dct" . }} - {{ template "projects.modmark" . }} -
-
+
+ PROJECTS + {{ template "projects.skal" . }} + {{ template "projects.dct" . }} + {{ template "projects.modmark" . }} +
{{ end }}