-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.xml
1615 lines (1615 loc) · 198 KB
/
index.xml
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>菠菜眾長</title><link>https://lruihao.cn/</link><description>Hugo FixIt 作者,喜欢瞎折腾、造轮子、写东西,分享一些前端开发中的所见、所闻、所思。</description><generator>Hugo 0.139.4 & FixIt v0.3.17-637c4641</generator><language>zh-CN</language><managingEditor>1024@lruihao.cn (Lruihao)</managingEditor><webMaster>1024@lruihao.cn (Lruihao)</webMaster><copyright>本站内容采用 CC BY-NC-SA 4.0 国际许可协议。</copyright><lastBuildDate>Thu, 19 Dec 2024 09:23:49 +0000</lastBuildDate><atom:link href="https://lruihao.cn/index.xml" rel="self" type="application/rss+xml"/><item><title>震惊!CSS 竟然能获取视口尺寸?</title><link>https://lruihao.cn/posts/css-viewport/</link><pubDate>Fri, 06 Dec 2024 10:32:22 +0800</pubDate><author>1024@lruihao.cn (Lruihao)</author><guid>https://lruihao.cn/posts/css-viewport/</guid><category domain="https://lruihao.cn/categories/css/">CSS</category><description><p>在这篇文章中,我们将探讨如何使用 CSS 获取视口尺寸,并展示一个简单的实现示例。</p>
<h2 id="效果" class="heading-element"><span>1 效果</span>
<a href="#%e6%95%88%e6%9e%9c" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><!-- markdownlint-disable-next-line no-inline-html -->
<blockquote class="blockquote-center"><p><span class="viewport-size"></span></p>
</blockquote>
<p>调整浏览器窗口大小,你会发现视口的宽度和高度会实时更新(旧浏览器可能不支持)。</p>
<blockquote>
<p>重要的是,这个效果是纯 CSS 实现的,不需要 JavaScript,真的震惊了!</p>
</blockquote>
<h2 id="实现原理" class="heading-element"><span>2 实现原理</span>
<a href="#%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><ol>
<li>定义 CSS 自定义属性(<code>@property</code>) <code>--vw</code> 和 <code>--vh</code>,分别表示视口的宽度和高度。</li>
<li>使用 <code>tan()</code> 和 <code>atan2()</code> 函数计算视口的宽度和高度。</li>
<li>使用 <code>counter</code> 和 <code>counter-reset</code> 属性将计算结果显示在页面上。</li>
</ol>
<h3 id="计算视口尺寸" class="heading-element"><span>2.1 计算视口尺寸</span>
<a href="#%e8%ae%a1%e7%ae%97%e8%a7%86%e5%8f%a3%e5%b0%ba%e5%af%b8" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>我们可以使用 <code>vw</code> 和 <code>vh</code> 获取浏览器视口尺寸,但是这是相对单位,所以需要转换为 <code>px</code> 才行。我们先利用自定义属性把相对单位转成 <code>px</code>,然后最关键的一步是巧妙地利用了三角函数 $tan(arctan(a)) = a$ 来实现这个转换。</p>
<h3 id="三角函数" class="heading-element"><span>2.2 三角函数</span>
<a href="#%e4%b8%89%e8%a7%92%e5%87%bd%e6%95%b0" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>在三角函数中,$tan(θ)$ 表示一个角度 $θ$ 的正切值,它等于对边(opposite)与邻边(adjacent)的比值。反过来,$arctan(a)$ 表示一个数值 $a$ 的反正切值,它返回一个角度 $θ$,使得 $tan(θ) = a$,因此得到公式:</p>
<p>$$ tan(arctan(a)) = a $$</p>
<p>CSS 中的 <code>tan()</code> 和 <code>atan2()</code> 函数可以用来计算正切值和反正切值。</p>
<p><code>tan()</code> 函数的语法如下:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-css" data-lang="css"><span class="line"><span class="cl"><span class="c">/* 单个 &lt;angle&gt; 值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">45deg</span><span class="o">));</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">0</span><span class="p">.</span><span class="nc">125turn</span><span class="o">));</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">0</span><span class="p">.</span><span class="nc">785398163rad</span><span class="o">));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">/* 单个 &lt;number&gt; 值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">0</span><span class="p">.</span><span class="nc">5773502</span><span class="o">));</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">1</span><span class="p">.</span><span class="nc">732</span> <span class="err">–</span> <span class="nt">1</span><span class="o">));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">/* 其他值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">pi</span> <span class="o">/</span> <span class="nt">3</span><span class="o">));</span>
</span></span><span class="line"><span class="cl"><span class="nt">width</span><span class="o">:</span> <span class="nt">calc</span><span class="o">(</span><span class="nt">100px</span> <span class="o">*</span> <span class="nt">tan</span><span class="o">(</span><span class="nt">e</span><span class="o">));</span></span></span></code></pre></td></tr></table>
</div>
</div><p><code>atan2()</code> 函数接受两个参数,对于所给两值 <code>x</code> 和 <code>y</code>,函数 <code>atan2(y, x)</code> 计算并返回正半横轴与从原点到点 <code>(x, y)</code> 的射线的夹角。函数的语法如下:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-css" data-lang="css"><span class="line"><span class="cl"><span class="c">/* 两个 &lt;number&gt; 值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">atan2</span><span class="o">(</span><span class="nt">3</span><span class="o">,</span> <span class="nt">2</span><span class="o">));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">/* 两个 &lt;dimension&gt; 值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">atan2</span><span class="o">(</span><span class="nt">1rem</span><span class="o">,</span> <span class="nt">-0</span><span class="p">.</span><span class="nc">5rem</span><span class="o">));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">/* 两个 &lt;percentage&gt; 值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">atan2</span><span class="o">(</span><span class="nt">20</span><span class="o">%,</span> <span class="nt">-30</span><span class="o">%));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c">/* 其他值 */</span>
</span></span><span class="line"><span class="cl"><span class="nt">transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">atan2</span><span class="o">(</span><span class="nt">pi</span><span class="o">,</span> <span class="nt">45</span><span class="o">));</span>
</span></span><span class="line"><span class="cl"><span class="nt">transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">atan2</span><span class="o">(</span><span class="nt">e</span><span class="o">,</span> <span class="nt">30</span><span class="o">));</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="代码示例" class="heading-element"><span>3 代码示例</span>
<a href="#%e4%bb%a3%e7%a0%81%e7%a4%ba%e4%be%8b" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>以下是完整的 HTML 和 CSS 代码,你也可以在我的 <a href="https://lruihao.github.io/html-demo/css-viewport.html"target="_blank" rel="external nofollow noopener noreferrer">html-demo<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 中查看。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl"><span class="cp">&lt;!DOCTYPE html&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">html</span> <span class="na">lang</span><span class="o">=</span><span class="s">&#34;en&#34;</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"> <span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&#34;UTF-8&#34;</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"> <span class="p">&lt;</span><span class="nt">meta</span> <span class="na">name</span><span class="o">=</span><span class="s">&#34;viewport&#34;</span> <span class="na">content</span><span class="o">=</span><span class="s">&#34;width=device-width, initial-scale=1.0&#34;</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"> <span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span>CSS Viewport Size<span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"> <span class="p">&lt;</span><span class="nt">style</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"> <span class="c">/* 自定义属性是为了把 vw 和 vh 转成 px */</span>
</span></span><span class="line"><span class="cl"> <span class="p">@</span><span class="k">property</span> <span class="nt">--vw</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="nt">syntax</span><span class="o">:</span> <span class="s1">&#39;&lt;length&gt;&#39;</span><span class="o">;</span>
</span></span><span class="line"><span class="cl"> <span class="nt">inherits</span><span class="o">:</span> <span class="nt">true</span><span class="o">;</span>
</span></span><span class="line"><span class="cl"> <span class="nt">initial-value</span><span class="o">:</span> <span class="nt">100vw</span><span class="o">;</span>
</span></span><span class="line"><span class="cl"> <span class="p">}</span>
</span></span><span class="line"><span class="cl"> <span class="p">@</span><span class="k">property</span> <span class="nt">--vh</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="nt">syntax</span><span class="o">:</span> <span class="s1">&#39;&lt;length&gt;&#39;</span><span class="o">;</span>
</span></span><span class="line"><span class="cl"> <span class="nt">inherits</span><span class="o">:</span> <span class="nt">true</span><span class="o">;</span>
</span></span><span class="line"><span class="cl"> <span class="nt">initial-value</span><span class="o">:</span> <span class="nt">100vh</span><span class="o">;</span>
</span></span><span class="line"><span class="cl"> <span class="p">}</span>
</span></span><span class="line"><span class="cl"> <span class="c">/*
</span></span></span><span class="line"><span class="cl"><span class="c"> 核心公式:
</span></span></span><span class="line"><span class="cl"><span class="c"> tan(θ) = opposite / adjacent
</span></span></span><span class="line"><span class="cl"><span class="c"> θ = arctan(opposite / adjacent)
</span></span></span><span class="line"><span class="cl"><span class="c"> tan(arctan(a)) = a
</span></span></span><span class="line"><span class="cl"><span class="c"> */</span>
</span></span><span class="line"><span class="cl"> <span class="p">:</span><span class="nd">root</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="nv">--width</span><span class="p">:</span> <span class="nf">tan</span><span class="p">(</span><span class="nf">atan2</span><span class="p">(</span><span class="nf">var</span><span class="p">(</span><span class="o">--</span><span class="n">vw</span><span class="p">),</span> <span class="mi">1</span><span class="kt">px</span><span class="p">));</span>
</span></span><span class="line"><span class="cl"> <span class="nv">--height</span><span class="p">:</span> <span class="nf">tan</span><span class="p">(</span><span class="nf">atan2</span><span class="p">(</span><span class="nf">var</span><span class="p">(</span><span class="o">--</span><span class="n">vh</span><span class="p">),</span> <span class="mi">1</span><span class="kt">px</span><span class="p">));</span>
</span></span><span class="line"><span class="cl"> <span class="p">}</span>
</span></span><span class="line"><span class="cl"> <span class="nt">body</span><span class="p">::</span><span class="nd">before</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="k">content</span><span class="p">:</span> <span class="nb">counter</span><span class="p">(</span><span class="n">width</span><span class="p">)</span> <span class="s1">&#39; X &#39;</span> <span class="nb">counter</span><span class="p">(</span><span class="n">height</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"> <span class="k">counter-reset</span><span class="p">:</span> <span class="k">width</span> <span class="nf">var</span><span class="p">(</span><span class="o">--</span><span class="n">width</span><span class="p">)</span> <span class="k">height</span> <span class="nf">var</span><span class="p">(</span><span class="o">--</span><span class="n">height</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"> <span class="k">display</span><span class="p">:</span> <span class="kc">block</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">font-size</span><span class="p">:</span> <span class="mi">150</span><span class="kt">px</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">font-weight</span><span class="p">:</span> <span class="mi">900</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">position</span><span class="p">:</span> <span class="kc">fixed</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">width</span><span class="p">:</span> <span class="n">fit-content</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">height</span><span class="p">:</span> <span class="n">fit-content</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="n">inset</span><span class="p">:</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="k">margin</span><span class="p">:</span> <span class="kc">auto</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"> <span class="p">}</span>
</span></span><span class="line"><span class="cl"> <span class="p">&lt;/</span><span class="nt">style</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="兼容性" class="heading-element"><span>4 兼容性</span>
<a href="#%e5%85%bc%e5%ae%b9%e6%80%a7" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>主要是 <code>counter</code> 和 <code>counter-reset</code> 属性的兼容性问题,看漫山红遍,层林尽染。</p>
<p class="ciu-embed" data-feature="css-at-counter-style" data-past="2" data-future="1" data-origin="https://caniuse.lruihao.cn" data-observer="true" data-theme=""></p>
<p class="ciu-embed" data-feature="mdn-css_properties_counter-reset_reset_does_not_affect_siblings" data-past="2" data-future="1" data-origin="https://caniuse.lruihao.cn" data-observer="true" data-theme=""></p></description></item><item><title>🌐 A component for website automatic translation.</title><link>https://lruihao.cn/projects/hugo-fixit/cmpt-translate/</link><pubDate>Mon, 02 Dec 2024 07:29:57 +0000</pubDate><guid>https://lruihao.cn/projects/hugo-fixit/cmpt-translate/</guid><category domain="https://lruihao.cn/categories/github/">GitHub</category><description><!-- markdownlint-disable-file MD033 MD041 -->
<h1 align="center">Auto Translate | FixIt</h1>
<p><img loading="lazy" src="https://github.com/user-attachments/assets/10ab49bb-973f-4630-9a79-9639783bab06" alt="auto-translate" srcset="https://github.com/user-attachments/assets/10ab49bb-973f-4630-9a79-9639783bab06?size=small, https://github.com/user-attachments/assets/10ab49bb-973f-4630-9a79-9639783bab06?size=medium 1.5x, https://github.com/user-attachments/assets/10ab49bb-973f-4630-9a79-9639783bab06?size=large 2x" data-title="auto-translate" class="suffix-invalid suffix-invalid__small suffix-invalid__large" style="background: url(/images/loading.min.svg) no-repeat center;" onload="this.title=this.dataset.title;for(const i of ['style', 'data-title','onerror','onload']){this.removeAttribute(i);}this.dataset.lazyloaded='';" onerror="this.title=this.dataset.title;for(const i of ['style', 'data-title','onerror','onload']){this.removeAttribute(i);}"/></p>
<div align="center" class="ignore">
<p>一个基于 <a href="https://github.com/xnx3/translate">translate.js</a> 实现网站自动翻译的组件。</p>
简体中文 |
<a href="https://fixit.lruihao.cn/zh-cn/ecosystem/hugo-fixit/cmpt-translate/?lang=chinese_traditional">繁體中文</a> |
<a href="https://raw.githubusercontent.com/hugo-fixit/cmpt-translate/refs/heads/main/README.en.md">English</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=french">Français</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=russian">Русский язык</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=spanish">Español</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=hindi">हिन्दी</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=german">deutsch</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=korean">한국어</a> |
<a href="https://fixit.lruihao.cn/ecosystem/hugo-fixit/cmpt-translate/?lang=japanese">しろうと</a>
</div>
<h2 id="demo" class="heading-element"><span>Demo</span>
<a href="#demo" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>无论原站点是多语言还是单语言,都可以通过此组件额外增加自动翻译功能。</p>
<ul>
<li>多语言 Hugo 站点:<a href="https://fixit.lruihao.cn"target="_blank" rel="external nofollow noopener noreferrer">fixit.lruihao.cn<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
<li>单语言 Hugo 站点:<a href="https://lruihao.cn"target="_blank" rel="external nofollow noopener noreferrer">lruihao.cn<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
</ul>
<p>在网站右上角切换配置的翻译语言,或者在 URL 中添加 <code>?lang=</code> 参数指定任意<a href="https://api.translate.zvo.cn/language.json"target="_blank" rel="external nofollow noopener noreferrer">支持的翻译语言<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>。例如:<code>?lang=korean</code>。</p>
<h2 id="特性" class="heading-element"><span>特性</span>
<a href="#%e7%89%b9%e6%80%a7" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><blockquote>
<p>每日翻译字符 <strong>200 万</strong>!<br>
<em>无语言配置文件、无 API Key、对 SEO 友好!</em></p>
</blockquote>
<ul>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持整页自动翻译</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持指定翻译语言</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持可选翻译服务</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持忽略翻译元素</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持忽略选择器</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持忽略关键词翻译</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持检测本地语言</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持自定义翻译术语</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持 CDN</li>
<li data-task="x" title="已完成"><i class="checkbox-icon fa-fw fa-solid fa-check-square" aria-hidden="true"></i>支持<a href="#enterprise">企业级翻译通道</a> *</li>
</ul>
<h2 id="要求" class="heading-element"><span>要求</span>
<a href="#%e8%a6%81%e6%b1%82" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><ul>
<li>Hugo v0.139.0 或更高版本。</li>
<li>FixIt v0.3.16 或更高版本。</li>
</ul>
<h2 id="安装组件" class="heading-element"><span>安装组件</span>
<a href="#%e5%ae%89%e8%a3%85%e7%bb%84%e4%bb%b6" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>安装方式与 <a href="https://fixit.lruihao.cn/zh-cn/documentation/installation/"target="_blank" rel="external nofollow noopener noreferrer">安装主题<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 相同,有多种安装方式,任选一种即可,这里介绍两种主流方式。</p>
<h3 id="作为-hugo-模块安装" class="heading-element"><span>作为 Hugo 模块安装</span>
<a href="#%e4%bd%9c%e4%b8%ba-hugo-%e6%a8%a1%e5%9d%97%e5%ae%89%e8%a3%85" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>首先确保你的项目本身是一个 <a href="https://gohugo.io/hugo-modules/use-modules/#initialize-a-new-module"target="_blank" rel="external nofollow noopener noreferrer">Hugo 模块<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>。</p>
<p>然后将此主题组件添加到你的 <code>hugo.toml</code> 配置文件中:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">module</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[[</span><span class="nx">module</span><span class="p">.</span><span class="nx">imports</span><span class="p">]]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">path</span> <span class="p">=</span> <span class="s2">&#34;github.com/hugo-fixit/FixIt&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="p">[[</span><span class="nx">module</span><span class="p">.</span><span class="nx">imports</span><span class="p">]]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">path</span> <span class="p">=</span> <span class="s2">&#34;github.com/hugo-fixit/cmpt-translate&#34;</span></span></span></code></pre></td></tr></table>
</div>
</div><p>在 Hugo 的第一次启动时,它将下载所需的文件。</p>
<p>要更新到模块的最新版本,请运行:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">hugo mod get -u
</span></span><span class="line"><span class="cl">hugo mod tidy</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="作为-git-子模块安装" class="heading-element"><span>作为 Git 子模块安装</span>
<a href="#%e4%bd%9c%e4%b8%ba-git-%e5%ad%90%e6%a8%a1%e5%9d%97%e5%ae%89%e8%a3%85" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>将 <a href="https://github.com/hugo-fixit"target="_blank" rel="external nofollow noopener noreferrer">FixIt<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 和此 git 存储库克隆到你的主题文件夹中,并将其作为网站目录的子模块添加。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git submodule add https://github.com/hugo-fixit/FixIt.git themes/FixIt
</span></span><span class="line"><span class="cl">git submodule add https://github.com/hugo-fixit/cmpt-translate.git themes/cmpt-translate</span></span></code></pre></td></tr></table>
</div>
</div><p>接下来编辑项目的 <code>hugo.toml</code> 并将此主题组件添加到你的主题中:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="nx">theme</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;FixIt&#34;</span><span class="p">,</span> <span class="s2">&#34;cmpt-translate&#34;</span><span class="p">]</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="配置" class="heading-element"><span>配置</span>
<a href="#%e9%85%8d%e7%bd%ae" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>为了通过 FixIt 主题在 <code>layouts/partials/custom.html</code> 文件中开放的 <a href="https://fixit.lruihao.cn/references/blocks/"target="_blank" rel="external nofollow noopener noreferrer">自定义块<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 将 <code>cmpt-translate.html</code> 注入到 <code>custom-assets</code> 中,你需要填写以下必要配置:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">params</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">params</span><span class="p">.</span><span class="nx">customPartials</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">head</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">menuDesktop</span> <span class="p">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl"> <span class="s2">&#34;inject/translate-menu-desktop.html&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"> <span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">menuMobile</span> <span class="p">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl"> <span class="s2">&#34;inject/translate-menu-mobile.html&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"> <span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">profile</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">aside</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">comment</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">footer</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">widgets</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">assets</span> <span class="p">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl"> <span class="s2">&#34;inject/cmpt-translate.html&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"> <span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">postFooterBefore</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">postFooterAfter</span> <span class="p">=</span> <span class="p">[]</span></span></span></code></pre></td></tr></table>
</div>
</div><p>另外,你还可以通过以下配置来自定义翻译的语言:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">languages</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">languages</span><span class="p">.</span><span class="nx">zh-cn</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">languageCode</span> <span class="p">=</span> <span class="s2">&#34;zh-CN&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="nx">languageName</span> <span class="p">=</span> <span class="s2">&#34;简体中文&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">params</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">params</span><span class="p">.</span><span class="nx">autoTranslate</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">enable</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl"> <span class="nx">service</span> <span class="p">=</span> <span class="s1">&#39;client.edge&#39;</span>
</span></span><span class="line"><span class="cl"> <span class="nx">languages</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">ignoreID</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">ignoreClass</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">ignoreTag</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">detectLocalLanguage</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl"> <span class="nx">cdn</span> <span class="p">=</span> <span class="s2">&#34;&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="nx">enterprise</span> <span class="p">=</span> <span class="kc">false</span></span></span></code></pre></td></tr></table>
</div>
</div><ul>
<li><code>enable</code>:是否启用自动翻译。</li>
<li><code>service</code>:翻译服务提供商,可选值为 <code>client.edge</code> 和 <code>translate.service</code>,详见:<a href="https://translate.zvo.cn/43086.html"target="_blank" rel="external nofollow noopener noreferrer">翻译服务提供商<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>。</li>
<li><code>languages</code>:要翻译到的语言 ID 列表,例如 <code>[&quot;english&quot;, &quot;chinese_simplified&quot;, &quot;chinese_traditional&quot;, ...]</code>,详见:<a href="https://api.translate.zvo.cn/language.json"target="_blank" rel="external nofollow noopener noreferrer">完整语言列表<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>。</li>
<li><code>ignoreID</code>:需要忽略翻译的元素 ID,例如 <code>[&quot;comment&quot;, ...]</code>。</li>
<li><code>ignoreClass</code>:需要忽略翻译的类名,例如 <code>[&quot;post-category&quot;, ...]</code>。</li>
<li><code>ignoreTag</code>:需要忽略翻译的标签,例如 <code>[&quot;title&quot;, ...]</code>。</li>
<li><code>ignoreText</code>:需要忽略翻译的文本,例如 <code>[&quot;FixIt&quot;, &quot;Lruihao&quot;, ...]</code>。</li>
<li><code>detectLocalLanguage</code>:是否检测本地语言。</li>
<li><code>cdn</code>:translate.js 的 CDN,例如 <code>https://cdn.jsdelivr.net/npm/i18n-jsautotranslate@latest</code>。</li>
<li><code>enterprise</code>:是否启用<a href="#enterprise">企业级翻译通道</a>。</li>
</ul>
<div class="alert alert-note"><p class="alert-title"><svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M0 8a8 8 0 1116 0A8 8 0 010 8zm8-6.5a6.5 6.5.0 100 13 6.5 6.5.0 000-13zM6.5 7.75A.75.75.0 017.25 7h1a.75.75.0 01.75.75v2.75h.25a.75.75.0 010 1.5h-2a.75.75.0 010-1.5h.25v-2h-.25a.75.75.0 01-.75-.75zM8 6a1 1 0 110-2 1 1 0 010 2z"/></svg>注意</p><p>为了避免翻译语言获取失败,即使你的站点本身是单语言的,也需要配置 <code>languageCode</code> 和 <code>languageName</code>,例如:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">languages</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">languages</span><span class="p">.</span><span class="nx">zh-cn</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">languageCode</span> <span class="p">=</span> <span class="s2">&#34;zh-CN&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="nx">languageName</span> <span class="p">=</span> <span class="s2">&#34;简体中文&#34;</span></span></span></code></pre></td></tr></table>
</div>
</div></div><h2 id="front-matter" class="heading-element"><span>Front Matter</span>
<a href="#front-matter" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">autoTranslate</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">local</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;&#39;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">fromLanguages</span><span class="p">:</span><span class="w"> </span><span class="p">[]</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">onlyLocalLang</span><span class="p">:</span><span class="w"> </span><span class="kc">false</span></span></span></code></pre></td></tr></table>
</div>
</div><ul>
<li>
<p><code>local</code>: <code>String</code> 用于指定当前页面的本地语言,例如 <code>local: english</code>。</p>
<p>默认本地语言同 Hugo 站点配置相同,如果某个页面实际语言与站点配置不同,可以通过 <code>local</code> 参数指定。</p>
</li>
<li>
<p><code>fromLanguages</code>: <code>Array</code> 类型,用于指定当前页面内容中出现的语种是否需要翻译。</p>
<p>例如:网页本身是中文,但是内容中还有其他语言,你可以指定需要翻译的语种,例如:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">fromLanguages</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">chinese_simplified</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span>- <span class="l">chinese_traditional</span></span></span></code></pre></td></tr></table>
</div>
</div></li>
<li>
<p><code>onlyLocalLang</code>: <code>Boolean</code> 类型,用于指定是否只翻译当前页面本地语言,默认为 <code>false</code>。</p>
<p>例如:网页本身是中文,但是内容中其他语言的摘要引用,设置 <code>onlyLocalLang: true</code> 可以只翻译中文。</p>
</li>
</ul>
<h2 id="自定义翻译术语" class="heading-element"><span>自定义翻译术语</span>
<a href="#%e8%87%aa%e5%ae%9a%e4%b9%89%e7%bf%bb%e8%af%91%e6%9c%af%e8%af%ad" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>在你的项目目录 <code>data</code> 文件夹下创建 <code>nomenclature.yml</code> 文件,然后添加自定义翻译术语,例如:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl">- <span class="nt">from</span><span class="p">:</span><span class="w"> </span><span class="l">english</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">to</span><span class="p">:</span><span class="w"> </span><span class="l">chinese_simplified</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">properties</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">Hello</span><span class="p">:</span><span class="w"> </span><span class="l">你好</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">World</span><span class="p">:</span><span class="w"> </span><span class="l">世界</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span>- <span class="nt">from</span><span class="p">:</span><span class="w"> </span><span class="l">english</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">to</span><span class="p">:</span><span class="w"> </span><span class="l">french</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">properties</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">Hello</span><span class="p">:</span><span class="w"> </span><span class="l">Bonjour</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="nt">World</span><span class="p">:</span><span class="w"> </span><span class="l">Monde</span></span></span></code></pre></td></tr></table>
</div>
</div><!-- markdownlint-disable-next-line MD033 -->
<h2 id="企业级翻译通道-a-identerprisea" class="heading-element"><span>企业级翻译通道 <a id="enterprise"></a></span>
<a href="#%e4%bc%81%e4%b8%9a%e7%ba%a7%e7%bf%bb%e8%af%91%e9%80%9a%e9%81%93-a-identerprisea" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><blockquote>
<p>企业级稳定翻译通道,仅针对<strong>付费用户</strong>开放。<br>
<strong>体验额度</strong>:每天有 5 万字符的体验额度,超出部分将不再翻译!</p>
</blockquote>
<p>在 FixIt 里启用企业级翻译通道,设置 <code>params.autoTranslate.enterprise</code> 为 <code>true</code> 即可,<a href="https://translate.zvo.cn/4087.html"target="_blank" rel="external nofollow noopener noreferrer">企业级翻译通道<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>相对于普通翻译通道有以下优势:</p>
<table>
<thead>
<tr>
<th style="text-align: left">服务</th>
<th style="text-align: left">开源翻译通道</th>
<th style="text-align: left">企业级翻译通道</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">服务端缓存层数</td>
<td style="text-align: left">1 层 (文件式缓存)</td>
<td style="text-align: left">1 层 (内存 + 文件式缓存)</td>
</tr>
<tr>
<td style="text-align: left">翻译响应速度</td>
<td style="text-align: left">1.5~5 秒</td>
<td style="text-align: left">0.8~1.5 秒</td>
</tr>
<tr>
<td style="text-align: left">翻译服务器</td>
<td style="text-align: left">1 台</td>
<td style="text-align: left">&gt;=3 台</td>
</tr>
<tr>
<td style="text-align: left">网络节点</td>
<td style="text-align: left">2 个</td>
<td style="text-align: left">&gt;=4 个</td>
</tr>
<tr>
<td style="text-align: left">翻译通道</td>
<td style="text-align: left">手动设置</td>
<td style="text-align: left">自动匹配最优</td>
</tr>
<tr>
<td style="text-align: left">国内缓存节点</td>
<td style="text-align: left">无</td>
<td style="text-align: left">有</td>
</tr>
<tr>
<td style="text-align: left">每日翻译字符</td>
<td style="text-align: left">200 万</td>
<td style="text-align: left">5000 万</td>
</tr>
</tbody>
</table>
<h3 id="赞助费用" class="heading-element"><span>赞助费用</span>
<a href="#%e8%b5%9e%e5%8a%a9%e8%b4%b9%e7%94%a8" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>考虑到 FixIt 生态受众群体大多为个人用户,因此我(<a href="https://github.com"target="_blank" rel="external nofollow noopener noreferrer">@Lruihao<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>)以<strong>个人名义</strong>拿出赞助收入进行补贴。</p>
<div class="alert alert-tip"><p class="alert-title"><svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M8 1.5c-2.363.0-4 1.69-4 3.75.0.984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75.0 01-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456.0 00-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863.0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751.0 01-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304.0-2.06-1.637-3.75-4-3.75zM5.75 12h4.5a.75.75.0 010 1.5h-4.5a.75.75.0 010-1.5zM6 15.25a.75.75.0 01.75-.75h2.5a.75.75.0 010 1.5h-2.5A.75.75.0 016 15.25z"/></svg>提示</p><p><strong>FixIt 项目补贴价</strong>:<strong>¥10</strong> <del><em>¥50</em></del> / 域名 / 月<br>
<em>到期自动禁用,需要重新赞助续费!</em></p>
</div><p>符合以下性质的可以免费联系我开通企业级翻译通道:</p>
<ul>
<li><a href="https://github.com/xnx3/translate"target="_blank" rel="external nofollow noopener noreferrer">translate.js<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 及相关生态产品的开发者</li>
<li><a href="https://github.com/hugo-fixit/FixIt"target="_blank" rel="external nofollow noopener noreferrer">FixIt<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 及相关生态产品的开发者</li>
</ul>
<p>另外,<a href="https://wx.zsxq.com/group/88888281181442?group_id=88888281181442&amp;coupon_code=ks2qf5zd&amp;inviter_id=15442515242512&amp;inviter_sid=e15da0zzz4&amp;keyword=BQcpe&amp;type=group"target="_blank" rel="external nofollow noopener noreferrer">Hugo FixIt 星球<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 成员每人补贴赠送 <strong>6 个月服务 / 年</strong>。</p>
<h3 id="赞助方式" class="heading-element"><span>赞助方式</span>
<a href="#%e8%b5%9e%e5%8a%a9%e6%96%b9%e5%bc%8f" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><ul>
<li><a href="https://lruihao.cn/images/wechatpay.jpg"target="_blank" rel="external nofollow noopener noreferrer">微信支付<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
<li><a href="https://lruihao.cn/images/alipay.jpg"target="_blank" rel="external nofollow noopener noreferrer">支付宝<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
</ul>
<p>选择赞助金额,然后在留言中备注 <code>AutoTranslate: 你的域名</code> 即可。</p>
<p>通过以下方式联系作者:</p>
<ul>
<li>邮箱:<code>1024#lruihao.cn</code> (将 <code>#</code> 替换为 <code>@</code>)</li>
<li>微信:<a href="https://lruihao.cn/images/qr-wx-mp_s.webp"target="_blank" rel="external nofollow noopener noreferrer">关注公众号回复“Cell”获取作者微信<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
</ul>
<h2 id="致谢" class="heading-element"><span>致谢</span>
<a href="#%e8%87%b4%e8%b0%a2" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p><a href="https://github.com/xnx3/translate"target="_blank" rel="external nofollow noopener noreferrer">translate.js<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 提供技术支持和赞助<a href="https://translate.zvo.cn/4087.html"target="_blank" rel="external nofollow noopener noreferrer">企业级翻译通道<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>。</p></description></item><item><title>🐟 一个 canvas 实现的小鱼游动动画效果。</title><link>https://lruihao.cn/projects/hugo-fixit/cmpt-flyfish/</link><pubDate>Tue, 05 Nov 2024 08:23:29 +0000</pubDate><guid>https://lruihao.cn/projects/hugo-fixit/cmpt-flyfish/</guid><category domain="https://lruihao.cn/categories/github/">GitHub</category><description><h2 id="fly-fish" class="heading-element"><span>Fly Fish</span>
<a href="#fly-fish" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>👉 简体中文说明 | <a href="https://raw.githubusercontent.com/hugo-fixit/cmpt-flyfish/refs/heads/main/README.en.md"target="_blank" rel="external nofollow noopener noreferrer">English README<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></p>
<p>一个 canvas 实现的小鱼游动动画效果。</p>
<h2 id="demo" class="heading-element"><span>Demo</span>
<a href="#demo" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p><a href="https://lruihao.cn"target="_blank" rel="external nofollow noopener noreferrer">https://lruihao.cn<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></p>
<h2 id="要求" class="heading-element"><span>要求</span>
<a href="#%e8%a6%81%e6%b1%82" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><ul>
<li>FixIt v0.3.12 或更高版本。</li>
</ul>
<h2 id="安装组件" class="heading-element"><span>安装组件</span>
<a href="#%e5%ae%89%e8%a3%85%e7%bb%84%e4%bb%b6" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>安装方法与 <a href="https://fixit.lruihao.cn/zh-cn/documentation/installation/"target="_blank" rel="external nofollow noopener noreferrer">安装主题<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 相同。有几种安装方式,请选择一种,例如,通过 Hugo 模块安装:</p>
<h3 id="作为-hugo-模块安装" class="heading-element"><span>作为 Hugo 模块安装</span>
<a href="#%e4%bd%9c%e4%b8%ba-hugo-%e6%a8%a1%e5%9d%97%e5%ae%89%e8%a3%85" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>首先确保你的项目本身是一个 <a href="https://gohugo.io/hugo-modules/use-modules/#initialize-a-new-module"target="_blank" rel="external nofollow noopener noreferrer">Hugo 模块<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>。</p>
<p>然后将此主题组件添加到你的 <code>hugo.toml</code> 配置文件中:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">module</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[[</span><span class="nx">module</span><span class="p">.</span><span class="nx">imports</span><span class="p">]]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">path</span> <span class="p">=</span> <span class="s2">&#34;github.com/hugo-fixit/FixIt&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="p">[[</span><span class="nx">module</span><span class="p">.</span><span class="nx">imports</span><span class="p">]]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">path</span> <span class="p">=</span> <span class="s2">&#34;github.com/hugo-fixit/cmpt-flyfish&#34;</span></span></span></code></pre></td></tr></table>
</div>
</div><p>在 Hugo 的第一次启动时,它将下载所需的文件。</p>
<p>要更新到模块的最新版本,请运行:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">hugo mod get -u
</span></span><span class="line"><span class="cl">hugo mod tidy</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="作为-git-子模块安装" class="heading-element"><span>作为 Git 子模块安装</span>
<a href="#%e4%bd%9c%e4%b8%ba-git-%e5%ad%90%e6%a8%a1%e5%9d%97%e5%ae%89%e8%a3%85" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h3><p>将 <a href="https://github.com/hugo-fixit"target="_blank" rel="external nofollow noopener noreferrer">FixIt<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 和此 git 存储库克隆到你的主题文件夹中,并将其作为网站目录的子模块添加。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git submodule add https://github.com/hugo-fixit/FixIt.git themes/FixIt
</span></span><span class="line"><span class="cl">git submodule add https://github.com/hugo-fixit/cmpt-flyfish.git themes/cmpt-flyfish</span></span></code></pre></td></tr></table>
</div>
</div><p>接下来编辑项目的 <code>hugo.toml</code> 并将此主题组件添加到你的主题中:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="nx">theme</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;FixIt&#34;</span><span class="p">,</span> <span class="s2">&#34;cmpt-flyfish&#34;</span><span class="p">]</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="配置" class="heading-element"><span>配置</span>
<a href="#%e9%85%8d%e7%bd%ae" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>为了通过 FixIt 主题在 <code>layouts/partials/custom.html</code> 文件中开放的 <a href="https://fixit.lruihao.cn/references/blocks/"target="_blank" rel="external nofollow noopener noreferrer">自定义块<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 将 <code>cmpt-flyfish.html</code> 注入到 <code>custom-assets</code> 中,你需要填写以下必要配置:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">params</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">params</span><span class="p">.</span><span class="nx">customPartials</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">head</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">profile</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">aside</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">comment</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">footer</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">widgets</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">assets</span> <span class="p">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl"> <span class="s2">&#34;inject/cmpt-flyfish.html&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"> <span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">postFooterBefore</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">postFooterAfter</span> <span class="p">=</span> <span class="p">[]</span></span></span></code></pre></td></tr></table>
</div>
</div><p>配置小鱼主题色,并启用动画:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">params</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">params</span><span class="p">.</span><span class="nx">flyfish</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">enable</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl"> <span class="nx">light</span> <span class="p">=</span> <span class="s2">&#34;rgb(0 119 190 / 10%)&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="nx">dark</span> <span class="p">=</span> <span class="s2">&#34;rgb(255 255 255 / 10%)&#34;</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="参考" class="heading-element"><span>参考</span>
<a href="#%e5%8f%82%e8%80%83" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><ul>
<li><a href="https://fixit.lruihao.cn/contributing/components/"target="_blank" rel="external nofollow noopener noreferrer">开发主题组件 | FixIt<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
<li><a href="https://fixit.lruihao.cn/components/dev-component/"target="_blank" rel="external nofollow noopener noreferrer">如何开发 Hugo 主题组件 | FixIt<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
</ul></description></item><item><title>自动获取 GitHub README 内容添加到 Hugo 文章</title><link>https://lruihao.cn/posts/content-adapters/</link><pubDate>Sun, 06 Oct 2024 11:10:22 +0800</pubDate><author>1024@lruihao.cn (Lruihao)</author><guid>https://lruihao.cn/posts/content-adapters/</guid><category domain="https://lruihao.cn/categories/memo/">Memo</category><description><img src="https://lruihao.cn/posts/content-adapters/featured-image.webp" alt="featured image" referrerpolicy="no-referrer"><p>在这个博客中,我经常会写一些关于开源项目的文章,而这些开源项目通常都是托管在 GitHub 上的。为了方便内容同步,我希望能够自动获取 GitHub 仓库的 README 内容,然后添加到 Hugo 文章中。这样,我就不用再手动复制粘贴 README 内容了。</p>
<h2 id="前言" class="heading-element"><span>1 前言</span>
<a href="#%e5%89%8d%e8%a8%80" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>这个愿景我想了很久了,但是用 JS 通过 GitHub API 获取 README 内容的实现方式体验并不好,所以我一直没有实现。直到最近,我发现了 Hugo v0.126.0 版本新增了一个内容适配器(Content adapters)的概念。</p>
<blockquote class="blockquote-center"><p>Create content adapters to dynamically add content when building your site.</p>
</blockquote>
<p>也就是说,我们可以在构建 Hugo 站点时,通过自定义的适配器动态添加内容。理论可行,实践开始。</p>
<h2 id="github-api" class="heading-element"><span>2 GitHub API</span>
<a href="#github-api" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>首先,我们需要找到 GitHub API 获取 README 内容的接口。懒得翻文档了,直接浏览器打开 <code>https://api.github.com</code>,在 API 列表中最终找到了获取 README 内容的接口:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-http" data-lang="http"><span class="line"><span class="cl"><span class="nf">GET</span> <span class="nn">/repos/{owner}/{repo}/readme</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
</span></span><span class="line"><span class="cl"><span class="n">Host</span><span class="o">:</span> <span class="l">api.github.com</span>
</span></span><span class="line"><span class="cl"><span class="n">Authorization</span><span class="o">:</span> <span class="l">token {your_token}</span></span></span></code></pre></td></tr></table>
</div>
</div><p>有些仓库会有多种语言的 README,还需要获取指定语言的 README 内容:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-http" data-lang="http"><span class="line"><span class="cl"><span class="nf">GET</span> <span class="nn">/repos/{owner}/{repo}/contents/README.{lang}.md</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
</span></span><span class="line"><span class="cl"><span class="n">Host</span><span class="o">:</span> <span class="l">api.github.com</span>
</span></span><span class="line"><span class="cl"><span class="n">Authorization</span><span class="o">:</span> <span class="l">token {your_token}</span></span></span></code></pre></td></tr></table>
</div>
</div><p>另外,GitHub API 有访问频率限制,需要在请求头中添加 <code>Authorization</code> 字段,值为 <code>token {your_token}</code>。<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
<h2 id="content-adapters" class="heading-element"><span>3 Content Adapters</span>
<a href="#content-adapters" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>在项目文件夹中创建 <code>_content.gotmpl</code>,添加以下代码:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-go-html-template" data-lang="go-html-template"><span class="line"><span class="cl"><span class="cp">{{-</span><span class="w"> </span><span class="nx">partial</span><span class="w"> </span><span class="s">&#34;adapters/projects.html&#34;</span><span class="w"> </span><span class="na">.</span><span class="w"> </span><span class="cp">-}}</span></span></span></code></pre></td></tr></table>
</div>
</div><p>目录结构如下:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-plain" data-lang="plain"><span class="line"><span class="cl">content/
</span></span><span class="line"><span class="cl">├── projects/
</span></span><span class="line"><span class="cl">│ ├── _content.gotmpl &lt;-- content adapter
</span></span><span class="line"><span class="cl">│ └── _index.md &lt;-- layout: projects
</span></span><span class="line"><span class="cl">data/
</span></span><span class="line"><span class="cl">└── projects.yml &lt;-- projects data</span></span></code></pre></td></tr></table>
</div>
</div><p>然后,打开 <code>hugo.toml</code> 文件,配置的 <code>projectsAdapters</code> 选项,启用内容适配器:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">params</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="p">[</span><span class="nx">params</span><span class="p">.</span><span class="nx">projectsAdapters</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">enable</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl"> <span class="nx">onlyPublic</span> <span class="p">=</span> <span class="kc">true</span>
</span></span><span class="line"><span class="cl"> <span class="nx">categories</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">collections</span> <span class="p">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl"> <span class="nx">ignoreList</span> <span class="p">=</span> <span class="p">[]</span></span></span></code></pre></td></tr></table>
</div>
</div><p>好了,现在准备工作都做完了,剩下要做的就是实现 <code>adapters/projects.html</code> 就好了。</p>
<p>思路:</p>
<ul
class="fi-timeline"
data-animation><li
class="fi-timeline-item"
data-size="medium"
data-node="circle"
style="--timeline-index: 1;"><div class="fi-timeline-item__content">遍历 <code>data/projects.yml</code> 中的项目数据</div>
<div class="fi-timeline-item__timestamp is-bottom"></div></li><li
class="fi-timeline-item"
data-size="medium"
data-node="circle"
style="--timeline-index: 2;"><div class="fi-timeline-item__content">通过 GitHub API 获取 README 内容</div>
<div class="fi-timeline-item__timestamp is-bottom"></div></li><li
class="fi-timeline-item"
data-size="medium"
data-node="circle"
style="--timeline-index: 3;"><div class="fi-timeline-item__content">README 解析为 Markdown 格式,并处理图片链接,部分字符转义</div>
<div class="fi-timeline-item__timestamp is-bottom"></div></li><li
class="fi-timeline-item"
data-size="medium"
data-node="circle"
style="--timeline-index: 4;" data-type="success"><div class="fi-timeline-item__content">将 README 内容添加到 Hugo 文章中</div>
<div class="fi-timeline-item__timestamp is-bottom"></div></li></ul><p>具体的源码实现可以查看 <a href="https://github.com/hugo-fixit/component-projects/"target="_blank" rel="external nofollow noopener noreferrer">component-projects<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a> 主题组件。</p>
<h2 id="实现效果" class="heading-element"><span>4 实现效果</span>
<a href="#%e5%ae%9e%e7%8e%b0%e6%95%88%e6%9e%9c" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><ul>
<li><a href="https://lruihao.cn/projects/">我的开源</a></li>
<li><a href="https://fixit.lruihao.cn/components/"target="_blank" rel="external nofollow noopener noreferrer">Theme Components | FixIt<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
</ul>
<!-- footnote reference definition -->
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>点击跳到 GitHub <a href="https://github.com/settings/tokens/new"target="_blank" rel="external nofollow noopener noreferrer">生成 token<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>,选择名为 <code>public_repo</code> 的范围以生成个人访问令牌。&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div></description></item><item><title>不使用任何框架,只使用原生 HTML、CSS 和 JavaScript 的一些小 demo。</title><link>https://lruihao.cn/projects/lruihao/html-demo/</link><pubDate>Fri, 13 Sep 2024 02:36:29 +0000</pubDate><author>1024@lruihao.cn (Lruihao)</author><guid>https://lruihao.cn/projects/lruihao/html-demo/</guid><category domain="https://lruihao.cn/categories/github/">GitHub</category><description><h2 id="html-demos" class="heading-element"><span>HTML demos</span>
<a href="#html-demos" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>不使用任何框架,只使用原生 HTML、CSS 和 JavaScript 的一些小 demo。</p>
<h2 id="文件预览" class="heading-element"><span>文件预览</span>
<a href="#%e6%96%87%e4%bb%b6%e9%a2%84%e8%a7%88" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>直接浏览器打开 <code>src</code> 目录下的 HTML 文件。</p>
<h2 id="serve-预览" class="heading-element"><span>serve 预览</span>
<a href="#serve-%e9%a2%84%e8%a7%88" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">yarn
</span></span><span class="line"><span class="cl">yarn serve</span></span></code></pre></td></tr></table>
</div>
</div><p>然后访问 <code>http://localhost:3000</code>。</p></description></item><item><title>⚙️ Versioning, change-log and release.</title><link>https://lruihao.cn/projects/hugo-fixit/fixit-releaser/</link><pubDate>Wed, 04 Sep 2024 18:10:59 +0000</pubDate><guid>https://lruihao.cn/projects/hugo-fixit/fixit-releaser/</guid><category domain="https://lruihao.cn/categories/github/">GitHub</category><description><h2 id="fixit-releaser" class="heading-element"><span>FixIt Releaser</span>
<a href="#fixit-releaser" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>Automatically update FixIt internal version number and generate changelog.</p>
<h2 id="installation" class="heading-element"><span>Installation</span>
<a href="#installation" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">npm install fixit-releaser --save-dev</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="configuration" class="heading-element"><span>Configuration</span>
<a href="#configuration" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>Add the following to <code>package.json</code> of FixIt project.</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="nt">&#34;scripts&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl"> <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;fixit-releaser version --prod&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"> <span class="nt">&#34;release&#34;</span><span class="p">:</span> <span class="s2">&#34;fixit-releaser changelog&#34;</span>
</span></span><span class="line"><span class="cl"> <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="usage" class="heading-element"><span>Usage</span>
<a href="#usage" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">npx fixit-releaser version --prod
</span></span><span class="line"><span class="cl"><span class="c1"># Update the FixIt version from v0.3.12-1ca9fdb7 to v0.3.12.</span>
</span></span><span class="line"><span class="cl">npx fixit-releaser version --dev
</span></span><span class="line"><span class="cl"><span class="c1"># Update the FixIt version from v0.3.12-1ca9fdb7 to v0.3.12-2ca9fdb7.</span>
</span></span><span class="line"><span class="cl">npx fixit-releaser changelog --starting-version v0.3.10
</span></span><span class="line"><span class="cl"><span class="c1"># auto-changelog: 6 kB written to CHANGELOG.md</span></span></span></code></pre></td></tr></table>
</div>
</div></description></item><item><title>Hugo theme component for JSON feed custom Output Format.</title><link>https://lruihao.cn/projects/hugo-fixit/hugo-json-feed/</link><pubDate>Thu, 22 Aug 2024 03:28:23 +0000</pubDate><guid>https://lruihao.cn/projects/hugo-fixit/hugo-json-feed/</guid><category domain="https://lruihao.cn/categories/github/">GitHub</category><description><h2 id="hugo-json-feed" class="heading-element"><span>Hugo JSON Feed</span>
<a href="#hugo-json-feed" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><blockquote>
<p>Hugo theme component for JSON feed custom Output Format.</p>
</blockquote>
<p>This component enables JSON feeds for your site.</p>
<h2 id="demo" class="heading-element"><span>Demo</span>
<a href="#demo" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><ul>
<li><a href="https://lruihao.cn/feed.json"target="_blank" rel="external nofollow noopener noreferrer">Home Feed<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
<li><a href="https://lruihao.cn/posts/feed.json"target="_blank" rel="external nofollow noopener noreferrer">Section Feed<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
<li><a href="https://lruihao.cn/collections/project/feed.json"target="_blank" rel="external nofollow noopener noreferrer">Term Feed<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a></li>
</ul>
<h2 id="install-component" class="heading-element"><span>Install Component</span>
<a href="#install-component" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>The installation method is the same as <a href="https://fixit.lruihao.cn/documentation/installation/"target="_blank" rel="external nofollow noopener noreferrer">installing a theme<i class="fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary" aria-hidden="true"></i></a>. There are several ways to install, choose one, for example, install through Hugo Modules:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-diff" data-lang="diff"><span class="line"><span class="cl">[module]
</span></span><span class="line"><span class="cl"> [[module.imports]]
</span></span><span class="line"><span class="cl"> path = &#34;github.com/hugo-fixit/FixIt&#34;
</span></span><span class="line"><span class="cl"><span class="gi">+ [[module.imports]]
</span></span></span><span class="line"><span class="cl"><span class="gi">+ path = &#34;github.com/hugo-fixit/hugo-json-feed&#34;
</span></span></span></code></pre></td></tr></table>
</div>
</div><h2 id="configuration" class="heading-element"><span>Configuration</span>
<a href="#configuration" class="heading-mark">
<svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>
</a>
</h2><p>Add &ldquo;jsonfeed&rdquo; to all the Page Kinds for which you want to create JSON feeds:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">outputs</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="c"># &lt;baseURL&gt;/feed.json</span>
</span></span><span class="line"><span class="cl"> <span class="nx">home</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;html&#34;</span><span class="p">,</span> <span class="s2">&#34;rss&#34;</span><span class="p">,</span> <span class="s2">&#34;jsonfeed&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="c"># &lt;baseURL&gt;/posts/feed.json etc.</span>
</span></span><span class="line"><span class="cl"> <span class="nx">section</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;html&#34;</span><span class="p">,</span> <span class="s2">&#34;rss&#34;</span><span class="p">,</span> <span class="s2">&#34;jsonfeed&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"> <span class="c"># &lt;baseURL&gt;/tags/foo/feed.json etc.</span>
</span></span><span class="line"><span class="cl"> <span class="nx">term</span> <span class="p">=</span> <span class="p">[</span><span class="s2">&#34;html&#34;</span><span class="p">,</span> <span class="s2">&#34;rss&#34;</span><span class="p">,</span> <span class="s2">&#34;jsonfeed&#34;</span><span class="p">]</span></span></span></code></pre></td></tr></table>
</div>
</div><p>If your site uses multiple theme components, you need to merge the <code>outputs</code> configuration of all theme components. For example, if your site uses both the <code>FixIt</code> and <code>hugo-json-feed</code> theme components, you need to merge the <code>outputs</code> configuration of the two theme components:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5