feat: Option to serve Bootstrap from the filesystem
All checks were successful
/ pre-commit (push) Successful in 1m7s

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-09-16 09:36:10 +02:00
commit ff92e30232
Signed by: jriou
GPG key ID: 9A099EDA51316854
8 changed files with 94 additions and 6 deletions

View file

@ -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 {

View file

@ -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)

View file

@ -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}}