summaryrefslogtreecommitdiffstats
path: root/layouts/shortcodes/recent-posts.html
blob: 55f7cd4a4a6ab0771b719b3ba811b5190048eaa8 (plain) (blame)
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
{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ $recent := first 12 $pages.ByDate.Reverse }}

<style>
  .recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .recent-list li {
    margin-bottom: 0.5em;
    line-height: 1.4;
  }
  .recent-date {
    font-family: monospace;
    margin-right: 1.5em;
    white-space: nowrap;
  }
  .recent-title {
    word-wrap: break-word;
  }
  .recent-empty {
    text-align: center;
    font-style: italic;
  }
  @media (max-width: 720px) {
    .recent-list li {
      display: flex;
      flex-wrap: wrap;
    }
    .recent-date {
      width: auto;
      margin-right: 0.5em;
    }
  }

  .recent-posts {
      margin-top: .8rem;
  }

  .recent-posts h2 {
      margin-top: 1rem;
      margin-bottom: 1rem;

  }
</style>

<div class="recent-posts">
  <h2>最近更新</h2>
  {{ if $recent }}
  <ul class="recent-list">
    {{ range $recent }}
    <li>
      <span class="recent-date">{{ .Date.Format "2006-01-02" }}</span>
      <a href="{{ .RelPermalink }}" class="recent-title">{{ .Title }}</a>
    </li>
    {{ end }}
  </ul>
  {{ else }}
  <div class="recent-empty">暂无文章</div>
  {{ end }}
</div>