Hexo搭建个人博客

2019-12-31  本文已影响0人  淡退

准备环境

  1. 安装 Node
  2. 安装 Git
  3. 注册码云或者github
  4. 安装 Hexo
npm install hexo-cli -g
image

搭建本地个人博客

初始化 hexo

hexo init
image

生成静态页面

hexo g

启动本地服务

hexo s
image

美化个人博客

博客主题设置

克隆主题

git clone https://github.com/theme-next/hexo-theme-next.git
image

配置主题

image

测试主题

image

发布文章

hexo new "此处输入文章名字"
image

front-matte 书写的时候要注意,冒号后面要跟一个空格号

---
title: a
date: 2019-04-14 23:10:17
---
image
hexo g

主题风格设置

博客左侧栏设置

image
image
image

分类设置

添加分类列表

hexo new page categories
image image image image

如何将文章添加到对应分类?

标签设置

Hexo 博客添加站内搜索

npm install hexo-generator-search --save
npm install hexo-generator-searchdb --save
search:
  path: search.xml
  field: post
  format: html
  limit: 10000

博客头像设置

添加博客头像

设置头像圆角并旋转打开

.site-author-image {
  display: block;
  margin: 0 auto;
  padding: $site-author-image-padding;
  max-width: $site-author-image-width;
  height: $site-author-image-height;
  border: $site-author-image-border-width solid $site-author-image-border-color;
  /* 头像圆形 */
  border-radius: 80px;
  -webkit-border-radius: 80px;
  -moz-border-radius: 80px;
  box-shadow: inset 0 -1px 0 #333sf;
  /* 设置循环动画 [animation: (play)动画名称 (2s)动画播放时长单位秒或微秒 (ase-out)动画播放的速度曲线为以低速结束 
    (1s)等待1秒然后开始动画 (1)动画播放次数(infinite为循环播放) ]*/
 
  /* 鼠标经过头像旋转360度 */
  -webkit-transition: -webkit-transform 1.0s ease-out;
  -moz-transition: -moz-transform 1.0s ease-out;
  transition: transform 1.0s ease-out;
}
img:hover {
  /* 鼠标经过停止头像旋转 
  -webkit-animation-play-state:paused;
  animation-play-state:paused;*/
  /* 鼠标经过头像旋转360度 */
  -webkit-transform: rotateZ(360deg);
  -moz-transform: rotateZ(360deg);
  transform: rotateZ(360deg);
}
/* Z 轴旋转动画 */
@-webkit-keyframes play {
  0% {
    -webkit-transform: rotateZ(0deg);
  }
  100% {
    -webkit-transform: rotateZ(-360deg);
  }
}
@-moz-keyframes play {
  0% {
    -moz-transform: rotateZ(0deg);
  }
  100% {
    -moz-transform: rotateZ(-360deg);
  }
}
@keyframes play {
  0% {
    transform: rotateZ(0deg);
  }
  100% {
    transform: rotateZ(-360deg);
  }
}

网页背景设置

body{
    background:url(/images/bg.jpg);
    background-size:cover;
    background-repeat:no-repeat;
    background-attachment:fixed;
    background-position:center;
    // 设置主题部分的透明度,具体看图
    opacity: 0.8;
}

效果图如下:


image

首页文章预览设置

这种方法可以根据文章的内容,自己在合适的位置添加 < !–more–> 标签,使用灵活,也是Hexo推荐的方法。

在文章的 front-matter 中添加 description 和 photos 字段,如下图所示。如果不需要显示图片的话,可以把 photos 去掉。
ps:不知道 front-matter 是什么的话,跳转到第二章的第4点的发布文章看下。


image

在主题文件下的_config.yml配置文件中添加默认截取的长度为 150 字符,可以根据需要自行设定。

设置网站图片 Favicon

网页顶部进度加载条设置

image

博客置顶设置

npm uninstall hexo-generator-index --save
npm install hexo-generator-index-pin-top --save
---
title: this is my first blog
date: 2019-04-14
top: 100
---

-在主题文件夹中打开 layout/_macro/post.swig 文件,定位到 post-header ,把下面的代码添加进去即可。

{% if post.top %}
  <i class="fa fa-thumb-tack"></i>
  <font color=7D26CD>置顶</font>
{% endif %}
image

参考文章:

上一篇下一篇

猜你喜欢

热点阅读