hexo-theme-linen 1.0.51 → 1.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/layout/post.ejs CHANGED
@@ -39,7 +39,8 @@
39
39
  </div>
40
40
  <% } %>
41
41
 
42
- <article id="post" class="article">
42
+ <% const isTravelSeries = ['旅行', 'Travel'].includes(page.series); %>
43
+ <article id="post" class="article<%= isTravelSeries ? ' travel-post' : '' %>">
43
44
  <h1 class="post-title"><%=page.title%><% if (page.subTitle) { %><span class="sub-title"><%=page.subTitle%></span><% } %></h1>
44
45
  <div class="post-meta">
45
46
  <% if (page.date && !date(page.date).startsWith('1970')) { %>
@@ -76,10 +77,10 @@
76
77
  <div class="post-nav-wrap">
77
78
  <div class="post-nav">
78
79
  <% if (page.prev) { %>
79
- <a class="post-nav-item prev" target="_self" href="<%= url_for(page.prev.path) %>"><span class="item-link"><%= page.prev.title %></span><% if (page.prev.subTitle) { %><span class="sub-title"><%=page.prev.subTitle%></span><% } %><span class="nav-indicator-text"><%=__('common.prevPost')%></span></a>
80
+ <a class="post-nav-item prev" target="_self" href="<%= url_for(page.prev.path) %>"><span class="nav-indicator-text"><%=__('common.prevPost')%></span><span class="post-nav-title"><span class="item-link"><%= page.prev.title %></span><% if (page.prev.subTitle) { %><span class="sub-title"><%=page.prev.subTitle%></span><% } %></span></a>
80
81
  <% } %>
81
82
  <% if (page.next) { %>
82
- <a class="post-nav-item next" target="_self" href="<%= url_for(page.next.path) %>"><span class="item-link"><%= page.next.title %></span><% if (page.next.subTitle) { %><span class="sub-title"><%=page.next.subTitle%></span><% } %><span class="nav-indicator-text"><%=__('common.nextPost')%></a>
83
+ <a class="post-nav-item next" target="_self" href="<%= url_for(page.next.path) %>"><span class="nav-indicator-text"><%=__('common.nextPost')%></span><span class="post-nav-title"><span class="item-link"><%= page.next.title %></span><% if (page.next.subTitle) { %><span class="sub-title"><%=page.next.subTitle%></span><% } %></span></a>
83
84
  <% } %>
84
85
  </div>
85
86
  </div>
@@ -130,10 +131,10 @@ const seriesInfo = getSeriesInfo(page?.series);
130
131
  <div class="post-nav-wrap">
131
132
  <div class="post-nav">
132
133
  <% if (previousPost) { %>
133
- <a class="post-nav-item prev" target="_self" href="<%=url_for(previousPost.path)%>"><span class="item-link"><%=previousPost.title %></span><% if (previousPost.subTitle) { %><span class="sub-title"><%=previousPost.subTitle%></span><% } %><span class="nav-indicator-text"><%=__('common.prevPost')%></span></a>
134
+ <a class="post-nav-item prev" target="_self" href="<%=url_for(previousPost.path)%>"><span class="nav-indicator-text"><%=__('common.prevPost')%></span><span class="post-nav-title"><span class="item-link"><%=previousPost.title %></span><% if (previousPost.subTitle) { %><span class="sub-title"><%=previousPost.subTitle%></span><% } %></span></a>
134
135
  <% } %>
135
136
  <% if (nextPost) { %>
136
- <a class="post-nav-item next" target="_self" href="<%=url_for(nextPost.path)%>"><span class="item-link"><%=nextPost.title %></span><% if (nextPost.subTitle) { %><span class="sub-title"><%=nextPost.subTitle%></span><% } %><span class="nav-indicator-text"><%=__('common.nextPost')%></a>
137
+ <a class="post-nav-item next" target="_self" href="<%=url_for(nextPost.path)%>"><span class="nav-indicator-text"><%=__('common.nextPost')%></span><span class="post-nav-title"><span class="item-link"><%=nextPost.title %></span><% if (nextPost.subTitle) { %><span class="sub-title"><%=nextPost.subTitle%></span><% } %></span></a>
137
138
  <% } %>
138
139
  </div>
139
140
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-linen",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "description": "A clean Hexo theme",
5
5
  "main": "index.js",
6
6
  "homepage": "https://github.com/lynanbreeze/hexo-theme-linen",
package/scripts/custom.js CHANGED
@@ -1,3 +1,335 @@
1
+ const TRAVEL_SERIES_NAMES = ["旅行", "Travel"];
2
+ const TRAVEL_ROUTE_HEADING_REGEX = /^(?:路线|路线规划|Route|Route Planning)$/i;
3
+ const TRAVEL_ROUTE_PALETTE = [
4
+ "#c97a63",
5
+ "#a8452e",
6
+ "#8a9a86",
7
+ "#c4b7a6",
8
+ "#b87d56",
9
+ "#6d8b74",
10
+ "#d49a79",
11
+ "#9c8f84",
12
+ ];
13
+
14
+ function stripHtmlTags(str) {
15
+ return String(str || "")
16
+ .replace(/<[^>]*>/g, "")
17
+ .trim();
18
+ }
19
+
20
+ function stripHeadingText(str) {
21
+ return stripHtmlTags(
22
+ String(str || "").replace(
23
+ /<a[^>]*class="[^"]*(?:headerlink|header-anchor)[^"]*"[^>]*>[\s\S]*?<\/a>/gi,
24
+ "",
25
+ ),
26
+ )
27
+ .replace(/^[#¶\s]+|[#¶\s]+$/g, "")
28
+ .trim();
29
+ }
30
+
31
+ function escapeAttr(str) {
32
+ return String(str || "").replace(/[&<>"']/g, (ch) => ({
33
+ "&": "&amp;",
34
+ "<": "&lt;",
35
+ ">": "&gt;",
36
+ '"': "&quot;",
37
+ "'": "&#39;",
38
+ })[ch]);
39
+ }
40
+
41
+ function parseChineseNumeral(str) {
42
+ const map = {
43
+ 半: 0.5,
44
+ 一: 1,
45
+ 二: 2,
46
+ 两: 2,
47
+ 三: 3,
48
+ 四: 4,
49
+ 五: 5,
50
+ 六: 6,
51
+ 七: 7,
52
+ 八: 8,
53
+ 九: 9,
54
+ 十: 10,
55
+ };
56
+ if (str in map) return map[str];
57
+ if (/^十[一二三四五六七八九]$/.test(str)) {
58
+ return 10 + map[str[1]];
59
+ }
60
+ return null;
61
+ }
62
+
63
+ function parseDurationFragment(text) {
64
+ const trimmed = String(text || "").trim();
65
+ if (!trimmed) return null;
66
+
67
+ // Compound: e.g. "2天1晚", "3 日 2 晚"
68
+ const compoundMatch = trimmed.match(
69
+ /^(\d+(?:\.\d+)?)\s*(日|天)\s*\d+(?:\.\d+)?\s*(?:晚|夜)$/,
70
+ );
71
+ if (compoundMatch) {
72
+ const value = Number(compoundMatch[1]);
73
+ if (Number.isFinite(value) && value > 0) {
74
+ return {
75
+ label: trimmed,
76
+ weight: value,
77
+ unitKind: "day",
78
+ unitText: compoundMatch[2],
79
+ };
80
+ }
81
+ }
82
+
83
+ // Half-day forms: "半日", "半天", "half day"
84
+ if (/^(半日|半天|half\s+day)$/i.test(trimmed)) {
85
+ const isEn = /day/i.test(trimmed);
86
+ return {
87
+ label: trimmed,
88
+ weight: 0.5,
89
+ unitKind: "day",
90
+ unitText: isEn ? "days" : trimmed.endsWith("日") ? "日" : "天",
91
+ };
92
+ }
93
+
94
+ // Chinese numeral forms: "一日", "两天", "一天半", "三日半"
95
+ const zhNumMatch = trimmed.match(
96
+ /^(十?[一二两三四五六七八九]|十)\s*(日|天|晚|夜)(半)?$/,
97
+ );
98
+ if (zhNumMatch) {
99
+ const base = parseChineseNumeral(zhNumMatch[1]);
100
+ if (base) {
101
+ const value = base + (zhNumMatch[3] ? 0.5 : 0);
102
+ const unitChar = zhNumMatch[2];
103
+ return {
104
+ label: trimmed,
105
+ weight: value,
106
+ unitKind: unitChar === "晚" || unitChar === "夜" ? "night" : "day",
107
+ unitText: unitChar,
108
+ };
109
+ }
110
+ }
111
+
112
+ // Numeric forms: "2 日", "0.5 天", "5 days", "2d", "3 nights", "4 小时", "3h"
113
+ const numMatch = trimmed.match(
114
+ /^(\d+(?:\.\d+)?)\s*(日|天|晚|夜|小时|days?|nights?|hours?|hrs?|d|h)$/i,
115
+ );
116
+ if (numMatch) {
117
+ const value = Number(numMatch[1]);
118
+ const unitRaw = numMatch[2];
119
+ if (Number.isFinite(value) && value > 0) {
120
+ const lower = unitRaw.toLowerCase();
121
+ let unitKind = "day";
122
+ let unitText = unitRaw;
123
+ if (lower === "晚" || lower === "夜" || lower.startsWith("night")) {
124
+ unitKind = "night";
125
+ unitText = lower.startsWith("night") ? "nights" : unitRaw;
126
+ } else if (
127
+ lower === "小时" ||
128
+ lower.startsWith("hour") ||
129
+ lower.startsWith("hr") ||
130
+ lower === "h"
131
+ ) {
132
+ unitKind = "hour";
133
+ unitText = lower === "小时" ? "小时" : "hours";
134
+ } else if (lower.startsWith("day") || lower === "d") {
135
+ unitKind = "day";
136
+ unitText = "days";
137
+ }
138
+ return {
139
+ label: trimmed,
140
+ weight: value,
141
+ unitKind,
142
+ unitText,
143
+ };
144
+ }
145
+ }
146
+
147
+ return null;
148
+ }
149
+
150
+ function parseTravelRouteItem(rawHtml) {
151
+ let content = String(rawHtml || "").trim();
152
+ if (/^<p>[\s\S]*<\/p>$/i.test(content) && !/<\/p>\s*<p>/i.test(content)) {
153
+ content = content.replace(/^<p>|<\/p>$/gi, "").trim();
154
+ }
155
+
156
+ let note = "";
157
+ let duration = null;
158
+
159
+ // Check for trailing parenthetical: either a pure duration like "大阪(2日)" or a note like "大阪 2 日(心斋桥)"
160
+ const trailingParenMatch = content.match(
161
+ /^(.*?)[\s]*(?:(([^()]+))|\(([^()]+)\))\s*$/,
162
+ );
163
+ if (trailingParenMatch && trailingParenMatch[1].trim()) {
164
+ const parenInner = (
165
+ trailingParenMatch[2] ||
166
+ trailingParenMatch[3] ||
167
+ ""
168
+ ).trim();
169
+ const parenDuration = parseDurationFragment(parenInner);
170
+ if (parenDuration) {
171
+ duration = parenDuration;
172
+ content = trailingParenMatch[1].trim();
173
+ } else {
174
+ note = parenInner;
175
+ content = trailingParenMatch[1].trim();
176
+ }
177
+ }
178
+
179
+ // Extract trailing duration from the remaining content if not yet parsed
180
+ if (!duration) {
181
+ const tailMatch = content.match(
182
+ /^(.*?)(?:[\s·•\-—::,,/]+)(\d+(?:\.\d+)?\s*(?:日|天)\s*\d+(?:\.\d+)?\s*(?:晚|夜)|\d+(?:\.\d+)?\s*(?:日|天|晚|夜|小时|days?|nights?|hours?|hrs?|d|h)|(?:半日|半天|half\s+day)|(?:十?[一二两三四五六七八九]|十)\s*(?:日|天|晚|夜)(?:半)?)\s*$/i,
183
+ );
184
+ if (tailMatch && tailMatch[1].trim()) {
185
+ const parsed = parseDurationFragment(tailMatch[2]);
186
+ if (parsed) {
187
+ duration = parsed;
188
+ content = tailMatch[1].trim();
189
+ }
190
+ }
191
+ }
192
+
193
+ // Fallback for no-space CJK place + duration, e.g. "大阪2日", "京都5天", "宇治半日"
194
+ if (!duration) {
195
+ const compactMatch = content.match(
196
+ /^(.*?)(\d+(?:\.\d+)?\s*(?:日|天)\s*\d+(?:\.\d+)?\s*(?:晚|夜)|\d+(?:\.\d+)?\s*(?:日|天|晚|夜|小时)|半日|半天)$/,
197
+ );
198
+ if (compactMatch && compactMatch[1].trim()) {
199
+ const parsed = parseDurationFragment(compactMatch[2]);
200
+ if (parsed) {
201
+ duration = parsed;
202
+ content = compactMatch[1].trim();
203
+ }
204
+ }
205
+ }
206
+
207
+ const place = content.replace(/[\s·•\-—::,,/]+$/, "").trim();
208
+ if (!place) {
209
+ return {
210
+ place: rawHtml.trim(),
211
+ duration: null,
212
+ note: "",
213
+ };
214
+ }
215
+
216
+ return { place, duration, note };
217
+ }
218
+
219
+ function getRouteGridCols(count) {
220
+ if (count <= 2) return 2;
221
+ if (count === 3 || count === 5 || count === 6 || count === 9) return 3;
222
+ return 4;
223
+ }
224
+
225
+ function buildTravelRouteBlock(listHtml, isEnglishPost) {
226
+ const innerListHtml = listHtml
227
+ .replace(/^<(?:ul|ol)[^>]*>/i, "")
228
+ .replace(/<\/(?:ul|ol)>\s*$/i, "");
229
+
230
+ // Skip lists containing nested lists or block-level media/containers
231
+ if (
232
+ /<(?:ul|ol|img|iframe|table|pre|blockquote|figure)\b/i.test(innerListHtml)
233
+ ) {
234
+ return null;
235
+ }
236
+
237
+ const liMatches = [...innerListHtml.matchAll(/<li[^>]*>([\s\S]*?)<\/li>/gi)];
238
+ if (liMatches.length < 2) {
239
+ return null;
240
+ }
241
+
242
+ const stops = liMatches.map((m) => parseTravelRouteItem(m[1]));
243
+ const stopsWithDuration = stops.filter((s) => s.duration);
244
+ const showBar = stopsWithDuration.length >= 2;
245
+ const cols = getRouteGridCols(stops.length);
246
+
247
+ // Build proportion bar (only segments with parsed durations)
248
+ let barHtml = "";
249
+ let summaryHtml = "";
250
+
251
+ if (showBar) {
252
+ const unitKinds = new Set(stopsWithDuration.map((s) => s.duration.unitKind));
253
+ const segmentsHtml = stops
254
+ .map((stop, idx) => {
255
+ if (!stop.duration) return "";
256
+ const color = TRAVEL_ROUTE_PALETTE[idx % TRAVEL_ROUTE_PALETTE.length];
257
+ let flexWeight = stop.duration.weight;
258
+ if (unitKinds.size > 1 && stop.duration.unitKind === "hour") {
259
+ flexWeight = Math.max(stop.duration.weight / 24, 0.25);
260
+ }
261
+ const tip = escapeAttr(
262
+ `${stripHtmlTags(stop.place)} · ${stop.duration.label}`,
263
+ );
264
+ return `<span class="travel-route-seg" style="flex:${flexWeight};--stop-color:${color};" title="${tip}"></span>`;
265
+ })
266
+ .join("");
267
+
268
+ barHtml = `<div class="travel-route-bar" aria-hidden="true">${segmentsHtml}</div>`;
269
+
270
+ // Build subtle summary when all durations share the same unit kind (day or night)
271
+ if (
272
+ stopsWithDuration.length === stops.length &&
273
+ unitKinds.size === 1 &&
274
+ (unitKinds.has("day") || unitKinds.has("night"))
275
+ ) {
276
+ const total = Number(
277
+ stopsWithDuration
278
+ .reduce((sum, s) => sum + s.duration.weight, 0)
279
+ .toFixed(2),
280
+ );
281
+ const firstUnit = stopsWithDuration[0].duration.unitText;
282
+ const useEnglish = isEnglishPost || /^[a-z]+$/i.test(firstUnit);
283
+ const summaryText = useEnglish
284
+ ? `${stops.length} STOPS · ${total} ${firstUnit.toUpperCase()}`
285
+ : `${stops.length} 站 · 共 ${total} ${firstUnit}`;
286
+ summaryHtml = `<div class="travel-route-summary">${summaryText}</div>`;
287
+ }
288
+ }
289
+
290
+ const itemsHtml = stops
291
+ .map((stop, idx) => {
292
+ const color = TRAVEL_ROUTE_PALETTE[idx % TRAVEL_ROUTE_PALETTE.length];
293
+ const num = String(idx + 1).padStart(2, "0");
294
+ const durationHtml = stop.duration
295
+ ? `<span class="travel-route-days">${stop.duration.label}</span>`
296
+ : "";
297
+ const noteHtml = stop.note
298
+ ? `<span class="travel-route-note">${stop.note}</span>`
299
+ : "";
300
+
301
+ return `<li class="travel-route-item" style="--stop-color:${color};"><div class="travel-route-item-top"><span class="travel-route-index">${num}</span><span class="travel-route-dot" aria-hidden="true"></span></div><div class="travel-route-place">${stop.place}</div>${durationHtml}${noteHtml}</li>`;
302
+ })
303
+ .join("");
304
+
305
+ return `<div class="travel-route-block${showBar ? " has-bar" : ""}" style="--route-cols:${cols};">${summaryHtml}${barHtml}<ul class="travel-route-grid">${itemsHtml}</ul></div>`;
306
+ }
307
+
308
+ function processTravelRoute(content, data) {
309
+ if (!content || !TRAVEL_SERIES_NAMES.includes(data?.series)) {
310
+ return content;
311
+ }
312
+
313
+ const isEnglishPost =
314
+ data?.series === "Travel" ||
315
+ String(data?.language || data?.lang || "").startsWith("en");
316
+
317
+ return content.replace(
318
+ /(<h([23])[^>]*>([\s\S]*?)<\/h\2>)((?:\s|<!--[\s\S]*?-->|<div\s+id="gitalk-initiator"[^>]*><\/div>)*)(<(ul|ol)[^>]*>[\s\S]*?<\/\6>)/gi,
319
+ (fullMatch, headingHtml, _level, headingInner, betweenHtml, listHtml) => {
320
+ const headingText = stripHeadingText(headingInner);
321
+ if (!TRAVEL_ROUTE_HEADING_REGEX.test(headingText)) {
322
+ return fullMatch;
323
+ }
324
+ const routeBlock = buildTravelRouteBlock(listHtml, isEnglishPost);
325
+ if (!routeBlock) {
326
+ return fullMatch;
327
+ }
328
+ return `${headingHtml}${betweenHtml}${routeBlock}`;
329
+ },
330
+ );
331
+ }
332
+
1
333
  function processCodeBlock(content) {
2
334
  return content.replace(
3
335
  /<\/figure>/g,
@@ -32,6 +364,7 @@ hexo.extend.filter.register(
32
364
  "after_post_render",
33
365
  function (data) {
34
366
  data.content = processCodeBlock(data.content);
367
+ data.content = processTravelRoute(data.content, data);
35
368
  data.content = process.call(this, data.content);
36
369
  return data;
37
370
  },
@@ -111,7 +111,7 @@ module.exports = function (hexo) {
111
111
  opacity: 1;
112
112
  }
113
113
  .lazyload-wrap .error-wrap{
114
- background-color: #f5f5f5;
114
+ background-color: #f7f6f2;
115
115
  opacity: 1;
116
116
  display: flex;
117
117
  flex-direction: column;
@@ -130,24 +130,28 @@ module.exports = function (hexo) {
130
130
  padding-top: 26.79640719%;
131
131
  }
132
132
  .lazyload-wrap .error-wrap .retry-btn{
133
- margin-top: 2em;
134
- background-image: linear-gradient(#f7f8fa ,#e7e9ec);
135
- border-color: #adb1b8 #a2a6ac #8d9096;
136
- border-style: solid;
137
- border-width: 1px;
138
- border-radius: 3px;
139
- box-shadow: rgba(255,255,255,.6) 0 1px 0 inset;
133
+ margin-top: 1.5em;
134
+ background-color: #ffffff;
135
+ border: 1px solid rgba(34, 33, 31, 0.18);
136
+ border-radius: 4px;
140
137
  box-sizing: border-box;
141
- color: #0f1111;
142
- display: inline-block;
143
- font-family: "Amazon Ember",Arial,sans-serif;
144
- font-size: 14px;
145
- height: 29px;
138
+ color: #22211f;
139
+ cursor: pointer;
140
+ display: inline-flex;
141
+ align-items: center;
142
+ justify-content: center;
143
+ font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
146
144
  font-size: 13px;
147
- outline: 0;
148
- overflow: hidden;
149
- padding: 0 11px;
145
+ font-weight: 500;
146
+ height: 32px;
147
+ padding: 0 14px;
150
148
  text-align: center;
149
+ transition: border-color 180ms cubic-bezier(0.22, 1, 0.36, 1), color 180ms cubic-bezier(0.22, 1, 0.36, 1), background-color 180ms cubic-bezier(0.22, 1, 0.36, 1);
150
+ }
151
+ .lazyload-wrap .error-wrap .retry-btn:hover{
152
+ border-color: rgba(168, 69, 46, 0.35);
153
+ color: #a8452e;
154
+ background-color: rgba(168, 69, 46, 0.06);
151
155
  }`;
152
156
 
153
157
  let settingsContent = `<script>var $lazyload = {