summaryrefslogtreecommitdiffstats
path: root/layouts/shortcodes/recent-posts.html
blob: 14ce25ed83e11e2aa89cefdd15839a90590814a5 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} {{
$recent := first 8 $pages.ByDate.Reverse }}
<style>
  .recent-list {
    margin: 0;
  }

  .recent-item {
    position: relative;
    margin-bottom: 8px;
    display: flex;
    align-items: flex-start;
  }

  .item-link {
    display: inline-block;
    text-decoration: none;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .post-date {
    font-size: 0.9em;
    color: #666;
    display: inline-block;
    min-width: 80px;
    flex-shrink: 0;
  }

  .recent-empty {
    text-align: center;
    font-style: italic;
  }

  .recent-post-item {
    margin-bottom: 1em;
  }

  .recent-post-title {
    margin-top: 2px;
  }

  @media (max-width: 720px) {
    .recent-post-item {
      flex-direction: column; /* 改为上下排列 */
      gap: 4px; /* 缩短日期和标题的间距 */
      margin-bottom: 1.5em;
    }

    .post-date {
      min-width: auto;
      font-size: 0.85em;
    }

    .recent-post-title {
      font-size: 1.05em;
    }

    .item-link {
      white-space: normal; /* 允许换行 */
      word-wrap: break-word; /* 强制长单词/链接换行 */
      overflow: visible; /* 取消隐藏 */
      text-overflow: clip; /* 取消省略号 */
    }
  }
</style>
<div class="recent-posts">
  {{ if $recent }} {{ range $index, $page := $recent }}

  <div class="recent-post-item">
    <span class="post-date">
      <time datetime='{{ .Date.Format "2006-01-02" }}'>
        {{ .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }}
      </time>
    </span>

    <h3 class="recent-post-title">
      <a href="{{ .RelPermalink }}" class="item-link">{{ .Title }}</a>
    </h3>
  </div>
  {{ end }} {{ else }}
  <p class="recent-empty">暂无文章</p>
  {{ end }}
</div>