為你的hexo部落格添加說說頁面
- 2020 年 4 月 9 日
- 筆記
解決導語中的問題的很好的一個辦法就是,添加一個說說的頁面,每次只有一兩句話,以類似於時間軸的形式展現出來。 我在網上搜了好久,基本上都是針對於wordpress的php的程式碼。wordpress我是真的用不好,還是hexo得我心。 然後我這個前端小白,抱著試一試的心理把php的程式碼直接做成頁面放進了我的部落格。沒想到還真的成了。但是肯定也是改了一些東西的,不然這篇文章意義何在? 一個比較大的變化就是,原版的程式碼中使用php獲取當前時間的函數再html中我沒有找到與之對應的。所以有個很尷尬的問題就是,當你想新建一個說說並且顯示日期的時候,你得手動。。。這個確實不太方便,但是我的能力也就止步於此了。 我是在這裡找到的源碼:純程式碼給wordpress增加說說/微博/微語功能 | 言曌部落格
下面是hexo添加這個頁面的大致步驟。
- 在
..blog文件夾source
中新建一個文件夾,命名隨意,但是一定要記住。這裡我新建的文件夾叫shuoshuo
- 在文件夾中新建一個
index.html
,並將程式碼粘貼進去 - 在對應的主題頁面菜單添加說說,並鏈接到創建的說說頁面
上面的第一第三步不難,並且每個主題可能還不一樣,所以就不細說了。
第二步: 將下面的程式碼粘貼到你的index.html中
<style type="text/css"> #shuoshuo_content { background-color: #fff; padding: 10px; min-height: 500px; } /* shuo */ body.theme-dark .cbp_tmtimeline::before { background: RGBA(255, 255, 255, 0.06); } ul.cbp_tmtimeline { padding: 0; } div class.cdp_tmlabel > li .cbp_tmlabel { margin-bottom: 0; } .cbp_tmtimeline { margin: 30px 0 0 0; padding: 0; list-style: none; position: relative; } /* The line */ .cbp_tmtimeline:before { content: ''; position: absolute; top: 0; bottom: 0; width: 4px; background: RGBA(0, 0, 0, 0.02); left: 80px; margin-left: 10px; } /* The date/time */ .cbp_tmtimeline > li .cbp_tmtime { display: block; /* width: 29%; */ /* padding-right: 110px; */ max-width: 70px; position: absolute; } .cbp_tmtimeline > li .cbp_tmtime span { display: block; text-align: right; } .cbp_tmtimeline > li .cbp_tmtime span:first-child { font-size: 0.9em; color: #bdd0db; } .cbp_tmtimeline > li .cbp_tmtime span:last-child { font-size: 1.2em; color: #9BCD9B; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmtime span:last-child { color: RGBA(255, 125, 73, 0.75); } div.cbp_tmlabel > p { margin-bottom: 0; } /* Right content */ .cbp_tmtimeline > li .cbp_tmlabel { margin: 0 0 45px 65px; background: #9BCD9B; color: #fff; padding: .8em 1.2em .4em 1.2em; /* font-size: 1.2em; */ font-weight: 300; line-height: 1.4; position: relative; border-radius: 5px; transition: all 0.3s ease 0s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); cursor: pointer; display: block; } .cbp_tmlabel:hover { /* transform:scale(1.05); */ transform: translateY(-3px); z-index: 1; -webkit-box-shadow: 0 15px 32px rgba(0, 0, 0, 0.15) !important } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel { background: RGBA(255, 125, 73, 0.75); } /* The triangle */ .cbp_tmtimeline > li .cbp_tmlabel:after { right: 100%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; border-right-color: #9BCD9B; border-width: 10px; top: 4px; } .cbp_tmtimeline > li:nth-child(odd) .cbp_tmlabel:after { border-right-color: RGBA(255, 125, 73, 0.75); } p.shuoshuo_time { margin-top: 10px; border-top: 1px dashed #fff; padding-top: 5px; } /* Media */ @media screen and (max-width: 65.375em) { .cbp_tmtimeline > li .cbp_tmtime span:last-child { font-size: 1.2em; } } .shuoshuo_author_img img { border: 1px solid #ddd; padding: 2px; float: left; border-radius: 64px; transition: all 1.0s; } .avatar { -webkit-border-radius: 100% !important; -moz-border-radius: 100% !important; box-shadow: inset 0 -1px 0 #3333sf; -webkit-box-shadow: inset 0 -1px 0 #3333sf; -webkit-transition: 0.4s; -webkit-transition: -webkit-transform 0.4s ease-out; transition: transform 0.4s ease-out; -moz-transition: -moz-transform 0.4s ease-out; } .zhuan { transform: rotateZ(720deg); -webkit-transform: rotateZ(720deg); -moz-transform: rotateZ(720deg); } /* end */ </style> </head> <body> <div id="primary" class="content-area" style=""> <main id="main" class="site-main" role="main"> <div id="shuoshuo_content"> <ul class="cbp_tmtimeline"> <li> <span class="shuoshuo_author_img"><img src="https://cdn.jsdelivr.net/gh/drew233/cdn/dreww.webp" class="avatar avatar-48" width="48" height="48"></span> <a class="cbp_tmlabel" href=""> <p></p> <p>第一個說說</p> <p></p> <p class="shuoshuo_time"><i class="fa fa-clock-o"></i> 2019年9月10日 </p> </a> </li> </ul> </div> </div> <script type="text/javascript"> (function () { var oldClass = ""; var Obj = ""; $(".cbp_tmtimeline li").hover(function () { Obj = $(this).children(".shuoshuo_author_img"); Obj = Obj.children("img"); oldClass = Obj.attr("class"); var newClass = oldClass + " zhuan"; Obj.attr("class", newClass); }, function () { Obj.attr("class", oldClass); }) }) </script>
如果在你的說說頁面你不想讓評論,直接在最上面加上
--- comment: false ---
每次想要新建一個說說的時候按照這個格式來
<li> <span class="shuoshuo_author_img"><img src="https://cdn.jsdelivr.net/gh/drew233/cdn/dreww.webp" class="avatar avatar-48" width="48" height="48"></span> <!-- 這個img src裡面的鏈接是說說頭像的鏈接 --> <a class="cbp_tmlabel" href=""> <!-- 這個href是你想要讓這個說說鏈接到的地方,如果沒有不管它就行 --> <p></p> <p><!-- 這裡寫的就是說說的內容 --></p> <p></p> <p class="shuoshuo_time"><i class="fa fa-clock-o"></i> 2019年9月10日 <!-- 這個地方寫上時間,如果不想寫刪除就行了。 --> </p> </a> </li>
按照你的想法將上面的程式碼改好之後,粘貼到你的shuoshuo文件夾中index.html裡面。根據每個
- 標籤查找你應該粘貼到的位置。注意這個順序就會是你在頁面上現實的順序。
為了預防你還不知道怎麼添加,給你一個三個說說的部分程式碼的例子
<div id="primary" class="content-area" style=""> <main id="main" class="site-main" role="main"> <div id="shuoshuo_content"> <ul class="cbp_tmtimeline"> <li> <span class="shuoshuo_author_img"><img src="https://cdn.jsdelivr.net/gh/drew233/cdn/dreww.webp" class="avatar avatar-48" width="48" height="48"></span> <a class="cbp_tmlabel" href=""> <p></p> <p>第一個說說</p> <p></p> <p class="shuoshuo_time"><i class="fa fa-clock-o"></i> 2019年9月10日 </p> </a> </li> <li> <span class="shuoshuo_author_img"><img src="https://cdn.jsdelivr.net/gh/drew233/cdn/dreww.webp" class="avatar avatar-48" width="48" height="48"></span> <a class="cbp_tmlabel" href=""> <p></p> <p>第一個說說</p> <p></p> <p class="shuoshuo_time"><i class="fa fa-clock-o"></i> 2019年9月10日 </p> </a> </li> <li> <span class="shuoshuo_author_img"><img src="https://cdn.jsdelivr.net/gh/drew233/cdn/dreww.webp" class="avatar avatar-48" width="48" height="48"></span> <a class="cbp_tmlabel" href=""> <p></p> <p>第一個說說</p> <p></p> <p class="shuoshuo_time"><i class="fa fa-clock-o"></i> 2019年9月10日 </p> </a> </li> </ul> </div> </div>
這裡我還是挺希望大家可以留言評論的,因為點贊功能我加不上。。。這個源碼很強的一點就是我試了好幾個主題,它的兼容性都特別好,直接融入主題,毫無違和感的那種,還是舔一波原作者,太強了。
效果圖:
我的說說介面傳送門: Drew最帥