Skip to content

Commit fd3fccd

Browse files
committed
import custom css and js as files
1 parent e19d9fd commit fd3fccd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

conf/config.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package conf
22

33
import (
4-
stdtpl "html/template"
54
"net/http"
6-
"strings"
75

86
"github.com/zrcoder/amisgo/internal/conf"
97
"github.com/zrcoder/amisgo/internal/template"
@@ -31,8 +29,8 @@ type (
3129
type Config struct {
3230
Title string
3331
Icon string
34-
CustomCSS stdtpl.CSS
35-
CustomJS stdtpl.JS
32+
CustomCSS []string
33+
CustomJS []string
3634
LocalSdkFS http.FileSystem
3735
*template.Templ
3836
}
@@ -108,14 +106,14 @@ func WithIcon(icon string) Option {
108106
// WithCustomCSS sets the custom CSS URL.
109107
func WithCustomCSS(customCSS ...string) Option {
110108
return func(c *Config) {
111-
c.CustomCSS = stdtpl.CSS(strings.Join(customCSS, "\n"))
109+
c.CustomCSS = customCSS
112110
}
113111
}
114112

115113
// WithCustomJS sets the custom JavaScript URL.
116114
func WithCustomJS(customJS ...string) Option {
117115
return func(c *Config) {
118-
c.CustomJS = stdtpl.JS(strings.Join(customJS, "\n"))
116+
c.CustomJS = customJS
119117
}
120118
}
121119

internal/template/template.gohtml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
<link rel="stylesheet" href="{{ .AmisBaseURL }}@{{ .AmisVersion }}/sdk/helper.min.css" />
2828
<link rel="stylesheet" href="{{ .AmisBaseURL }}@{{ .AmisVersion }}/sdk/iconfont.min.css" />
2929
{{ end }}
30+
31+
{{ range .CustomCSS }}
32+
<link rel="stylesheet" href="{{.}}" />
33+
{{ end }}
34+
35+
{{ range .CustomJS }}
36+
<script src="{{.}}"></script>
37+
{{ end }}
3038

3139
<style>
3240
html,
@@ -38,7 +46,6 @@
3846
margin: 0;
3947
padding: 0;
4048
}
41-
{{ .CustomCSS }}
4249
</style>
4350
</head>
4451
<body>
@@ -48,11 +55,6 @@
4855
{{ else }}
4956
<script src="{{ .AmisBaseURL }}@{{ .AmisVersion }}/sdk/sdk.min.js"></script>
5057
{{ end }}
51-
{{ if .CustomJS }}
52-
<script type="text/javascript">
53-
{{ .CustomJS }}
54-
</script>
55-
{{ end }}
5658
<script type="text/javascript">
5759
(function () {
5860
let amis = amisRequire('amis/embed');

0 commit comments

Comments
 (0)