Skip to content

Commit

Permalink
Merge pull request #25 from blackfyre/postcards
Browse files Browse the repository at this point in the history
Postcards
  • Loading branch information
blackfyre authored Oct 18, 2023
2 parents 3746bcd + c543114 commit d54e668
Show file tree
Hide file tree
Showing 38 changed files with 1,880 additions and 276 deletions.
71 changes: 40 additions & 31 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,51 @@ testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 500
exclude_dir = ["tmp", "vendor", "testdata", "resources", "dist", ".idea", ".github"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "css", "js"]
include_file = []
kill_delay = "10s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 600
exclude_dir = [
"tmp",
"vendor",
"testdata",
"resources",
"dist",
".idea",
".github",
"wga_data",
]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "css", "js"]
include_file = []
kill_delay = "10s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false
main_only = false
time = false

[misc]
clean_on_exit = false
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
clear_on_rebuild = false
keep_scroll = true
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ WGA_S3_ACCESS_KEY=
WGA_S3_ACCESS_SECRET=

WGA_PROTOCOL=https
WGA_HOSTNAME=wga.hu

WGA_SMTP_HOST=
WGA_SMTP_PORT=
WGA_SMTP_USERNAME=
WGA_SMTP_PASSWORD=
WGA_SENDER_ADDRESS=
WGA_SENDER_NAME=

WGA_RECAPTCHA_SITE_KEY=
WGA_RECAPTCHA_SECRET_KEY=
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
working-directory: ./resources/sitebuild
run: |
npm ci
npm run build-copy
npm run build
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ dist/
tmp/

assets/public/css/style.css
*/mjml/*.html

assets/public/js/*.js
assets/public/js/*.map
assets/public/js/*.txt
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"mjmlio.vscode-mjml",
"sibiraj-s.vscode-scss-formatter",
"esbenp.prettier-vscode",
"alexcvzz.vscode-sqlite",
"mrmlnc.vscode-scss"
]
}
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,38 @@ WGA_S3_ACCESS_KEY=
WGA_S3_ACCESS_SECRET=

WGA_PROTOCOL=http
WGA_HOSTNAME=localhost:8090

WGA_SMTP_HOST=
WGA_SMTP_PORT=
WGA_SMTP_USERNAME=
WGA_SMTP_PASSWORD=
WGA_SENDER_ADDRESS=
WGA_SENDER_NAME=

WGA_RECAPTCHA_SITE_KEY=
WGA_RECAPTCHA_SECRET_KEY=
```

| Variable | Description |
| ---------------------- | ---------------------------------------------------------------------------- |
| `WGA_ADMIN_EMAIL` | The email address of the admin user |
| `WGA_ADMIN_PASSWORD` | The password of the admin user |
| `WGA_S3_ENDPOINT` | The endpoint of the S3 bucket |
| `WGA_S3_BUCKET` | The name of the S3 bucket |
| `WGA_S3_REGION` | The region of the S3 bucket |
| `WGA_S3_ACCESS_KEY` | The access key of the S3 bucket |
| `WGA_S3_ACCESS_SECRET` | The access secret of the S3 bucket |
| `WGA_PROTOCOL` | The protocol to use for the application, valid values are `http` and `https` |
| `WGA_SMTP_HOST` | The address of the SMTP host |
| `WGA_SMTP_PORT` | The SMTP service port on the host adress |
| `WGA_SMTP_USERNAME` | The username for the SMTP service |
| `WGA_SMTP_PASSWORD` | The password for the SMTP service |
| `WGA_SENDER_ADDRESS` | The sending email address |
| `WGA_SENDER_NAME` | The name of the email sender |
| Variable | Description |
| -------------------------- | ---------------------------------------------------------------------------- |
| `WGA_ADMIN_EMAIL` | The email address of the admin user |
| `WGA_ADMIN_PASSWORD` | The password of the admin user |
| `WGA_S3_ENDPOINT` | The endpoint of the S3 bucket |
| `WGA_S3_BUCKET` | The name of the S3 bucket |
| `WGA_S3_REGION` | The region of the S3 bucket |
| `WGA_S3_ACCESS_KEY` | The access key of the S3 bucket |
| `WGA_S3_ACCESS_SECRET` | The access secret of the S3 bucket |
| `WGA_PROTOCOL` | The protocol to use for the application, valid values are `http` and `https` |
| `WGA_HOSTNAME` | The domain pointing to the application |
| `WGA_SMTP_HOST` | The address of the SMTP host |
| `WGA_SMTP_PORT` | The SMTP service port on the host adress |
| `WGA_SMTP_USERNAME` | The username for the SMTP service |
| `WGA_SMTP_PASSWORD` | The password for the SMTP service |
| `WGA_SENDER_ADDRESS` | The sending email address |
| `WGA_SENDER_NAME` | The name of the email sender |
| `WGA_RECAPTCHA_SITE_KEY` | The site key for the recaptcha service |
| `WGA_RECAPTCHA_SECRET_KEY` | The secret key for the recaptcha service |

### Running the application

Expand Down
76 changes: 76 additions & 0 deletions assets/internals.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,84 @@
package assets

import (
"bytes"
"embed"
"html/template"
"log"

"blackfyre.ninja/wga/utils"
"github.com/pocketbase/pocketbase/apis"
)

//go:embed "reference/*" "views/*"
var InternalFiles embed.FS

// renderPage renders the given template with the provided data and returns the resulting HTML string.
// The template is parsed from the views directory using the provided template name and the layout.html file.
// If the template cannot be parsed or there is an error rendering it, an error is returned.
func RenderPage(t string, data map[string]any) (string, error) {

patterns := []string{
"views/layout.html",
"views/partials/*.html",
}

patterns = append(patterns, "views/pages/"+t+".html")

return renderHtml(patterns, "layout", data)
}

// renderBlock renders a given block of HTML using the provided data and returns the resulting HTML string.
// The function searches for HTML templates in the "views/pages" and "views/partials" directories of the InternalFiles filesystem.
// It uses the utils.TemplateFuncs map to provide additional functions to the templates.
// If an error occurs while parsing or rendering the template, the function returns an empty string and the error.
func RenderBlock(block string, data map[string]any) (string, error) {

patterns := []string{
"views/pages/*.html",
"views/partials/*.html",
}

return renderHtml(patterns, block, data)
}

// RenderEmail renders an email template with the given data.
// The function takes a string `t` representing the template name and a map `data` containing the data to be rendered.
// It returns a string representing the rendered email and an error if any occurred.
func RenderEmail(t string, data map[string]any) (string, error) {

patterns := []string{
"views/emails/*.html",
}

return renderHtml(patterns, t, data)
}

// renderHtml renders an HTML template using the provided patterns, name and data.
// It returns the rendered HTML as a string and an error if any occurred.
func renderHtml(patterns []string, name string, data map[string]any) (string, error) {

ts, err := template.New("").Funcs(utils.TemplateFuncs).ParseFS(
InternalFiles,
patterns...,
)

if err != nil {
log.Println("Error parsing template")
log.Println(err)
return "", err
}

html := new(bytes.Buffer)

err = ts.ExecuteTemplate(html, name, data)

if err != nil {
// or redirect to a dedicated 404 HTML page
log.Println("Error rendering template")
log.Println(err)
return "", apis.NewNotFoundError("", err)
}

return html.String(), nil
}
File renamed without changes.
120 changes: 0 additions & 120 deletions assets/public/js/site.js

This file was deleted.

File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d54e668

Please sign in to comment.