forked from jriou/coller
feat: Option to serve Bootstrap from the filesystem
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
b62a807f89
commit
ff92e30232
8 changed files with 94 additions and 6 deletions
|
@ -28,6 +28,7 @@ type Config struct {
|
|||
EnableUploadFileButton bool `json:"enable_upload_file_button"`
|
||||
TLSCertFile string `json:"tls_cert_file"`
|
||||
TLSKeyFile string `json:"tls_key_file"`
|
||||
BootstrapDirectory string `json:"bootstrap_directory"`
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
|
|
|
@ -196,6 +196,7 @@ type PageData struct {
|
|||
URL string
|
||||
Note *Note
|
||||
EnableUploadFileButton bool
|
||||
BootstrapDirectory string
|
||||
}
|
||||
|
||||
type HomeHandler struct {
|
||||
|
@ -430,10 +431,11 @@ func (s *Server) Start() error {
|
|||
"string": func(b []byte) string { return string(b) },
|
||||
}
|
||||
p := PageData{
|
||||
Title: s.config.Title,
|
||||
Expirations: s.config.Expirations,
|
||||
Expiration: s.config.Expiration,
|
||||
Languages: s.config.Languages,
|
||||
Title: s.config.Title,
|
||||
Expirations: s.config.Expirations,
|
||||
Expiration: s.config.Expiration,
|
||||
Languages: s.config.Languages,
|
||||
BootstrapDirectory: s.config.BootstrapDirectory,
|
||||
}
|
||||
|
||||
if s.config.ShowVersion {
|
||||
|
@ -470,6 +472,10 @@ func (s *Server) Start() error {
|
|||
}
|
||||
r.Path("/{id:[a-zA-Z0-9]+}.html").Handler(webNoteHandler).Methods("GET")
|
||||
|
||||
if s.config.BootstrapDirectory != "" {
|
||||
r.PathPrefix("/static/bootstrap/").Handler(http.StripPrefix("/static/bootstrap/", http.FileServer(http.Dir(s.config.BootstrapDirectory))))
|
||||
}
|
||||
|
||||
r.Path("/").Handler(&HomeHandler{Templates: templates, PageData: p}).Methods("GET")
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", s.config.ListenAddress, s.config.ListenPort)
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
<title>{{.Title}}</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{{if ne .BootstrapDirectory ``}}/static/bootstrap/css/bootstrap.min.css{{else}}https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css{{end}}" rel="stylesheet">
|
||||
</head>
|
||||
{{end}}
|
Loading…
Add table
Add a link
Reference in a new issue