asset view helper
This commit is contained in:
parent
8198dfa775
commit
68c3f8d3f3
3 changed files with 10 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
|||
package layouts
|
||||
|
||||
import "github.com/anthdm/kit/view"
|
||||
|
||||
var (
|
||||
title = "GOTHKIT project"
|
||||
)
|
||||
|
@ -12,7 +14,7 @@ templ BaseLayout() {
|
|||
<link rel="icon" type="image/x-icon" href="/public/favicon.ico"/>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<link rel="stylesheet" href="/public/assets/styles.css"/>
|
||||
<link rel="stylesheet" href={ view.Asset("styles.css") }/>
|
||||
<!-- Jquery -->
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
|
||||
<!-- Alpine Plugins -->
|
||||
|
|
|
@ -50,12 +50,8 @@ func (kit *Kit) Auth() Auth {
|
|||
return value
|
||||
}
|
||||
|
||||
// Redirect with HTMX support.
|
||||
func (kit *Kit) Redirect(status int, url string) error {
|
||||
http.Redirect(kit.Response, kit.Request, url, status)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (kit *Kit) HXRedirect(status int, url string) error {
|
||||
if len(kit.Request.Header.Get("HX-Request")) > 0 {
|
||||
kit.Response.Header().Set("HX-Redirect", url)
|
||||
kit.Response.WriteHeader(http.StatusSeeOther)
|
||||
|
|
|
@ -2,12 +2,18 @@ package view
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/anthdm/gothkit/kit"
|
||||
"github.com/anthdm/gothkit/kit/middleware"
|
||||
)
|
||||
|
||||
func Asset(name string) templ.SafeURL {
|
||||
return templ.URL(fmt.Sprintf("/public/assets/%s", name))
|
||||
}
|
||||
|
||||
// Auth is a view helper function that returns the current Auth.
|
||||
// If Auth is not set a default auth will be returned
|
||||
func Auth(ctx context.Context) kit.Auth {
|
||||
|
|
Loading…
Reference in a new issue