aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/feeds-generate.html
blob: ab6043589f48f8edc8e4badae2f85cce5367c2c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{{- $author := index .Site.Data.authors ((or .Params.author .Site.Author.default.user) | default "default") -}}

{{ $feeds := slice }}

{{- if $author.webring.rss -}}
  {{ range $key, $value := (seq 3) }}
    {{ range $author.webring.rss -}}

      {{ with resources.GetRemote . }}
        {{- with .Err -}}
          {{- warnf "%s" . -}}
        {{- end -}}
      {{ end }}

      {{ with resources.GetRemote . | transform.Unmarshal -}}

        {{- $title              := "No Title Found" -}}
        {{- $link               := "https://example.com/link" -}}
        {{- $description        := "No description found." -}}
        {{- $content            := "No content found." -}}
        {{- $sourceTitle        := "No source title found" -}}
        {{- $sourceLink         := "https://example.com/" -}}
        {{- $sourceDescription  := "No source description found." -}}
        {{- $date               := now.Format "2006-01-02T15:04:05Z" -}}

        {{ with .channel -}}

          {{ if reflect.IsMap (index .link 0) -}}
            {{ $sourceLink = index (index .link 0) "-href" -}}
          {{ else -}}
            {{ $sourceLink = index .link 0 -}}
          {{ end -}}

          {{ $sourceTitle       = .title -}}
          {{ $sourceDescription = .description -}}


          {{ if reflect.IsMap .item -}}
            {{ with .item }}
              {{ $title = index . "title" }}
              {{ $link  = index . "link" }}
              {{ $date  = index . "pubDate" }}
            {{ end }}
          {{ else -}}
            {{ range first $value .item -}}
              {{ $description = .description -}}
              {{ $content     = .description -}}
              {{ $title       = .title -}}
              {{ $link        = .link -}}
              {{ $date        = .pubDate -}}
            {{ end -}}
          {{ end }}

        {{ else -}}

          {{ $sourceLink = index (index .link 0) "-href" -}}
          {{ $sourceTitle = .title -}}
          {{ $sourceDescription = .subtitle -}}

          {{ range first $value .entry -}}

            {{ if reflect.IsMap .title -}}
              {{ $title = index .title "#text" -}}
            {{ else -}}
              {{ $title = .title -}}
            {{ end -}}

            {{ $date = .updated -}}
            {{ $link = .id -}}

              {{ with .content -}}
                {{ $description = index . "#text" -}}
                {{ $content     = index . "#text" -}}
              {{ end -}}
              {{ with .summary -}}
                {{ $description = index . "#text" -}}
                {{ $content     = index . "#text" -}}
              {{ end -}}
            {{ end -}}

        {{ end -}}

        {{
          $feeds = $feeds | append (dict
            "FeedContent"           ($content | plainify | htmlUnescape)
            "FeedContentShort"      (delimit (first 1 (split ($content | plainify | htmlUnescape) "\n")) " " | truncate 250)
            "FeedDate"              ($date | plainify | htmlUnescape | time.Format "January 2, 2006")
            "FeedDateTime"          ($date | plainify | htmlUnescape | time.Format "2006-01-02T15:04:05Z")
            "FeedDateTitle"         ($date | plainify | htmlUnescape | time.Format "Monday, January 2 2006 at 15:04:05 MST")
            "FeedDescription"       ($description | plainify | htmlUnescape)
            "FeedDescriptionShort"  (delimit (first 1 (split ($description | plainify | htmlUnescape) "\n")) " " | truncate 250)
            "FeedLink"              ($link | plainify | htmlUnescape)
            "FeedName"              (delimit ((delimit (first 3 (split ($sourceTitle | plainify | htmlUnescape) " ")) " ") | findRE "^([^.|:|?|!]+)") " " | replaceRE "[^a-zA-Z ]" "")
            "FeedSourceDescription" ($sourceDescription | plainify | htmlUnescape)
            "FeedSourceDomain"      (($sourceLink | plainify | htmlUnescape | urls.Parse).Host)
            "FeedSourceLink"        ($sourceLink | plainify | htmlUnescape)
            "FeedSourceTitle"       ($sourceTitle | plainify | htmlUnescape)
            "FeedTitle"             ($title | plainify | htmlUnescape)
          )
        }}

      {{ end }}
    {{ end }}
  {{ end }}

  {{ range $feeds }}

    {{- $imageCanonicalURL :=
      (print
        "https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url="
        "http://"
        .FeedSourceDomain
        "&size=64"
      )
    -}}
    {{- $imageSource       := "/images/404.png" -}}
    {{- $imageTitle        := "No image found" -}}

    {{- with $image := resources.GetRemote $imageCanonicalURL -}}
      {{- with .Err -}}
        {{ warnf "%s" . }}
        {{- $fallbackImage := imageConfig (print "static/images/404.png") -}}
        {{- with $fallbackImage -}}
          {{- $fallbackWidth  := .Width -}}
          {{- $fallbackHeight := .Height -}}
        {{ end }}
      {{- else -}}
        {{- $imageTitle  = $imageCanonicalURL -}}
        {{- $imageSource = $image.RelPermalink -}}
      {{ end }}
    {{ end }}

    {{ $template := resources.Get "templates/markdown-feed.yaml" }}
    {{ $name := urlize (replace .FeedTitle "/" "-") }}
    {{ $path := print "/data/generates/content/" $author.user "/feeds/" $name ".md" }}

    {{ $description := .FeedSourceTitle }}
    {{ if gt (len .FeedSourceDescription) (len .FeedSourceTitle) }}
     {{ $description = .FeedSourceDescription }}
    {{ end }}

    {{ $content := .FeedContentShort }}
    {{ if gt (len .FeedTitle) (len .FeedContentShort) }}
     {{ $content = .FeedTitle }}
    {{ end }}

    {{ $markdown := resources.ExecuteAsTemplate
       $path
       (dict
        "author"      $author.user
        "content"     $content
        "date"        .FeedDateTime
        "description" $description
        "domain"      .FeedSourceDomain
        "image"       $imageSource
        "link"        .FeedLink
        "name"        .FeedName
        "raw"         (strings.TrimLeft "/" $path)
        "self"        (print $author.user "/feeds/" $name "/")
        "tags"        "[rss]"
       )
       $template
    }}
    {{ $writeToFile := $markdown.RelPermalink }}
  {{ end }}

    <web-ring>
      <h1>Web Ring</h1>
        <aside>
          {{ range first 3 (uniq (sort $feeds "FeedDateTime" "desc")) }}
            <web-ring-item>
              <header>
                <a
                  rel="noopener"
                  target="_blank"
                  title="{{ .FeedLink }}"
                  href="{{ .FeedLink }}">
                  {{ .FeedTitle }}
                </a>
              </header>

              <p>
                <time
                  title="{{ .FeedDateTitle }}"
                  datetime="{{ .FeedDateTime }}">
                  {{ .FeedDate }}
                </time>
                {{- with .FeedDescriptionShort -}}
                  {{ "--" | markdownify }}
                  {{ . }}
                {{- end }}
              </p>

              <a
                rel="noopener"
                target="_blank"
                title="{{ .FeedSourceDescription }}"
                href="{{ .FeedSourceLink }}">
                {{ .FeedSourceTitle }}
              </a>
            </web-ring-item>
          {{ end }}
      </aside>
    </web-ring>
{{ end }}