Compare commits
No commits in common. "main" and "fcf497b1a12e80a982d5fc093184524413f20cb3" have entirely different histories.
main
...
fcf497b1a1
5
Makefile
5
Makefile
@ -1,5 +0,0 @@
|
|||||||
FLAGS := -s -skipbindings
|
|
||||||
TAGS := -tags webkit2_40
|
|
||||||
|
|
||||||
default:
|
|
||||||
wails dev $(FLAGS) $(TAGS)
|
|
@ -2,12 +2,8 @@
|
|||||||
|
|
||||||
> **Extremely WIP GUI Prototype ™**
|
> **Extremely WIP GUI Prototype ™**
|
||||||
|
|
||||||
## Bikemap
|
|
||||||
|
|
||||||
See [`#1`](https://git.vvvvvvaria.org/Toolsheds/snackbar/issues/1) 🤓
|
|
||||||
|
|
||||||
## Hacking
|
## Hacking
|
||||||
|
|
||||||
* Install [`wails`](https://wails.io), [`templ`](https://templ.guide)
|
* Install [`wails`](https://wails.io), [`templ`](https://templ.guide) & [`npm`](https://www.npmjs.com)
|
||||||
* Run `wails doctor` to check your system can run everything
|
* Run `wails doctor` to check your system can run everything
|
||||||
* Run `make`, hack & auto-reload the GUI on [localhost:34115](http://localhost:34115)
|
* Run `wails dev -browser` to start up the development server
|
||||||
|
39
app.go
39
app.go
@ -8,12 +8,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
|
||||||
|
|
||||||
"varia.zone/snackbar/components"
|
"varia.zone/snackbar/components"
|
||||||
|
|
||||||
@ -34,27 +32,6 @@ func NewApp() *App {
|
|||||||
return &App{}
|
return &App{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) startup(ctx context.Context) {
|
|
||||||
sites, err := existingSites()
|
|
||||||
if err != nil {
|
|
||||||
// TODO(d1): is this the correct approach for error handling?
|
|
||||||
panic(fmt.Sprintf("unable to read sites from %s", SitesDir))
|
|
||||||
}
|
|
||||||
|
|
||||||
randPort := rand.Intn(1400-1300) + 1300
|
|
||||||
for _, siteName := range sites {
|
|
||||||
cmd := exec.Command(HugoBinPath, "serve", "--port", fmt.Sprintf("%v", randPort), "--buildDrafts", "--source", filepath.Join(SitesDir, siteName), "--theme", "nostyleplease")
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
// TODO(d1): is this the correct approach for error handling?
|
|
||||||
panic(fmt.Sprintf("unable to serve site: %s", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) shutdown(ctx context.Context) {
|
|
||||||
fmt.Print("SHUTTING DOWN!")
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureDataDir() error {
|
func ensureDataDir() error {
|
||||||
paths := []string{LocalDir, HomeDir, HugoDir, SitesDir}
|
paths := []string{LocalDir, HomeDir, HugoDir, SitesDir}
|
||||||
for _, fpath := range paths {
|
for _, fpath := range paths {
|
||||||
@ -170,21 +147,6 @@ func hugoNewSite(w http.ResponseWriter, r *http.Request) {
|
|||||||
templ.Handler(components.Homepage(sites)).ServeHTTP(w, r)
|
templ.Handler(components.Homepage(sites)).ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func siteConfig(w http.ResponseWriter, r *http.Request) {
|
|
||||||
siteName := chi.URLParam(r, "site-name")
|
|
||||||
|
|
||||||
sites, err := existingSites()
|
|
||||||
if err != nil {
|
|
||||||
w.Write([]byte(fmt.Sprintf("unable to list existing sites: %s", err)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !slices.Contains(sites, siteName) {
|
|
||||||
w.Write([]byte(fmt.Sprintf("site '%s' does not exist?", siteName)))
|
|
||||||
}
|
|
||||||
|
|
||||||
templ.Handler(components.SiteConfig(siteName)).ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRouter creates a new web router.
|
// NewRouter creates a new web router.
|
||||||
func NewRouter() *chi.Mux {
|
func NewRouter() *chi.Mux {
|
||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
@ -194,7 +156,6 @@ func NewRouter() *chi.Mux {
|
|||||||
|
|
||||||
router.Get("/init", initialise)
|
router.Get("/init", initialise)
|
||||||
router.Post("/hugo/new", hugoNewSite)
|
router.Post("/hugo/new", hugoNewSite)
|
||||||
router.Get("/{site-name}/config", siteConfig)
|
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,3 @@ templ Homepage(sites []string) {
|
|||||||
<p id="new-site-loader" class="htmx-indicator">Creating new site...</p>
|
<p id="new-site-loader" class="htmx-indicator">Creating new site...</p>
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
|
|
||||||
templ SiteConfig(site string) {
|
|
||||||
<p>Welcome to WIP config for { site }</p>
|
|
||||||
}
|
|
||||||
|
@ -75,40 +75,3 @@ func Homepage(sites []string) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SiteConfig(site string) templ.Component {
|
|
||||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
|
||||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
|
||||||
if !templ_7745c5c3_IsBuffer {
|
|
||||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
|
||||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
||||||
}
|
|
||||||
ctx = templ.InitializeContext(ctx)
|
|
||||||
templ_7745c5c3_Var4 := templ.GetChildren(ctx)
|
|
||||||
if templ_7745c5c3_Var4 == nil {
|
|
||||||
templ_7745c5c3_Var4 = templ.NopComponent
|
|
||||||
}
|
|
||||||
ctx = templ.ClearChildren(ctx)
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p>Welcome to WIP config for ")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
var templ_7745c5c3_Var5 string
|
|
||||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(site)
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/templates.templ`, Line: 25, Col: 37}
|
|
||||||
}
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
if !templ_7745c5c3_IsBuffer {
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
|
||||||
}
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
13
frontend/package.json
Normal file
13
frontend/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"vite": "^3.0.7"
|
||||||
|
}
|
||||||
|
}
|
1
frontend/package.json.md5
Executable file
1
frontend/package.json.md5
Executable file
@ -0,0 +1 @@
|
|||||||
|
12a10e92fe971e5bd12d427dfbcf9918
|
0
frontend/src/assets/images/.git-keep-me
Normal file
0
frontend/src/assets/images/.git-keep-me
Normal file
4
main.go
4
main.go
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed all:frontend components
|
//go:embed all:frontend/dist components
|
||||||
var assets embed.FS
|
var assets embed.FS
|
||||||
|
|
||||||
//go:embed build/appicon.png
|
//go:embed build/appicon.png
|
||||||
@ -33,8 +33,6 @@ func main() {
|
|||||||
return router
|
return router
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
OnStartup: app.startup,
|
|
||||||
OnShutdown: app.shutdown,
|
|
||||||
Bind: []interface{}{
|
Bind: []interface{}{
|
||||||
app,
|
app,
|
||||||
},
|
},
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
"$schema": "https://wails.io/schemas/config.v2.json",
|
"$schema": "https://wails.io/schemas/config.v2.json",
|
||||||
"name": "snackbar",
|
"name": "snackbar",
|
||||||
"outputfilename": "snackbar",
|
"outputfilename": "snackbar",
|
||||||
"wailsjsdir": "./frontend",
|
"frontend:install": "npm install",
|
||||||
|
"frontend:build": "npm run build",
|
||||||
|
"frontend:dev:watcher": "npm run dev",
|
||||||
|
"frontend:dev:serverUrl": "auto",
|
||||||
"preBuildHooks": {
|
"preBuildHooks": {
|
||||||
"*/*": "templ generate"
|
"*/*": "templ generate"
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user