From b41368462c89dbfc5230350c46629266f03ad9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 16 Feb 2021 19:24:33 +0100 Subject: Use go-embed for templates instead of inline strings. They should also use CRLF (cf issue #46). --- .editorconfig | 3 +- .gitattributes | 5 +++ internal/feed/template/html.tpl | 58 +++++++++++++++++++++++++++++++++++ internal/feed/template/html.tpl.go | 63 -------------------------------------- internal/feed/template/template.go | 9 ++++++ internal/feed/template/text.tpl | 37 ++++++++++++++++++++++ internal/feed/template/text.tpl.go | 42 ------------------------- 7 files changed, 111 insertions(+), 106 deletions(-) create mode 100644 .gitattributes create mode 100644 internal/feed/template/html.tpl delete mode 100644 internal/feed/template/html.tpl.go create mode 100644 internal/feed/template/text.tpl delete mode 100644 internal/feed/template/text.tpl.go diff --git a/.editorconfig b/.editorconfig index 03f964f..0111a8e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,4 +9,5 @@ indent_size = 4 [*.tpl] indent_style = space -indent_size = 2 \ No newline at end of file +indent_size = 2 +end_of_line = crlf \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..777829e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Default +* text=auto + +# Templates should have CRLF +*.tpl text eol=crlf diff --git a/internal/feed/template/html.tpl b/internal/feed/template/html.tpl new file mode 100644 index 0000000..b320ebb --- /dev/null +++ b/internal/feed/template/html.tpl @@ -0,0 +1,58 @@ +{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} +{{define "bottomLine"}} + {{if .content}} + + + {{.descr}}   + + + {{.content}} + + + {{end}} +{{end}} + + + + + + + + + +
Feed + {{with .Feed.Link}}{{end}} + {{or .Feed.Title .Feed.Link "Unnammed feed"}} + {{if .Feed.Link}}{{end}} +
Item + {{with .Item.Link}}{{end}} + {{or .Item.Title .Item.Link}} + {{if .Item.Link}}{{end}} +
+{{with .Body}} + {{html .}} +{{end}} +{{with .Item.Enclosures}} + + + + + {{range .}} + + + + {{end}} +
Files:
+     + {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) +
+{{end}} +
+ + {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} + {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} + {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} + {{with .FeedLink}} + {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} + {{end}} +
\ No newline at end of file diff --git a/internal/feed/template/html.tpl.go b/internal/feed/template/html.tpl.go deleted file mode 100644 index be84030..0000000 --- a/internal/feed/template/html.tpl.go +++ /dev/null @@ -1,63 +0,0 @@ -package template - -var Html = fromString("Feed", htmlTpl, true) - -//noinspection HtmlDeprecatedAttribute,HtmlUnknownTarget -const htmlTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} -{{define "bottomLine"}} - {{if .content}} - - - {{.descr}}   - - - {{.content}} - - - {{end}} -{{end}} - - - - - - - - - -
Feed - {{with .Feed.Link}}{{end}} - {{or .Feed.Title .Feed.Link "Unnammed feed"}} - {{if .Feed.Link}}{{end}} -
Item - {{with .Item.Link}}{{end}} - {{or .Item.Title .Item.Link}} - {{if .Item.Link}}{{end}} -
-{{with .Body}} - {{html .}} -{{end}} -{{with .Item.Enclosures}} - - - - - {{range .}} - - - - {{end}} -
Files:
-     - {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) -
-{{end}} -
- - {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} - {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} - {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} - {{with .FeedLink}} - {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} - {{end}} -
` diff --git a/internal/feed/template/template.go b/internal/feed/template/template.go index d8eb850..09dacf1 100644 --- a/internal/feed/template/template.go +++ b/internal/feed/template/template.go @@ -15,6 +15,15 @@ type Template interface { Execute(wr io.Writer, data interface{}) error } +//go:embed html.tpl +var htmlTpl string + +//go:embed text.tpl +var textTpl string + +var Html = fromString("Feed", htmlTpl, true) +var Text = fromString("Feed", textTpl, false) + func must(t Template, err error) Template { if err != nil { panic(err) diff --git a/internal/feed/template/text.tpl b/internal/feed/template/text.tpl new file mode 100644 index 0000000..57eef18 --- /dev/null +++ b/internal/feed/template/text.tpl @@ -0,0 +1,37 @@ +{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} +{{- with .Item.Link -}} +<{{.}}> + +{{ end -}} +{{- with .TextBody -}} +{{.}} +{{ end -}} +{{- with .Item.Enclosures}} +Files: +{{- range . }} + {{ .URL}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) +{{- end -}} +{{- end}} +-- +Feed: {{ with .Feed.Title -}}{{.}}{{- end }} +{{ with .Feed.Link -}} + <{{.}}> +{{end -}} +Item: {{ with .Item.Title -}} + {{.}} +{{- end }} +{{ with .Item.Link -}} + <{{.}}> +{{end -}} +{{ with .Date -}} + Date: {{.}} +{{ end -}} +{{ with .Creator -}} + Author: {{.}} +{{ end -}} +{{ with (join ", " .Categories) -}} + Filed under: {{.}} +{{ end -}} +{{ with .FeedLink -}} + Feed-Link: {{.}} +{{ end -}} \ No newline at end of file diff --git a/internal/feed/template/text.tpl.go b/internal/feed/template/text.tpl.go deleted file mode 100644 index 19aa9b2..0000000 --- a/internal/feed/template/text.tpl.go +++ /dev/null @@ -1,42 +0,0 @@ -package template - -var Text = fromString("Feed", textTpl, false) - -//noinspection HtmlDeprecatedAttribute,HtmlUnknownTarget -const textTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} -{{- with .Item.Link -}} -<{{.}}> - -{{ end -}} -{{- with .TextBody -}} -{{.}} -{{ end -}} -{{- with .Item.Enclosures}} -Files: -{{- range . }} - {{ .URL}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) -{{- end -}} -{{- end}} --- -Feed: {{ with .Feed.Title -}}{{.}}{{- end }} -{{ with .Feed.Link -}} - <{{.}}> -{{end -}} -Item: {{ with .Item.Title -}} - {{.}} -{{- end }} -{{ with .Item.Link -}} - <{{.}}> -{{end -}} -{{ with .Date -}} - Date: {{.}} -{{ end -}} -{{ with .Creator -}} - Author: {{.}} -{{ end -}} -{{ with (join ", " .Categories) -}} - Filed under: {{.}} -{{ end -}} -{{ with .FeedLink -}} - Feed-Link: {{.}} -{{ end -}}` -- cgit v1.2.3 From 76583655b140ead3b1212ea0dcbcf9cab7278379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 16 Feb 2021 19:27:13 +0100 Subject: Increment go-version to 1.16 --- .github/workflows/go.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- go.mod | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2286985..e1cf719 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.15 + - name: Set up Go 1.16 uses: actions/setup-go@v2 with: - go-version: 1.15 + go-version: 1.16 id: go - name: Checkout diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb80408..687b92d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.15 + - name: Set up Go 1.16 uses: actions/setup-go@v2 with: - go-version: 1.15 + go-version: 1.16 id: go - name: Checkout diff --git a/go.mod b/go.mod index 36796c2..2f0fc80 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Necoro/feed2imap-go -go 1.15 +go 1.16 require ( github.com/PuerkitoBio/goquery v1.6.1 -- cgit v1.2.3 From 44d52ca74fabfecc3b47a31ccdcbdded5300170f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 16 Feb 2021 19:35:14 +0100 Subject: Fix CRLF ending --- internal/feed/template/html.tpl | 114 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/internal/feed/template/html.tpl b/internal/feed/template/html.tpl index b320ebb..aa7d341 100644 --- a/internal/feed/template/html.tpl +++ b/internal/feed/template/html.tpl @@ -1,58 +1,58 @@ -{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} -{{define "bottomLine"}} - {{if .content}} - - - {{.descr}}   - - - {{.content}} - - - {{end}} -{{end}} - - - - - - - - - -
Feed - {{with .Feed.Link}}{{end}} - {{or .Feed.Title .Feed.Link "Unnammed feed"}} - {{if .Feed.Link}}{{end}} -
Item - {{with .Item.Link}}{{end}} - {{or .Item.Title .Item.Link}} - {{if .Item.Link}}{{end}} -
-{{with .Body}} - {{html .}} -{{end}} -{{with .Item.Enclosures}} - - - - - {{range .}} - - - - {{end}} -
Files:
-     - {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) -
-{{end}} -
- - {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} - {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} - {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} - {{with .FeedLink}} - {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} - {{end}} +{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feeditem*/ -}} +{{define "bottomLine"}} + {{if .content}} + + + + + {{end}} +{{end}} +
+ {{.descr}}   + + {{.content}} +
+ + + + + + + + +
Feed + {{with .Feed.Link}}{{end}} + {{or .Feed.Title .Feed.Link "Unnammed feed"}} + {{if .Feed.Link}}{{end}} +
Item + {{with .Item.Link}}{{end}} + {{or .Item.Title .Item.Link}} + {{if .Item.Link}}{{end}} +
+{{with .Body}} + {{html .}} +{{end}} +{{with .Item.Enclosures}} + + + + + {{range .}} + + + + {{end}} +
Files:
+     + {{.URL | lastUrlPart}} ({{with .Length}}{{. | byteCount}}, {{end}}{{.Type}}) +
+{{end}} +
+ + {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} + {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} + {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} + {{with .FeedLink}} + {{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "" . "" | html))}} + {{end}}
\ No newline at end of file -- cgit v1.2.3 From 2df7f561b6a4977051499731740aae2138c9d001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Thu, 18 Feb 2021 09:47:23 +0100 Subject: Import 'embed' package --- internal/feed/template/template.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/feed/template/template.go b/internal/feed/template/template.go index 09dacf1..9804190 100644 --- a/internal/feed/template/template.go +++ b/internal/feed/template/template.go @@ -1,6 +1,7 @@ package template import ( + _ "embed" "fmt" html "html/template" "io" -- cgit v1.2.3