Add Widget-Content-Frameless option to extension widget

This commit is contained in:
Svilen Markov 2024-12-22 13:31:26 +00:00
parent b44b7b80ff
commit 495eaa0a37
3 changed files with 15 additions and 4 deletions

View File

@ -29,6 +29,9 @@ Used to specify the title of the widget. If not provided, the widget's title wil
### `Widget-Content-Type`
Used to specify the content type that will be returned by the extension. If not provided, the content will be shown as plain text.
### `Widget-Content-Frameless`
When set to `true`, the widget's content will be displayed without the default background or "frame".
## Content Types
> [!NOTE]

View File

@ -1,5 +1,7 @@
{{ template "widget-base.html" . }}
{{ define "widget-content-classes" }}{{ if .Extension.Frameless }}widget-content-frameless{{ end }}{{ end }}
{{ define "widget-content" }}
{{ .Extension.Content }}
{{ end }}

View File

@ -76,8 +76,9 @@ var extensionStringToType = map[string]extensionType{
}
const (
extensionHeaderTitle = "Widget-Title"
extensionHeaderContentType = "Widget-Content-Type"
extensionHeaderTitle = "Widget-Title"
extensionHeaderContentType = "Widget-Content-Type"
extensionHeaderContentFrameless = "Widget-Content-Frameless"
)
type extensionRequestOptions struct {
@ -88,8 +89,9 @@ type extensionRequestOptions struct {
}
type extension struct {
Title string
Content template.HTML
Title string
Content template.HTML
Frameless bool
}
func convertExtensionContent(options extensionRequestOptions, content []byte, contentType extensionType) template.HTML {
@ -148,6 +150,10 @@ func fetchExtension(options extensionRequestOptions) (extension, error) {
}
}
if stringToBool(response.Header.Get(extensionHeaderContentFrameless)) {
extension.Frameless = true
}
extension.Content = convertExtensionContent(options, body, contentType)
return extension, nil