-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jmoiron/standard-mode
overhaul towards newer more standard packages
- Loading branch information
Showing
95 changed files
with
6,455 additions
and
1,492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
export CGO_CFLAGS := -g -O2 -Wno-return-local-addr | ||
# -Wno-stringop-overflow | ||
|
||
build: | ||
CGO_FLAGS=$CGO_FLAGS go build --tags="fts5" | ||
|
||
reload: | ||
./monet --load-posts backup/posts.json | ||
./monet --load-stream backup/stream.json | ||
./monet --load-pages backup/pages.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="/static/fonts.css"> | ||
{{if .debug}} | ||
<link rel="stylesheet/less" href="/static/style.less"> | ||
<script src="/static/js/less.js"></script> | ||
{{else}} | ||
<link rel="stylesheet" href="/static/style.css"> | ||
{{end}} | ||
<script src="/static/js/cash.min.js"></script> | ||
<script src="/static/js/admin.js"></script> | ||
<script src="/static/js/split-grid.min.js"></script> | ||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/split.js/1.6.0/split.min.js"></script> --> | ||
<title>{{.title}}</title> | ||
</head> | ||
<body> | ||
<div class="content"> | ||
<div class="container admin {{.extraContainerClass}}"> | ||
{{.body}} | ||
</div> | ||
</div> | ||
<div class="footer"> | ||
<div class="container"> | ||
<div class="user-controls"> | ||
<a href="/admin/users/">users <i class="icon icon-user"></i></a> | ||
</div> | ||
<div class="admin-controls"> | ||
<a href="/admin/">home <i class="icon icon-home"></i></a> or | ||
<a href="/logout/">logout <i class="icon icon-signout"></i></a> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="panels"> | ||
{{range $i, $panel := .panels}} | ||
<div class="{{if eq (mod $i 2) (0)}}left{{else}}right{{end}}-panel panel"> | ||
{{$panel|safe}} | ||
</div> | ||
{{if ne (mod $i 2) (0)}}<div class="clear panel-sep"></div>{{end}} | ||
{{end}} | ||
</div> | ||
<div class="clear"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package admin | ||
|
||
import ( | ||
"embed" | ||
"log/slog" | ||
"net/http" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/jmoiron/monet/app" | ||
"github.com/jmoiron/monet/auth" | ||
"github.com/jmoiron/monet/db" | ||
"github.com/jmoiron/monet/mtr" | ||
) | ||
|
||
// the admin app attaches all of the admins to itself | ||
// it relies on the auth app, but apps register their admin | ||
// capabilities without importing this app, so it should be ok | ||
|
||
type App struct { | ||
db db.DB | ||
sm *auth.SessionManager | ||
|
||
BaseURL string | ||
Apps []app.App | ||
Admins []app.Admin | ||
} | ||
|
||
//go:embed admin/* | ||
var templates embed.FS | ||
|
||
func NewApp(db db.DB, sm *auth.SessionManager) *App { | ||
return &App{db: db, sm: sm} | ||
} | ||
|
||
func (a *App) WithBaseURL(url string) *App { | ||
a.BaseURL = url | ||
return a | ||
} | ||
|
||
func (a *App) Name() string { return "stream" } | ||
|
||
func (a *App) Register(reg *mtr.Registry) { | ||
reg.AddBaseFS("admin-base", "admin/base.html", templates) | ||
reg.AddPathFS("admin/index.html", templates) | ||
} | ||
|
||
func (a *App) Migrate() error { return nil } | ||
|
||
func (a *App) Collect(apps ...app.App) { | ||
a.Apps = apps | ||
for _, app := range apps { | ||
ad, err := app.GetAdmin() | ||
if err != nil { | ||
slog.Error("error for adminapp", "app", app.Name(), "err", err) | ||
continue | ||
} | ||
if ad == nil { | ||
slog.Debug("no admin for app", "app", app.Name()) | ||
continue | ||
} | ||
a.Admins = append(a.Admins, ad) | ||
} | ||
} | ||
|
||
// GetAdmin is yo dawg? | ||
func (a *App) GetAdmin() (app.Admin, error) { | ||
return nil, nil | ||
} | ||
|
||
func (a *App) Bind(r chi.Router) { | ||
// presumably we are bound to something like `/admin/` | ||
r.Route(a.BaseURL, func(r chi.Router) { | ||
r.Use(a.sm.RequireAuthenticatedRedirect("/admin/")) | ||
for _, ad := range a.Admins { | ||
ad.Bind(r) | ||
} | ||
|
||
r.Get("/", a.index) | ||
}) | ||
} | ||
|
||
func (a *App) index(w http.ResponseWriter, r *http.Request) { | ||
var panels []string | ||
for _, ad := range a.Admins { | ||
ps, err := ad.Panels(r) | ||
if err != nil { | ||
slog.Error("rendering panel", "err", err) | ||
continue | ||
} | ||
panels = append(panels, ps...) | ||
} | ||
|
||
reg := mtr.RegistryFromContext(r.Context()) | ||
|
||
err := reg.RenderWithBase(w, "admin-base", "admin/index.html", mtr.Ctx{ | ||
"panels": panels, | ||
}) | ||
|
||
if err != nil { | ||
slog.Error("rendering template", "err", err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.