Browse Source

Add Widget-Content-Frameless option to extension widget

Svilen Markov 6 tháng trước cách đây
mục cha
commit
495eaa0a37

+ 3 - 0
docs/extensions.md

@@ -29,6 +29,9 @@ Used to specify the title of the widget. If not provided, the widget's title wil
 ### `Widget-Content-Type`
 ### `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.
 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
 ## Content Types
 
 
 > [!NOTE]
 > [!NOTE]

+ 2 - 0
internal/glance/templates/extension.html

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

+ 10 - 4
internal/glance/widget-extension.go

@@ -76,8 +76,9 @@ var extensionStringToType = map[string]extensionType{
 }
 }
 
 
 const (
 const (
-	extensionHeaderTitle       = "Widget-Title"
-	extensionHeaderContentType = "Widget-Content-Type"
+	extensionHeaderTitle            = "Widget-Title"
+	extensionHeaderContentType      = "Widget-Content-Type"
+	extensionHeaderContentFrameless = "Widget-Content-Frameless"
 )
 )
 
 
 type extensionRequestOptions struct {
 type extensionRequestOptions struct {
@@ -88,8 +89,9 @@ type extensionRequestOptions struct {
 }
 }
 
 
 type extension 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 {
 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)
 	extension.Content = convertExtensionContent(options, body, contentType)
 
 
 	return extension, nil
 	return extension, nil