瀏覽代碼

Add HTML widget

Svilen Markov 1 年之前
父節點
當前提交
75079a981b
共有 3 個文件被更改,包括 36 次插入0 次删除
  1. 14 0
      docs/configuration.md
  2. 20 0
      internal/widget/html.go
  3. 2 0
      internal/widget/widget.go

+ 14 - 0
docs/configuration.md

@@ -26,6 +26,7 @@
   - [Twitch Channels](#twitch-channels)
   - [Twitch Channels](#twitch-channels)
   - [Twitch Top Games](#twitch-top-games)
   - [Twitch Top Games](#twitch-top-games)
   - [iframe](#iframe)
   - [iframe](#iframe)
+  - [HTML](#html)
 
 
 ## Intro
 ## Intro
 Configuration is done via a single YAML file and a server restart is required in order for any changes to take effect. Trying to start the server with an invalid config file will result in an error.
 Configuration is done via a single YAML file and a server restart is required in order for any changes to take effect. Trying to start the server with an invalid config file will result in an error.
@@ -1412,3 +1413,16 @@ The source of the iframe.
 
 
 ##### `height`
 ##### `height`
 The height of the iframe. The minimum allowed height is 50.
 The height of the iframe. The minimum allowed height is 50.
+
+### HTML
+Embed any HTML.
+
+Example:
+
+```yaml
+- type: html
+  source: |
+    <p>Hello, <span class="color-primary">World</span>!</p>
+```
+
+Note the use of `|` after `source:`, this allows you to insert a multi-line string.

+ 20 - 0
internal/widget/html.go

@@ -0,0 +1,20 @@
+package widget
+
+import (
+	"html/template"
+)
+
+type HTML struct {
+	widgetBase `yaml:",inline"`
+	Source     template.HTML `yaml:"source"`
+}
+
+func (widget *HTML) Initialize() error {
+	widget.withTitle("").withError(nil)
+
+	return nil
+}
+
+func (widget *HTML) Render() template.HTML {
+	return widget.Source
+}

+ 2 - 0
internal/widget/widget.go

@@ -27,6 +27,8 @@ func New(widgetType string) (Widget, error) {
 		return &Bookmarks{}, nil
 		return &Bookmarks{}, nil
 	case "iframe":
 	case "iframe":
 		return &IFrame{}, nil
 		return &IFrame{}, nil
+	case "html":
+		return &HTML{}, nil
 	case "hacker-news":
 	case "hacker-news":
 		return &HackerNews{}, nil
 		return &HackerNews{}, nil
 	case "releases":
 	case "releases":