forked from kitian616/jekyll-TeXt-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooks.html
217 lines (193 loc) · 6 KB
/
books.html
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
206
207
208
209
210
211
212
213
214
215
216
217
---
layout: page
sidebar: false
full_width: true
---
<html>
<head>
<title>读书记录</title>
<style>
body {
font-family: Arial, sans-serif;
}
.timeline {
position: relative;
width: 90%;
margin: 0 auto;
padding-top: 20px;
}
.year {
position: relative;
padding-bottom: 20px;
}
.year-dot {
position: absolute;
top: 0;
left: -20px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #008000;
}
.year-number {
position: relative;
font-weight: bold;
font-size: 2.1em;
color: #8b4513;
background-color: #ff8c00;
padding: 5px 10px;
border-radius: 5px;
display: inline-block;
cursor: pointer;
margin-bottom: 10px;
}
.year-number .book-count {
font-size: 0.5em;
color: #ffffff;
}
.books-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
margin-top: 20px;
}
.book {
display: flex;
flex-direction: row;
border-left: 2px solid #008000;
padding-left: 15px;
max-width: 100%;
transition: all 0.3s;
}
.book-cover {
flex-shrink: 0;
width: 100px;
height: 150px;
object-fit: cover;
margin-right: 20px;
}
.book-info {
display: flex;
flex-direction: column;
justify-content: flex-start;
max-width: calc(100% - 140px);
transition: all 0.3s;
}
.book-details {
margin-bottom: 10px;
}
.book-details p {
margin: 0;
word-wrap: break-word;
font-size: 1em; /* 默认字体大小 */
}
.book-dates {
font-size: 0.8em; /* 调小的字体大小 */
color: #555; /* 可选:调整颜色以区分日期 */
}
.book-note {
position: relative;
word-wrap: break-word;
}
.book-note p {
margin: 0;
overflow: hidden;
white-space: normal;
}
.book-note.collapsed p {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.book-note.collapsed p::after {
content: '...查看更多';
color: blue;
cursor: pointer;
display: inline;
}
.year.collapsed .books-container {
display: none;
}
.expanded {
grid-column: 1 / -1; /* 占据整行 */
width: 100%; /* 最大宽度 */
}
.custom-title {
padding-left: 55px; /* 左侧空白的空间 */
}
@media (max-width: 480px) {
.custom-title {
padding-left: 0px; /* 左侧空白的空间 */
}
}
</style>
</head>
<h1 class="custom-title">在读和读过的书</h1>
<body>
{% assign previous_year = '' %}
<div class="timeline">
愿我们在白底黑字中读懂自己
{% assign books_by_year = site.data.books | group_by_exp:"book", "book.start_date | split: '.' | first" %}
{% assign sorted_books_by_year = books_by_year | sort: "name" | reverse %}
{% for year in sorted_books_by_year %}
{% assign current_year = year.name %}
<div class="year{% if forloop.first == false %} collapsed{% endif %}">
<div class="year-dot"></div>
<div class="year-number" onclick="toggleYear(this)">{{ current_year }} <span class="book-count">({{ year.items | size }})</span></div>
<div class="books-container">
{% for book in year.items %}
{%- if book.finish_date -%}
{% assign state = 'success' %}
{%- else -%}
{% assign state = 'warning' %}
{%- endif -%}
<div class="book">
<img class="book-cover" src="{{ book.cover }}" alt="{{ book.name }}"/>
<div class="book-info">
<div class="book-details">
<p class="{{ state }}">
<a href="{{ book.douban_link }}">{{ book.name }}</a><br>
<span class="book-dates">{{ book.start_date }} -> {{ book.finish_date }}</span>
</p>
</div>
<div class="book-note collapsed">
<p class="info">{{ book.note }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const notes = document.querySelectorAll('.book-note p.info');
notes.forEach(note => {
const noteText = note.textContent.trim();
const parent = note.parentElement;
if (noteText.length <= 150) {
parent.classList.remove('collapsed');
parent.removeAttribute('onclick'); // 移除点击事件
} else {
parent.classList.add('collapsed');
parent.setAttribute('onclick', 'toggleNoteIfNecessary(this)'); // 添加点击事件
}
});
});
function toggleYear(element) {
const yearElement = element.parentNode;
yearElement.classList.toggle('collapsed');
}
function toggleNoteIfNecessary(element) {
const note = element.querySelector('p.info');
const isCollapsed = element.classList.contains('collapsed');
if (isCollapsed) {
element.classList.remove('collapsed');
} else {
element.classList.add('collapsed');
}
}
</script>
</body>
</html>