Skip to content

Commit de9dafd

Browse files
committed
Add Custom Index Title.
1 parent 3f91d78 commit de9dafd

File tree

7 files changed

+69
-5
lines changed

7 files changed

+69
-5
lines changed

assets/dist/app.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/dist/index.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/dist/index.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/app.js

+40
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,43 @@ function pageDown() {
112112
});
113113
}
114114

115+
function hitokoto() {
116+
const dom = document.querySelector('div#customTitle').querySelector('h2');
117+
const cache = sessionStorage.getItem('hitokoto');
118+
if (cache !== null && cache !== '') {
119+
dom.innerText = cache;
120+
return;
121+
}
122+
fetch('//v1.hitokoto.cn/?c=c&c=d&c=i&c=k&encode=json', {method: 'GET', mode: "cors"})
123+
.then(res => res.json())
124+
.then(res => {
125+
const text = `${res.hitokoto} - ${res.from ? `《${res.from}》` : ''}${res.from_who ? res.from_who : ''}`;
126+
sessionStorage.setItem('hitokoto', text);
127+
dom.innerText = text;
128+
})
129+
.catch(err => {
130+
console.error('「一言」请求失败');
131+
console.error(err);
132+
dom.innerText = '学而不思则罔,思而不学则殆。 - 《论语》 孔子';
133+
});
134+
}
135+
115136
/* ================= 页面动画 ================== */
116137

138+
function titleAnimation() {
139+
const path = document.querySelector('path#pathTitle');
140+
if (path === null) {
141+
return
142+
}
143+
144+
const length = path.getTotalLength();
145+
146+
path.style.strokeDasharray = length;
147+
path.style.strokeDashoffset = length;
148+
149+
TweenMax.to(path, 5, {strokeDashoffset: 0});
150+
}
151+
117152
// 页面封面 视差效果
118153
function coverPin() {
119154
const section = document.querySelector('#welcome');
@@ -181,6 +216,11 @@ window.addEventListener('load', () => {
181216
pageDown();
182217
}
183218

219+
if (document.querySelector('div#customTitle') !== null) {
220+
titleAnimation();
221+
hitokoto();
222+
}
223+
184224
searchController();
185225
mainScroll();
186226

assets/less/index.less

+9
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ header#welcome {
374374
}
375375
}
376376

377+
div#customTitle {
378+
h2 {
379+
font-family: 'CodeFont', cursive;
380+
margin: 0.5rem auto;
381+
382+
word-break: break-word;
383+
}
384+
}
385+
377386
div.tags a {
378387
font-size: 1.2rem;
379388
color: var(--white-font-color);

index.ftl

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
<#include "module/menu.ftl">
88

99
<#-- Page Cover -->
10-
<@cover.layout img="${settings.index_cover!}" title="${settings.title!blog_title}" subtitle="${settings.subtitle!}" />
10+
<@cover.layout img="${settings.index_cover!}" title="" subtitle="">
11+
<div id="customTitle">
12+
<svg xmlns="http://www.w3.org/2000/svg" height="120" width="300">
13+
<path
14+
id="pathTitle"
15+
d="M 1.0389924,25.612305 C 10.395233,29.939699 22.06724,16.661916 25.860272,11.217656 27.653702,8.6133136 34.78628,2.2689916 29.233265,2.4827893 17.845106,13.596036 12.248381,25.465618 9.623045,38.792263 c -2.7261904,13.83861 -5.0168454,37.654274 4.664846,41.985042 6.533225,2.492119 13.413366,-4.51983 18.745849,-9.182644 4.29594,-4.315364 20.851225,-17.7611 18.308679,-21.927513 -2.715331,-2.115344 -3.949963,12.630097 -1.906016,18.538554 1.959565,5.664519 4.862591,14.316271 12.622777,13.433258 8.03929,-0.914773 15.746816,-14.589734 14.388086,-23.526579 -3.086548,-20.301284 -20.950952,-15.005709 -25.615844,-7.7282 6.429822,6.091884 15.994024,2.2568 24.622178,1.501583 7.101806,-0.621614 20.258916,-3.596322 30.27827,-5.851673 3.79154,-0.853479 6.95667,-0.643022 11.27928,-2.903743 4.30131,-3.657235 -9.52917,-1.324271 -13.37611,0.792615 -5.379671,2.960328 -11.207421,9.003219 -10.073169,14.727978 0.745293,3.761667 4.511698,5.3255 9.891079,6.837607 4.64741,1.306341 10.63879,6.179117 8.29242,9.68181 -4.79527,7.158479 -17.791481,7.73153 -22.515646,5.39236 -5.358525,-3.578132 1.048821,-2.002714 8.818797,-2.750862 23.387259,-0.08013 31.888229,-15.040578 47.948019,-22.707187 7.98405,-3.62706 19.31076,-3.673222 21.72444,-6.737839 3.60646,-4.579106 -9.56355,-6.721206 -14.38203,-5.086884 -10.20395,3.460982 -17.52679,16.491167 -15.89726,26.494683 0.77291,4.744749 2.9387,9.608693 11.2026,9.915943 10.94853,0.407072 20.12697,-30.610349 20.12697,-30.610349 0,0 -0.22138,18.509953 -1.85549,27.60206 -1.89474,10.542313 -2.58892,22.147376 -9.1563,30.911637 -3.23892,4.32237 -6.72422,7.16382 -13.80386,9.20259 -7.20501,2.07486 -15.16915,-0.49132 -15.905,-5.74487 -1.56211,-11.152605 16.31914,-14.639366 29.27414,-19.86133 15.12648,-6.097276 22.64463,-13.515764 35.69529,-35.698333 0,0 -7.34951,18.306313 -1.44901,24.248195 3.53309,3.557828 11.17687,2.86662 15.60275,0.319263 7.16299,-4.122739 11.43879,-13.4485 10.80782,-21.271341 -2.40325,-9.985686 -9.61118,-16.458446 -20.02728,-13.158051 -3.61628,1.175959 -9.70812,6.815327 -8.04709,8.530708 11.50913,3.161098 29.71514,-5.633357 42.59799,-7.369898 9.07227,-1.170624 25.92944,-1.292971 29.97948,-3.269137 5.81842,-2.839017 -7.58851,-2.789604 -14.36127,-1.32875 -5.82453,1.256326 -15.68913,7.588361 -16.88658,24.548822 -0.48247,6.833495 4.58205,15.220689 11.09797,15.007591 14.93106,-0.488298 20.16894,-26.202342 22.78046,-35.966125 C 269.2961,30.60547 278.00163,-0.22111672 277.75862,2.9147966 268.03927,28.300777 261.56914,47.71714 260.73898,66.720078 c 1.83895,6.249338 6.17716,12.998876 12.64877,15.09042 8.20478,2.651683 18.46478,-1.520731 25.30611,-5.770423"
16+
style="fill:none;stroke:#ffffff;stroke-width:5px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
17+
</svg>
18+
<h2 style="font-family: cursive;"></h2>
19+
</div>
20+
</@cover.layout>
1121

1222
<main>
1323
<#if settings.custom_info??>

module/cover.ftl

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
<img src="${(img?? && img != "")?string(img, settings.default_pic)}" alt="">
77
</div>
88
<div class="title">
9-
<h1>${title!}</h1>
9+
<#if title?? && title != "">
10+
<h1>${title!}</h1>
11+
</#if>
12+
<#if subtitle?? && subtitle != "">
1013
<h3>${subtitle!}</h3>
14+
</#if>
15+
1116
<#nested >
1217
</div>
1318
<div id="down">

0 commit comments

Comments
 (0)