update assets use

This commit is contained in:
2024-12-11 17:37:58 +08:00
parent f6c961adb6
commit af08d9befc
25 changed files with 177 additions and 218 deletions

View File

@@ -1,12 +1,10 @@
package base
import (
"github.com/zhang2092/go-url-shortener/internal/templ/css"
"github.com/zhang2092/go-url-shortener/internal/templ/funcs"
"github.com/zhang2092/go-url-shortener/internal/templ/js"
)
import "github.com/zhang2092/go-url-shortener/internal/templ/util"
templ Base(page string) {
templ Base(assets ...string) {
{{ csses := util.GetCssFile(assets...) }}
{{ jss := util.GetJsFile(assets...) }}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
@@ -15,9 +13,8 @@ templ Base(page string) {
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="/assets/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/assets/css/index.css"/>
switch page {
case "home":
@css.HomeCSS()
for _, cs := range csses {
<link rel="stylesheet" href={ cs }/>
}
<title>URL段地址服务</title>
</head>
@@ -28,7 +25,7 @@ templ Base(page string) {
URL段地址服务
</a>
<ul class="flex oauth">
{{ auth := funcs.GetAuthorize(ctx) }}
{{ auth := util.GetAuthorize(ctx) }}
if auth != nil {
<li style="font-size: 12px;">
欢迎您: { auth.Name }
@@ -50,9 +47,8 @@ templ Base(page string) {
{ children... }
<script src="/assets/js/jquery.min.js"></script>
<script src="/assets/js/bootstrap.bundle.min.js"></script>
switch page {
case "home":
@js.HomeJS()
for _, js := range jss {
<script src={ js }></script>
}
</body>
</html>

View File

@@ -8,13 +8,9 @@ package base
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
import (
"github.com/zhang2092/go-url-shortener/internal/templ/css"
"github.com/zhang2092/go-url-shortener/internal/templ/funcs"
"github.com/zhang2092/go-url-shortener/internal/templ/js"
)
import "github.com/zhang2092/go-url-shortener/internal/templ/util"
func Base(page string) templ.Component {
func Base(assets ...string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -35,13 +31,27 @@ func Base(page string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
csses := util.GetCssFile(assets...)
jss := util.GetJsFile(assets...)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"zh-CN\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"><link rel=\"shortcut icon\" href=\"/assets/favicon.ico\" type=\"image/x-icon\"><link rel=\"stylesheet\" href=\"/assets/css/bootstrap.min.css\"><link rel=\"stylesheet\" href=\"/assets/css/index.css\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
switch page {
case "home":
templ_7745c5c3_Err = css.HomeCSS().Render(ctx, templ_7745c5c3_Buffer)
for _, cs := range csses {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<link rel=\"stylesheet\" href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(cs)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templ/base/base.templ`, Line: 17, Col: 36}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -50,18 +60,18 @@ func Base(page string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
auth := funcs.GetAuthorize(ctx)
auth := util.GetAuthorize(ctx)
if auth != nil {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li style=\"font-size: 12px;\">欢迎您: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(auth.Name)
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(auth.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templ/base/base.templ`, Line: 34, Col: 30}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templ/base/base.templ`, Line: 31, Col: 30}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -87,9 +97,21 @@ func Base(page string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
switch page {
case "home":
templ_7745c5c3_Err = js.HomeJS().Render(ctx, templ_7745c5c3_Buffer)
for _, js := range jss {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script src=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(js)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templ/base/base.templ`, Line: 51, Col: 20}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}