Hexo-添加友链页面

写在前面

在此使用的是NexT主题,自己创建一个友情链接页面。


1. 添加友链页面

  1. 添加页面

./source/ 目录下创建links/index.md

或执行命令

hexo new page links

可以在文件内写友链声明等内容,将会被放在友链后。

2. 修改配置

修改主题配置文件

./themes/next/_config.yml
menu: home: / || home ··· links: /links/ || link

修改主题语言配置文件,以zh-Hans.yml为例

./themes/next/language/zh-Hans.yml
menu: home: 首页 ··· links: 友链 # 新增该选项表示新增“友链”菜单

3. 添加模板

创建./themes/next/layout/links.swig文件

在此贴上我的代码, 【此处折叠】
links.swig.txtview raw
{% block content %} {######################} {### LINKS BLOCK ###} {######################} <!-- 引入样式 --> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> <!-- 引入组件库 --> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <!-- 引入MDUI --> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/mdui/0.4.3/css/mdui.min.css"> <script src="//cdnjs.cloudflare.com/ajax/libs/mdui/0.4.3/js/mdui.min.js"></script> <!-- 引入Mystyle样式 --> <link rel="stylesheet" href="/css/mystyle.css"> <div id="links"> <el-tooltip :content=" '当前样式: ' + value " placement="top"> <el-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949" active-value="default" inactive-value="square" @change = changeStyleClass> </el-switch> </el-tooltip> <div class="links-content"> <div class="mdui-panel mdui-panel-gapless " mdui-panel="{accordion: false}"> <div class="mdui-panel-item mdui-panel-item-open"> <div class="mdui-panel-item-header no-icon note warning"> <div class="link-info">👨‍🎓 跟着大佬走,成为小大佬</div> <i class="mdui-panel-item-arrow mdui-icon material-icons">keyboard_arrow_down</i> </div> <div class="mdui-panel-item-body link-navigation"> {% for link in site.data.links.defaultlinks %} <div class="card"> <a class="link" href="{{ link.site }}" target="_blank"> <el-avatar {% if site.data.links.shape === 'square' %} shape="square" {% else %} shape="circle" {% endif %} :size="60" fit="contain" src="{% if link.avatar !== '' %}{{ link.avatar }}{% endif %}" @error="errorHandler"> <img class="ava" src="{{ site.data.links.defaultPic }}"/> </el-avatar> <div class="card-header"> <div>{{ link.nickname }}</div> <div class="info">{{ link.info }}</div> </div> </a> </div> {% endfor %} </div> </div> <div class="mdui-panel-item mdui-panel-item-open"> <div class="mdui-panel-item-header no-icon note primary"> <div class="link-info">🍭 五湖四海的朋友们</div> <i class="mdui-panel-item-arrow mdui-icon material-icons">keyboard_arrow_down</i> </div> <div class="mdui-panel-item-body link-navigation"> {% for link in site.data.links.friendslinks %} <div class="card"> <a class="link" href="{{ link.site }}" target="_blank"> <el-avatar {% if site.data.links.shape === 'square' %} shape="square" {% else %} shape="circle" {% endif %} :size="60" fit="contain" src="{% if link.avatar !== '' %}{{ link.avatar }}{% endif %}" @error="errorHandler"> <img class="ava" src="{{ site.data.links.defaultPic }}"/> </el-avatar> <div class="card-header"> <div>{{ link.nickname }}</div> <div class="info">{{ link.info }}</div> </div> </a> </div> {% endfor %} </div> </div> </div> {{ page.content }} </div> </div> <script> new Vue({ el: '#links', data: function() { return { value: 'default', circleUrl: "/static/images/default.png" } }, methods:{ changeStyleClass: function(callback){ console.log(callback) if(callback !== 'square'){ if($('div').hasClass('squareCard')){ var l = $(".squareCard").length; for (var i=0;i < l;i++){ $(".squareCard>a>span")[0].classList.toggle('el-avatar'); $(".squareCard>a>span")[0].classList.toggle('el-avatar--square'); $(".squareCard")[0].classList.replace('squareCard','card'); } } }else{ if($('div').hasClass('card')){ var l = $(".card").length; for (var i=0;i < l;i++){ $(".card>a>span")[0].classList.toggle('el-avatar'); $(".card>a>span")[0].classList.toggle('el-avatar--square'); $(".card")[0].classList.replace('card','squareCard'); } } } }, errorHandler() { return true } } }) </script> <script> var cards = document.getElementsByClassName("card"); for (var i=0;i<cards.length;i++){ cards[i].onclick = function(){ this.firstElementChild.click(); } } </script> {##########################} {### END LINKS BLOCK ###} {##########################} {% endblock %}

./themes/next/layout/page.swig中引入模板,

./themes/next/layout/page.swig
··· ··· <!-- 友情链接--> {% elif page.type === 'links' %} {% include 'links.swig' %} <!-- 友情链接--> {% elif page.type === 'schedule' %} ··· ···

4. 添加样式

创建./themes/next/source/css/mystyle.css文件

在此贴上我的代码, 【此处折叠】
mystyle.cssview raw
#links { margin-top: 60px; } .links-content { margin-top: 1rem; } .links-content .mdui-panel-item, .links-content .mdui-panel-gapless{ -webkit-box-shadow: none !important; box-shadow: none !important; } .links-content .mdui-panel-item .note{ margin: 0px; } .link-navigation{ margin-top: 15px; } .link-navigation::after { content: " "; display: block; clear: both; } .card { width: 300px; height: 64px; font-size: 1rem; padding: 10px 20px; border-radius: 4px; transition: 0.4s; margin-bottom: 1rem; display: block; -webkit-box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2), 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12); box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2), 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12); } .card:nth-child(odd) { float: left; } .card:nth-child(even) { float: right; } .card:hover { transform: scale(1.1); -webkit-box-shadow: 0 5px 5px -3px rgba(0, 0, 0, .2), 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12); box-shadow: 0 5px 5px -3px rgba(0, 0, 0, .2), 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12); } .card a { border: none; display: inline-flex; } .card .ava { width: 4rem !important; height: 4rem !important; margin: 0 !important; margin-right: 1em !important; border-radius: 4px; display: inline; } .card .card-header { font-style: italic; overflow: hidden; width: 236px; padding-left: 10px; } .card .link { font-style: normal; color: #2bbc8a; font-weight: bold; text-decoration: none; } .card .link:hover { color: #d480aa; text-decoration: none; } .card .card-header .info { font-style: normal; color: #a3a3a3; font-size: 14px; min-width: 0; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; } .squareCard { margin: 5px 10px !important; padding: 3px !important; border-radius: 3px; overflow: hidden; float: left; width: 145px; position: relative; min-height: 1px; -webkit-box-sizing: border-box; box-sizing: border-box; border-radius: 2px; -webkit-box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2), 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12); box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2), 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12); -webkit-transition: -webkit-box-shadow .25s cubic-bezier(0.4, 0, 0.2, 1); transition: -webkit-box-shadow .25s cubic-bezier(.4, 0, .2, 1); transition: box-shadow .25s cubic-bezier(.4, 0, .2, 1); transition: box-shadow .25s cubic-bezier(.4, 0, .2, 1), -webkit-box-shadow .25s cubic-bezier(.4, 0, .2, 1); will-change: box-shadow; transition: all .3s; } .squareCard:hover { -webkit-box-shadow: 0 5px 5px -3px rgba(0, 0, 0, .2), 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12); box-shadow: 0 5px 5px -3px rgba(0, 0, 0, .2), 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12); opacity: .8; } @media (max-width: 600px) { .squareCard { float: left; } } /* - top: 0; - left: 0; - width: 100%; - height: 100%; - background: rgba(255, 255, 255, 0.5); - -webkit-transition: -webkit-transform 0.5s; - transition: transform 0.5s; - -webkit-transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, -100%, 0); - transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, -100%, 0); + left: -100px; + bottom: -63px; + width: 50px; + height: 277px; + background: #fff; + -webkit-transition: transform 0.5s ease; + transition: transform 0.5s ease; + -webkit-transform: translateX(-50px) rotate(45deg); + transform: translateX(-50px) rotate(45deg); */ .squareCard::before { position: absolute; content: ''; left: -100px; bottom: -63px; width: 50px; height: 277px; background: #fff; -webkit-transition: transform 0.5s ease; transition: transform 0.5s ease; -webkit-transform: translateX(-50px) rotate(45deg); transform: translateX(-50px) rotate(45deg); z-index: 99999; } /* - -webkit-transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, 100%, 0); - transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, 45deg) translate3d(0, 100%, 0); + -webkit-transform: translateX(360px) rotate(45deg); + transform: translateX(360px) rotate(45deg); */ .squareCard:hover::before { -webkit-transform: translateX(360px) rotate(45deg); transform: translateX(360px) rotate(45deg); } .squareCard a { position: relative; display: inline-block; overflow: hidden; color: #ff4081; text-decoration: none; vertical-align: top; outline: 0; } .squareCard img { margin: 0 !important; padding: 0 !important; width: 10rem; height: 8.7rem; background-color: aliceblue; object-fit: contain; } .squareCard .card-header { width: calc(100%); border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; overflow: hidden; background: rgba(0, 0, 0, .3); z-index: 3; position: absolute; right: 0; bottom: 0; min-height: 48px; max-height: 68px; box-sizing: border-box; padding: 5px; color: #fff; -webkit-box-align: center; -webkit-align-items: center; align-items: center; } .squareCard .card-header div:first-of-type { height: 20px; text-align: left; overflow: hidden; font-size: 16px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; transition: all .3s; } .squareCard .card-header .info { height: 18px; margin-top: 4px; overflow: hidden; font-size: 12px; line-height: 18px; text-overflow: ellipsis; white-space: nowrap; opacity: 1; }

5. 添加友链

创建./source/_data/links.yml文件,并配置

./source/_data/links.yml
defaultPic: /static/images/default.png # 默认图片 shape: # 可选值 square | circle,默认square defaultlinks: - nickname: # 名称 site: # 网址 avatar: # 头像 info: # 简介 friendslinks : - nickname: # 名称 site: # 网址 avatar: # 头像 info: # 简介