美文网首页hexo建博
hexo6--next美化整理

hexo6--next美化整理

作者: pigpi | 来源:发表于2017-11-24 15:57 被阅读0次

    title: hexo6--next美化整理
    date: 2017-10-25 13:15:08
    categories: hexo建博
    tags: [hexo, next]
    copyright: true
    keywords: hexo,next,美化
    comments: ture


    既然选择了next主题,也不打算经常换,但是做一些美化还是可以考虑的。

    在右上角或者左上角实现fork me on github

    效果

    1.png

    实现

    点击这里挑选自己喜欢的样式,并复制代码。 然后粘贴刚才复制的代码到themes/next/layout/_layout.swig文件中(放在<div class="headband"></div>的下面),并把href改为你的github地址。

    2.png

    重新clean并生成。

    404页面

    默认的404页面是github的,如果想自定义,需要把自己的404.html页面放在皮肤的source目录下即可。建议使用腾讯公益的页面:

    <!DOCTYPE HTML> 
    <html> 
    <head> 
    <meta http-equiv="content-type" content="text/html;charset=utf-8;"/> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
    <meta name="robots" content="all" /> <meta name="robots" content="index,follow"/> 
    </head> 
    <body> 
    <script type="text/javascript" src="http://www.qq.com/404/search_children.js" charset="utf-8" homePageUrl="your site url " homePageName="回到我的主页"></script> 
    </body> 
    </html>
    

    添加动态背景

    效果

    3.png

    线条会动啊动,飘啊飘。

    实现

    添加js

    修改 themes/next/layout/_layout.swig

    {% if theme.canvas_nest %}
    <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js">
    </script>
    {% endif %}
    

    将上述代码防止在< /body> 前就可以了(注意不要放在< /head>的后面)。

    修改_config.yml

    打开皮肤目录下的_config.yml 配置文件,添加如下代码:

    # background settings
    # add canvas-nest effect
    # see detail from https://github.com/hustcc/canvas-nest.js
    canvas_nest: true
    

    设置

    动态背景的某些属性可以自定义,

    {% if theme.canvas_nest %}
    <script type="text/javascript"
    color="0,0,255" opacity='0.7' zIndex="-2" count="99" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
    {% endif %}
    
    • color :线条颜色, 默认: '0,0,0';三个数字分别为(R,G,B)
    • opacity: 线条透明度(0~1), 默认: 0.5
    • count: 线条的总数量, 默认: 150
    • zIndex: 背景的z-index属性,css属性用于控制所在层的位置, 默认: -1

    重新clean并生成。

    网站底部字数统计&文章字数统计功能

    效果

    4.png 5.png

    实现

    安装插件:

    $ npm install hexo-wordcount --save
    

    修改主题配置文件

    # Post wordcount display settings
    # Dependencies: https://github.com/willin/hexo-wordcount
    post_wordcount:
      item_text: true
      wordcount: true
      min2read: true
      totalcount: true
      separated_meta: true
    

    网站的图标Favicon

    把图标文件favicon.ico 放在/themes/next/source/images里,并且修改主题配置文件:

    # Put your favicon.ico into `hexo-site/source/` directory.
    favicon: /favicon.ico
    

    在文章底部增加版权信息

    效果

    6.png

    实现

    在目录 /themes/next/layout/_macro/下添加 my-copyright.swig文件:

    {% if page.copyright %}
    <div class="my_post_copyright">
      <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
    
      <!-- JS库 sweetalert 可修改路径 -->
      <script type="text/javascript" src="http://jslibs.wuxubj.cn/sweetalert_mini/jquery-1.7.1.min.js"></script>
      <script src="http://jslibs.wuxubj.cn/sweetalert_mini/sweetalert.min.js"></script>
      <link rel="stylesheet" type="text/css" href="http://jslibs.wuxubj.cn/sweetalert_mini/sweetalert.mini.css">
      <p><span>本文标题:</span><a href="{{ url_for(page.path) }}">{{ page.title }}</a></p>
      <p><span>文章作者:</span><a href="/" title="访问 {{ theme.author }} 的个人博客">{{ theme.author }}</a></p>
      <p><span>发布时间:</span>{{ page.date.format("YYYY年MM月DD日 - HH:MM") }}</p>
      <p><span>最后更新:</span>{{ page.updated.format("YYYY年MM月DD日 - HH:MM") }}</p>
      <p><span>原始链接:</span><a href="{{ url_for(page.path) }}" title="{{ page.title }}">{{ page.permalink }}</a>
        <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="{{ page.permalink }}"  aria-label="复制成功!"></i></span>
      </p>
      <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
    </div>
    <script> 
        var clipboard = new Clipboard('.fa-clipboard');
        clipboard.on('success', $(function(){
          $(".fa-clipboard").click(function(){
            swal({   
              title: "",   
              text: '复制成功',   
              html: false,
              timer: 500,   
              showConfirmButton: false
            });
          });
        }));  
    </script>
    {% endif %}
    

    在目录/themes/next/source/css/_common/components/post/下添加my-post-copyright.styl文件:

    .my_post_copyright {
      width: 85%;
      max-width: 45em;
      margin: 2.8em auto 0;
      padding: 0.5em 1.0em;
      border: 1px solid #d3d3d3;
      font-size: 0.93rem;
      line-height: 1.6em;
      word-break: break-all;
      background: rgba(255,255,255,0.4);
    }
    .my_post_copyright p{margin:0;}
    .my_post_copyright span {
      display: inline-block;
      width: 5.2em;
      color: #b5b5b5;
      font-weight: bold;
    }
    .my_post_copyright .raw {
      margin-left: 1em;
      width: 5em;
    }
    .my_post_copyright a {
      color: #808080;
      border-bottom:0;
    }
    .my_post_copyright a:hover {
      color: #a3d2a3;
      text-decoration: underline;
    }
    .my_post_copyright:hover .fa-clipboard {
      color: #000;
    }
    .my_post_copyright .post-url:hover {
      font-weight: normal;
    }
    .my_post_copyright .copy-path {
      margin-left: 1em;
      width: 1em;
      +mobile(){display:none;}
    }
    .my_post_copyright .copy-path:hover {
      color: #808080;
      cursor: pointer;
    }
    

    修改/themes/next/layout/_macro/post.swig文件,在代码

    {% if theme.wechat_subscriber.enabled and not is_index %}
      <div>
        {% include 'wechat-subscriber.swig' %}
      </div>
    {% endif %}
    

    之前添加增加如下代码:

    {% if not is_index %}
          <div>
            {% include 'my-copyright.swig' %}
          </div>
    {% endif %}
    

    修改/themes/next/source/css/_common/components/post/post.styl文件,在最后一行增加代码:

    @import "my-post-copyright"
    

    保存重新生成即可。

    隐藏网页底部hexo和主题信息

    7.png

    打开/themes/next/layout/_partials/footer.swig,注释掉下述代码:

    8.png

    相关文章

      网友评论

        本文标题:hexo6--next美化整理

        本文链接:https://www.haomeiwen.com/subject/ikrfbxtx.html