hexo-theme-hipaper-keyboarddaily 1.7.0 → 1.7.1

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/_config.yml CHANGED
@@ -43,6 +43,8 @@ random_thumb: true
43
43
  # 两者互斥,同时为 true 时只生效 fancybox
44
44
  fancybox: false
45
45
  photo_swipe: true
46
+ # img_grid: 正文 {% imggrid %} 九宫格图片组样式(1 张单列、2/4 张两列、其余三列)
47
+ img_grid: true
46
48
 
47
49
 
48
50
  # Sidebar
@@ -73,4 +73,8 @@
73
73
  <%- css('css/img-zoom.min') %>
74
74
  <% } %>
75
75
 
76
+ <% if (theme.img_grid){ %>
77
+ <%- css('css/img-grid.min') %>
78
+ <% } %>
79
+
76
80
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-hipaper-keyboarddaily",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Bugfix for A newspaper theme for Hexo.",
5
5
  "author": "iTimeTraveler, bugfix by keyboarddaily",
6
6
  "repository": {
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 九宫格图片组标签
3
+ *
4
+ * {% imggrid %}
5
+ * http://example.com/1.jpg
6
+ * http://example.com/2.jpg
7
+ * ...
8
+ * {% endimggrid %}
9
+ *
10
+ * 可选参数 contain:整组图片改为完整显示(不裁切),适合截图/长图。
11
+ * 列数由图片数量决定(见 css/img-grid.min.css):1 张单列、2/4 张两列、其余三列。
12
+ */
13
+ hexo.extend.tag.register(
14
+ 'imggrid',
15
+ function (args, content) {
16
+ var root = hexo.config.root || '/';
17
+ var contain = args.indexOf('contain') > -1;
18
+
19
+ var urls = String(content || '')
20
+ .split('\n')
21
+ .map(function (line) {
22
+ return line.trim();
23
+ })
24
+ .filter(function (line) {
25
+ return line && line.indexOf('#') !== 0;
26
+ });
27
+
28
+ if (!urls.length) return '';
29
+
30
+ var escape = function (str) {
31
+ return str
32
+ .replace(/&/g, '&amp;')
33
+ .replace(/"/g, '&quot;')
34
+ .replace(/</g, '&lt;')
35
+ .replace(/>/g, '&gt;');
36
+ };
37
+
38
+ var items = urls
39
+ .map(function (url) {
40
+ var src = url;
41
+ if (!/^([a-z][a-z0-9+.-]*:)?\/\//i.test(src)) {
42
+ src = root + src.replace(/^\//, '');
43
+ }
44
+ src = escape(src);
45
+ return '<a class="fancybox" href="' + src + '"><img src="' + src + '" alt=""></a>';
46
+ })
47
+ .join('');
48
+
49
+ return (
50
+ '<div class="img-grid" data-count="' +
51
+ urls.length +
52
+ '"' +
53
+ (contain ? ' data-fit="contain"' : '') +
54
+ '>' +
55
+ items +
56
+ '</div>'
57
+ );
58
+ },
59
+ { ends: true }
60
+ );
@@ -0,0 +1,55 @@
1
+ /* 微博九宫格图片组(配合 {% imggrid %} 标签使用)
2
+ 列数按 data-count 决定:1 张单列不裁切、2/4 张两列、其余三列 */
3
+ .article-entry .img-grid {
4
+ display: grid;
5
+ grid-template-columns: repeat(3, 1fr);
6
+ gap: 4px;
7
+ margin: 1em 0;
8
+ }
9
+
10
+ .article-entry .img-grid[data-count="2"],
11
+ .article-entry .img-grid[data-count="4"] {
12
+ grid-template-columns: repeat(2, 1fr);
13
+ }
14
+
15
+ .article-entry .img-grid[data-count="1"] {
16
+ grid-template-columns: 1fr;
17
+ }
18
+
19
+ .article-entry .img-grid > a.fancybox {
20
+ display: block;
21
+ margin: 0;
22
+ aspect-ratio: 1 / 1;
23
+ overflow: hidden;
24
+ background: #f2f2f2;
25
+ }
26
+
27
+ .article-entry .img-grid img {
28
+ width: 100%;
29
+ height: 100%;
30
+ object-fit: cover;
31
+ display: block;
32
+ margin: 0;
33
+ }
34
+
35
+ /* 单图与 contain 模式保留完整画面 */
36
+ .article-entry .img-grid[data-count="1"] > a.fancybox {
37
+ aspect-ratio: auto;
38
+ }
39
+
40
+ .article-entry .img-grid[data-count="1"] img,
41
+ .article-entry .img-grid[data-fit="contain"] img {
42
+ height: auto;
43
+ object-fit: contain;
44
+ }
45
+
46
+ /* 主题脚本按 alt 插入的 .caption 会破坏格子对齐 */
47
+ .article-entry .img-grid .caption {
48
+ display: none;
49
+ }
50
+
51
+ @media (max-width: 600px) {
52
+ .article-entry .img-grid {
53
+ gap: 2px;
54
+ }
55
+ }