summaryrefslogtreecommitdiff
path: root/layouts/_shortcodes/linkding-bookmarks.html
blob: 45109c2a85f166a819d0d28ffade8fa12abcd553 (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
{{/*
Shortcode to display Linkding RSS feed bookmarks
Usage: {{< linkding-bookmarks >}}
*/}}

{{/* Read the RSS feed file */}}
{{ $rssFile := "data/linkding.xml" }}
{{ if fileExists $rssFile }}
    {{ $rssContent := readFile $rssFile }}

    {{/* Parse RSS XML */}}
    {{ $rss := $rssContent | transform.Unmarshal }}

    {{ if $rss }}
        {{/* Get channel items */}}
        {{ $items := $rss.channel.item }}

        {{ if $items }}
            <div class="linkding-bookmarks">
                {{ range $items }}
                    <div class="bookmark-item mb-4 p-4 rounded-md" style="background-color: var(--block-background-color);">
                        <h3 class="m-0 mb-2">
                            <a href="{{ .link }}" target="_blank" rel="noopener noreferrer"
                               style="color: var(--text-color); text-decoration: none;">
                                {{ .title }}
                            </a>
                        </h3>
                        {{ if .description }}
                            <p class="m-0 text-sm opacity-80">{{ .description }}</p>
                        {{ end }}
                        {{ if .category }}
                            <div class="mt-2 flex flex-wrap gap-2">
                                {{ if reflect.IsSlice .category }}
                                    {{ range .category }}
                                        <span class="text-secondary text-xs rounded"
                                              style="background-color: var(--border-color-light);">
                                            #{{ . }}
                                        </span>
                                    {{ end }}
                                {{ else }}
                                    <span class="text-secondary text-xs rounded"
                                          style="background-color: var(--border-color-light);">
                                        #{{ .category }}
                                    </span>
                                {{ end }}
                            </div>
                        {{ end }}
                        <div class="mt-2 text-xs opacity-60">
                            于 {{ dateFormat "2006-01-02" .pubDate }} 添加至书签
                        </div>
                    </div>
                {{ end }}
            </div>
        {{ else }}
            <p>No bookmarks found in RSS feed.</p>
        {{ end }}
    {{ else }}
        <p>Unable to parse RSS feed.</p>
    {{ end }}
{{ else }}
    <p>RSS feed file not found. Please run the GitHub Action to fetch the feed.</p>
{{ end }}