hexo的butterfly主题美化,2024年初版

前言:被同事拉入hexo坑后,他直接推荐我使用butterfly主题,网上很多美化要么用不起,要么有问题,经过一系列踩坑后诞生了这篇文章,不定时更新新功能......

欢迎各位大佬分享/提供新的butterfly主题优化教程,非常感谢!!

先贴上butterfly主题作者的官方美化文档地址,如果有大佬比较会的可以直接看他的(不过部分功能可能用不了了):Butterfly 安裝文檔(一) 快速開始 | Butterfly

注意!!!如果发现配置不生效,请hexo clean然后清除浏览器缓存试试,如果还是不行,请检查配置文件的缩进是否有问题!!!

1. 准备工作

1.1 安装butterfly

在hexo的根目录下键入以下命令:

npm i hexo-theme-butterfly

1.2 修改配置文件,应用butterfly主题

修改 _config.yml 中的 theme 属性为 butterfly

1.3 安装插件

如果你没有 pug 以及 stylus 的渲染器,请下载安装

在hexo根目录下键入以下命令:

npm install hexo-renderer-pug hexo-renderer-stylus --save

1.4 推荐操作,复制一份butterfly主题专用的配置文件

在 hexo 的根目录创建一个文件 _config.butterfly.yml 后续对butterfly主题的美化配置就在该配置文件下进行修改就可以了~

层级关系如下图所示:

1.5 设置一个图片存储目录

在 source 目录下新建一个 image 文件夹,方便后续存储展示用的相关图片(名字你可以随便取

层级关系如下

2. 网站资料配置

_config.yml 文件里配置!

对应效果如图:

 3. 导航栏配置

这里我直接copy展示用的代码了(毕竟完全不会

nav:
  logo: /image/test.gif
  display_title: true
  fixed: false # fixed navigation bar    
post_asset_folder: true  
menu:
  首页: / || fas fa-home
  时间轴: /archives/ || fas fa-archive
  标签: /tags/ || fas fa-tags
  分类: /categories/ || fas fa-folder-open
  清单||fa fa-heartbeat:
    音乐: /music/ || fas fa-music
    照片: /Gallery/ || fas fa-images
    电影: /movies/ || fas fa-video

效果(搜索是额外配的,后面会说):

 4. 修改头像

将你喜欢的头像复制到之前配置的image文件夹里,路径如图所示:

然后在你复制出来的主题配置文件,也就是  _config.butterfly.yml 中添加如下配置:

#头像
avatar:
  img: /image/miku.jpg
  # effect: true # 头像会一直转,转的贼快,太鬼畜了

5. 顶部图设置

代码如下:

#顶部图
index_img: /image/miku.jpg
default_top_img: /image/miku.jpg
index_top_img_height: 400px #顶部图高度

效果:

tips:

  1. 感觉400px差不多了,或者默认就是全屏,但是全屏得往下拉才能看见博客。对于萌新不是很友好,我第一次进就是发现找半天找不到博客在哪
  2. 图片不要被宽屏误导了,请选择竖屏展示的图片,且清晰度越高越好(不然就是糊的)
  3. 经过观察,设置为400px时,展示的图片位置大概就在中间,所以最好选择你最想展示的部分为中间的图片~

6. 统计功能

推荐使用百度的api,首先你需要到百度统计官网申请id:

百度统计——一站式智能数据分析与应用平台

具体咋申请我忘了......自己多找找看吧 

问号后面的代码就是id,在 _config.yml 中添加如下配置

baidu_analytics: 你的id

7. 运行时间

 代码如下:

runtimeshow:
  enable: true
  publish_date: 1/4/2024 00:00:00

publish_date 就是你博客的创建时间,格式是 日/月/年 

效果:

8. 本地搜索

在主题配置文件下 _config.butterfly.yml 加入如下代码:

local_search:
  enable: true
  # Preload the search data when the page loads.
  preload: false
  # Show top n results per article, show all results by setting to -1
  top_n_per_article: 1
  # Unescape html strings to the readable one.
  unescape: true
  CDN:

效果:

9. 背景特效

详见官方文档:Butterfly 安裝文檔(四) 主題配置-2 | Butterfly

我的博客选的是动态彩带,代码如下:

canvas_fluttering_ribbon:
  enable: true
  mobile: false # false 手机端不显示 true 手机端显示

10. 鼠标点击特效

目前官方文档中鼠标点击特效的文字特效已无法使用(截至2024/1/18),目前我的博客采用的是爱心效果,代码如下:

# 点击出现爱心
click_heart:
  enable: true
  mobile: false

11. 网站副标题(循环打字特效)

添加如下代码即可(速度我已经进行了相应调整,您可以根据自己的喜好进行修改):

# 主页subtitle
subtitle:
  enable: true
  # Typewriter Effect (打字效果)
  effect: true
  startDelay: 300 # time before typing starts in milliseconds
  typeSpeed: 200 # type speed in milliseconds
  backSpeed: 800 # backspacing speed in milliseconds
  # loop (循环打字)
  loop: true
  # source 调用三方服务
  # source: false 开关调用
  # subtitle 会先显示 source , 再显示 sub 的內容
  source: true
  # 如果关闭打字效果,subtitle 只会显示 sub 的第一行文字
  sub:
    - 自小刺头深草里 , 而今渐觉出蓬蒿
    - 时人不识凌云木 , 直待凌云始道高

效果:

12. 页面加载动画

在主题配置文件 _config.butterfly.yml 加入以下代码即可:

#加载动画
preloader:
  enable: true
  source: 1 #可选值1=fullpage或2=progress bar,可查看https://codebyzach.github.io/pace/
  pace_css_url: 

效果:

这个加载动画是butterfly默认的,目前在百度上没有找到可以直接使用的加载动画代码或url,只能凑合着用了,呃呃。

13. 池塘养鱼

在主题配置文件 _config.butterfly.yml 加入以下代码即可:

inject:
  head:
    
  bottom:
       - <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
       - <script src="https://cdn.jsdelivr.net/gh/xiabo2/CDN@latest/fishes.js"></script>

有时候会遇到cdn解析失败,导致鱼塘加载不出来,建议还是以js文件格式本地引入,操作方法见下👇👇👇

13.1 在 source 目录下新建一个 styles 文件夹,用于存放相关文件

层级如下:

13.2 添加如下两个文件

注意:这两个文件的目录是基于我设置的styles目录下,如果你的文件夹名称是你自己设置的,请同步修改文件中涉及到的文件引用地址路径!!!

文件一:fish-base.js

var RENDERER = {
	POINT_INTERVAL : 5,
	FISH_COUNT : 3,
	MAX_INTERVAL_COUNT : 50,
	INIT_HEIGHT_RATE : 0.5,
	THRESHOLD : 50,
	
	init : function(){
		this.setParameters();
		this.reconstructMethods();
		this.setup();
		this.bindEvent();
		this.render();
	},
	setParameters : function(){
		this.$window = $(window);
		this.$container = $('#jsi-flying-fish-container');
		this.$canvas = $('<canvas />');
		this.context = this.$canvas.appendTo(this.$container).get(0).getContext('2d');
		this.points = [];
		this.fishes = [];
		this.watchIds = [];
	},
	createSurfacePoints : function(){
		var count = Math.round(this.width / this.POINT_INTERVAL);
		this.pointInterval = this.width / (count - 1);
		this.points.push(new SURFACE_POINT(this, 0));
		
		for(var i = 1; i < count; i++){
			var point = new SURFACE_POINT(this, i * this.pointInterval),
				previous = this.points[i - 1];
				
			point.setPreviousPoint(previous);
			previous.setNextPoint(point);
			this.points.push(point);
		}
	},
	reconstructMethods : function(){
		this.watchWindowSize = this.watchWindowSize.bind(this);
		this.jdugeToStopResize = this.jdugeToStopResize.bind(this);
		this.startEpicenter = this.startEpicenter.bind(this);
		this.moveEpicenter = this.moveEpicenter.bind(this);
		this.reverseVertical = this.reverseVertical.bind(this);
		this.render = this.render.bind(this);
	},
	setup : function(){
		this.points.length = 0;
		this.fishes.length = 0;
		this.watchIds.length = 0;
		this.intervalCount = this.MAX_INTERVAL_COUNT;
		this.width = this.$container.width();
		this.height = this.$container.height();
		this.fishCount = this.FISH_COUNT * this.width / 500 * this.height / 500;
		this.$canvas.attr({width : this.width, height : this.height});
		this.reverse = false;
		
		this.fishes.push(new FISH(this));
		this.createSurfacePoints();
	},
	watchWindowSize : function(){
		this.clearTimer();
		this.tmpWidth = this.$window.width();
		this.tmpHeight = this.$window.height();
		this.watchIds.push(setTimeout(this.jdugeToStopResize, this.WATCH_INTERVAL));
	},
	clearTimer : function(){
		while(this.watchIds.length > 0){
			clearTimeout(this.watchIds.pop());
		}
	},
	jdugeToStopResize : function(){
		var width = this.$window.width(),
			height = this.$window.height(),
			stopped = (width == this.tmpWidth && height == this.tmpHeight);
			
		this.tmpWidth = width;
		this.tmpHeight = height;
		
		if(stopped){
			this.setup();
		}
	},
	bindEvent : function(){
		this.$window.on('resize', this.watchWindowSize);
		this.$container.on('mouseenter', this.startEpicenter);
		this.$container.on('mousemove', this.moveEpicenter);
		this.$container.on('click', this.reverseVertical);
	},
	getAxis : function(event){
		var offset = this.$container.offset();
		
		return {
			x : event.clientX - offset.left + this.$window.scrollLeft(),
			y : event.clientY - offset.top + this.$window.scrollTop()
		};
	},
	startEpicenter : function(event){
		this.axis = this.getAxis(event);
	},
	moveEpicenter : function(event){
		var axis = this.getAxis(event);
		
		if(!this.axis){
			this.axis = axis;
		}
		this.generateEpicenter(axis.x, axis.y, axis.y - this.axis.y);
		this.axis = axis;
	},
	generateEpicenter : function(x, y, velocity){
		if(y < this.height / 2 - this.THRESHOLD || y > this.height / 2 + this.THRESHOLD){
			return;
		}
		var index = Math.round(x / this.pointInterval);
		
		if(index < 0 || index >= this.points.length){
			return;
		}
		this.points[index].interfere(y, velocity);
	},
	reverseVertical : function(){
		this.reverse = !this.reverse;
		
		for(var i = 0, count = this.fishes.length; i < count; i++){
			this.fishes[i].reverseVertical();
		}
	},
	controlStatus : function(){
		for(var i = 0, count = this.points.length; i < count; i++){
			this.points[i].updateSelf();
		}
		for(var i = 0, count = this.points.length; i < count; i++){
			this.points[i].updateNeighbors();
		}
		if(this.fishes.length < this.fishCount){
			if(--this.intervalCount == 0){
				this.intervalCount = this.MAX_INTERVAL_COUNT;
				this.fishes.push(new FISH(this));
			}
		}
	},
	render : function(){
		requestAnimationFrame(this.render);
		this.controlStatus();
		this.context.clearRect(0, 0, this.width, this.height);
		this.context.fillStyle = 'hsl(0, 0%, 95%)';
		
		for(var i = 0, count = this.fishes.length; i < count; i++){
			this.fishes[i].render(this.context);
		}
		this.context.save();
		this.context.globalCompositeOperation = 'xor';
		this.context.beginPath();
		this.context.moveTo(0, this.reverse ? 0 : this.height);
		
		for(var i = 0, count = this.points.length; i < count; i++){
			this.points[i].render(this.context);
		}
		this.context.lineTo(this.width, this.reverse ? 0 : this.height);
		this.context.closePath();
		this.context.fill();
		this.context.restore();
	}
};
var SURFACE_POINT = function(renderer, x){
	this.renderer = renderer;
	this.x = x;
	this.init();
};
SURFACE_POINT.prototype = {
	SPRING_CONSTANT : 0.03,
	SPRING_FRICTION : 0.9,
	WAVE_SPREAD : 0.3,
	ACCELARATION_RATE : 0.01,
	
	init : function(){
		this.initHeight = this.renderer.height * this.renderer.INIT_HEIGHT_RATE;
		this.height = this.initHeight;
		this.fy = 0;
		this.force = {previous : 0, next : 0};
	},
	setPreviousPoint : function(previous){
		this.previous = previous;
	},
	setNextPoint : function(next){
		this.next = next;
	},
	interfere : function(y, velocity){
		this.fy = this.renderer.height * this.ACCELARATION_RATE * ((this.renderer.height - this.height - y) >= 0 ? -1 : 1) * Math.abs(velocity);
	},
	updateSelf : function(){
		this.fy += this.SPRING_CONSTANT * (this.initHeight - this.height);
		this.fy *= this.SPRING_FRICTION;
		this.height += this.fy;
	},
	updateNeighbors : function(){
		if(this.previous){
			this.force.previous = this.WAVE_SPREAD * (this.height - this.previous.height);
		}
		if(this.next){
			this.force.next = this.WAVE_SPREAD * (this.height - this.next.height);
		}
	},
	render : function(context){
		if(this.previous){
			this.previous.height += this.force.previous;
			this.previous.fy += this.force.previous;
		}
		if(this.next){
			this.next.height += this.force.next;
			this.next.fy += this.force.next;
		}
		context.lineTo(this.x, this.renderer.height - this.height);
	}
};
var FISH = function(renderer){
	this.renderer = renderer;
	this.init();
};
FISH.prototype = {
	GRAVITY : 0.4,
	
	init : function(){
		this.direction = Math.random() < 0.5;
		this.x = this.direction ? (this.renderer.width + this.renderer.THRESHOLD) : -this.renderer.THRESHOLD;
		this.previousY = this.y;
		this.vx = this.getRandomValue(4, 10) * (this.direction ? -1 : 1);
		
		if(this.renderer.reverse){
			this.y = this.getRandomValue(this.renderer.height * 1 / 10, this.renderer.height * 4 / 10);
			this.vy = this.getRandomValue(2, 5);
			this.ay = this.getRandomValue(0.05, 0.2);
		}else{
			this.y = this.getRandomValue(this.renderer.height * 6 / 10, this.renderer.height * 9 / 10);
			this.vy = this.getRandomValue(-5, -2);
			this.ay = this.getRandomValue(-0.2, -0.05);
		}
		this.isOut = false;
		this.theta = 0;
		this.phi = 0;
	},
	getRandomValue : function(min, max){
		return min + (max - min) * Math.random();
	},
	reverseVertical : function(){
		this.isOut = !this.isOut;
		this.ay *= -1;
	},
	controlStatus : function(context){
		this.previousY = this.y;
		this.x += this.vx;
		this.y += this.vy;
		this.vy += this.ay;
		
		if(this.renderer.reverse){
			if(this.y > this.renderer.height * this.renderer.INIT_HEIGHT_RATE){
				this.vy -= this.GRAVITY;
				this.isOut = true;
			}else{
				if(this.isOut){
					this.ay = this.getRandomValue(0.05, 0.2);
				}
				this.isOut = false;
			}
		}else{
			if(this.y < this.renderer.height * this.renderer.INIT_HEIGHT_RATE){
				this.vy += this.GRAVITY;
				this.isOut = true;
			}else{
				if(this.isOut){
					this.ay = this.getRandomValue(-0.2, -0.05);
				}
				this.isOut = false;
			}
		}
		if(!this.isOut){
			this.theta += Math.PI / 20;
			this.theta %= Math.PI * 2;
			this.phi += Math.PI / 30;
			this.phi %= Math.PI * 2;
		}
		this.renderer.generateEpicenter(this.x + (this.direction ? -1 : 1) * this.renderer.THRESHOLD, this.y, this.y - this.previousY);
		
		if(this.vx > 0 && this.x > this.renderer.width + this.renderer.THRESHOLD || this.vx < 0 && this.x < -this.renderer.THRESHOLD){
			this.init();
		}
	},
	render : function(context){
		context.save();
		context.translate(this.x, this.y);
		context.rotate(Math.PI + Math.atan2(this.vy, this.vx));
		context.scale(1, this.direction ? 1 : -1);
		context.beginPath();
		context.moveTo(-30, 0);
		context.bezierCurveTo(-20, 15, 15, 10, 40, 0);
		context.bezierCurveTo(15, -10, -20, -15, -30, 0);
		context.fill();
		
		context.save();
		context.translate(40, 0);
		context.scale(0.9 + 0.2 * Math.sin(this.theta), 1);
		context.beginPath();
		context.moveTo(0, 0);
		context.quadraticCurveTo(5, 10, 20, 8);
		context.quadraticCurveTo(12, 5, 10, 0);
		context.quadraticCurveTo(12, -5, 20, -8);
		context.quadraticCurveTo(5, -10, 0, 0);
		context.fill();
		context.restore();
		
		context.save();
		context.translate(-3, 0);
		context.rotate((Math.PI / 3 + Math.PI / 10 * Math.sin(this.phi)) * (this.renderer.reverse ? -1 : 1));
		
		context.beginPath();
		
		if(this.renderer.reverse){
			context.moveTo(5, 0);
			context.bezierCurveTo(10, 10, 10, 30, 0, 40);
			context.bezierCurveTo(-12, 25, -8, 10, 0, 0);
		}else{
			context.moveTo(-5, 0);
			context.bezierCurveTo(-10, -10, -10, -30, 0, -40);
			context.bezierCurveTo(12, -25, 8, -10, 0, 0);
		}
		context.closePath();
		context.fill();
		context.restore();
		context.restore();
		this.controlStatus(context);
	}
};
$(function(){
	RENDERER.init();
});

文件二:fish.js

fish();
function fish() {
    return (
      $("#footer-wrap").css({
        position: "absolute",
        "text-align": "center",
        top: 0,
        right: 0,
        left: 0,
        bottom: 0,
      }),
      $("footer").append(
        '<div class="container" id="jsi-flying-fish-container"></div>'
      ),
      $("body").append(
        '<script src="/styles/fish-base.js"></script>'
      ),
      this
    );
  }

13.3 在主题配置文件下引入这两个文件

代码如下:

- <script src="/styles/fish.js"></script>

一样也得引入 jquery:

- <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>

层级关系如图所示:

14. 渐变色设置

在styles目录下新建一个 main.css 文件,键入以下代码:

/* 鱼塘固定宽度 */
canvas:not(#ribbon-canvas), #web_bg {
    margin-bottom: -0.5rem;
    display: block;
    width: 100%;
    height: 160px
}

/* 鱼塘渐变色 */
body{
 overflow-x: hidden;
}
#footer {
 height:160px;
 background: linear-gradient(
  135deg,
  rgba(23, 23, 116, 0.2),
  rgba(28, 181, 224, 0.2)
 );
}
#footer #footer-wrap,
#footer-wrap a {
 color: #000;
}
#footer #footer-wrap {
 z-index: 1;
}

#footer .container {
 line-height: 0;
 position: relative;
 height: 100%;
 width: 100vw;
}

/* 侧边栏个人信息卡片动态渐变色 */
#aside-content>.card-widget.card-info{
    background: linear-gradient(-45deg, rgba(255, 225, 245, 0.6), 
rgba(255, 225, 225, 0.9), 
rgba(225, 255, 251, 0.9), 
rgba(255, 225, 255, 0.6));
}
[data-theme=dark] #aside-content>.card-widget.card-info {
    background: linear-gradient(-45deg, rgb(225, 238, 255), 
    rgba(225, 255, 253, 0.9), 
    rgba(225, 243, 255, 0.9), 
    rgba(255, 225, 253, 0.6));
}
/* 侧边栏公告栏卡片渐变色 */
#aside-content>.card-widget.card-announcement{
    background: linear-gradient(-45deg, rgba(255, 225, 245, 0.6), 
    rgba(255, 225, 225, 0.9), 
    rgba(225, 255, 251, 0.9), 
    rgba(255, 225, 255, 0.6));
}
[data-theme=dark] #aside-content>.card-widget.card-announcement{
    background: linear-gradient(-45deg, rgba(255, 225, 245, 0.6), 
    rgba(255, 225, 225, 0.9), 
    rgba(225, 255, 251, 0.9), 
    rgba(255, 225, 255, 0.6));
}
/* 侧边栏目录最新文章卡片渐变色 */
#aside-content>.sticky_layout>.card-widget{
    background: linear-gradient(-45deg, rgba(255, 225, 245, 0.6), 
    rgba(255, 225, 225, 0.9), 
    rgba(225, 255, 251, 0.9), 
    rgba(255, 225, 255, 0.6));
}
[data-theme=dark] #aside-content>.sticky_layout>.card-widget{
    background: linear-gradient(-45deg, rgba(255, 225, 245, 0.6), 
    rgba(255, 225, 225, 0.9), 
    rgba(225, 255, 251, 0.9), 
    rgba(255, 225, 255, 0.6));
}
/* 个人信息Follow me按钮 */
#aside-content>.card-widget.card-info>#card-info-btn {
    background-color: #3eb8be;
    border-radius: 8px;
}
/*文章页面*/
/* .layout>#post {
    background: linear-gradient(-45deg, rgba(225, 255, 252, 0.8), 
rgba(255, 225, 229, 0.9), 
rgba(225, 255, 225, 0.9), 
rgba(253, 255, 225, 0.8));
}
[data-theme=dark] .layout>#post {
    background: linear-gradient(-45deg, rgba(24,40,72,.2), 
rgba(35,37,58,.9), 
rgba(35,37,58,.9), 
rgba(24,40,72,.2));
} */
/*主页文章预览页面*/
#recent-posts>.recent-post-item{
    background: linear-gradient(-45deg, rgba(225, 255, 252, 0.8), 
    rgba(255, 225, 229, 0.9), 
    rgba(225, 255, 225, 0.9), 
    rgba(253, 255, 225, 0.8));
}
[data-theme=dark] #recent-posts>.recent-post-item{
    background: linear-gradient(-45deg, rgba(24,40,72,.2), 
rgba(35,37,58,.9), 
rgba(35,37,58,.9), 
rgba(24,40,72,.2));
}

/*分类页面*/
.layout>#page {
    background: linear-gradient(-45deg, rgba(225,235,255,.8), 
rgba(225,235,255,.9), 
rgba(225,235,255,.9), 
rgba(225,235,255,.8));
}
[data-theme=dark] .layout>#page {
    background: linear-gradient(-45deg, rgba(24,40,72,.2), 
rgba(35,37,58,.9), 
rgba(35,37,58,.9), 
rgba(24,40,72,.2));
}

/*时间轴页面*/
.layout>#archive {
    background: linear-gradient(-45deg, rgba(225,235,255,.8), 
rgba(225,235,255,.9), 
rgba(225,235,255,.9), 
rgba(225,235,255,.8));
}
[data-theme=dark] .layout>#archive {
    background: linear-gradient(-45deg, rgba(24,40,72,.2), 
rgba(35,37,58,.9), 
rgba(35,37,58,.9), 
rgba(24,40,72,.2));
}

这里我只修改了鱼塘和部分个人主页的渐变色,懂前端或美学的你可以自己调成你喜欢的渐变色。

比较简单粗暴的改法可看这张图片,点点点就完事了

同样,也需要在主题配置文件中引入这个css文件:

- <link rel="stylesheet" href="/styles/main.css">

层级关系如下图所示:

15. 浏览器图标修改

先找一个你喜欢的图标,注意格式需为32*32。可以从阿里的矢量图库中下载自己喜欢的:

iconfont-阿里巴巴矢量图标库

保存后放在image文件夹内(或者你自己自定义存图片的文件夹):

 在你的主题配置文件内添加如下代码即可:

favicon: /image/动物.png

 效果如图所示:

16. 添加域名备案信息(butterfly主题) 

之前被同事忽悠下搞了个域名,.site的才1.8一年,还是挺香的。买了之后直接解析发现还蛮不错的,不用输难记的ip地址了。但是第二天就被tx云ban了......然后才发现在拆那搞域名是多么的复杂与麻烦。听一句劝,不想麻烦还是别搞了.......

当你经过七七八八的审核之后,恭喜你拿到了属于你个人的域名!!!congratulations~~~

然后tx云就会提醒你必须在网站页脚处公示自己的icp备案号,否则被工信部逮到了又要罚款5k到1w元不等.......这风险也太大了......要是哪个黑客把我页面黑了然后把域名信息给我删了,我找谁说理去。(而且人家还可以通过备案号直接查到你真实姓名叫啥,把我这个社恐整的怪不好意思的,都不敢让没面基过的网友逛我博客)

在度娘找了半天,终于找到了butterfly主题的配置方法

在你的主题配置文件下加入以下代码:

footer:
  owner:
    enable: true
    since: 2024
  custom_text: <img src="https://haiyong.site/img/icp.png"><a href="https://beian.miit.gov.cn/#/Integrated/index" style="color:black" target="_blank">xICP备xxx号-1(你的icp备案号)</a>
  copyright: true

层级关系如下:

 然后老样子hexo clean,重启,你的页脚上就有域名icp备案相关信息了:

17. nginx配置监听转发

hexo默认端口是4000,别人通过域名访问时又不想让别人输网址的时候再加4000端口,那就用默认的80端口。但宝塔的linux使用80启动项目直接就起不了,所以干脆用nginx代理转发算了。

17.1 安装nginx

宝塔有可视化面板直接装nginx,但是等的时间巨长,都够你打把游戏了。同事说用命令行贼快,但是程序员都很懒,我还是选择可视化安装,毕竟后面重启、改配置啥的都不用跑命令了,全可视化操作。

17.2 转发配置

安装好后加入如下配置,如果有的话直接替换就行了:

server{
  listen 80; # 监听的端口
  server_name  xxxx; # 监听的地址,相当于就是你的域名地址
  index  index.php index.html index.htm;
 
  location / {
    proxy_pass xxxx; # 转发地址,带上端口号
    proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

 搞完了记得重启nginx!!!

 搞完了记得重启nginx!!!

 搞完了记得重启nginx!!!

此时恭喜你,可以通过域名直接访问你的个人博客了~~~就是有点慢,自娱自乐还是挺可以的,挺有成就感的~~~

18. 搬运自己的csdn文章到hexo

百度一搜一大堆,这里自己简单总结下:

18.1 获取文章信息

打开自己写的文章,打开开发者模式(F12),搜索article_content

18.2 将复制的文章信息转换为md格式

进入下方网站,按照序号操作,最后转换的文件不用下载,可以直接全选复制到typora里操作。

markdown编辑器 - 在线工具

右边还可以直接预览md样式,对于我这种md新手来说很方便~

不过因为csdn本身直接写文章应该不算严格格式的md,例如有的段落、图片前可能会有个空格。这个在md中好像是不允许的(反正我丢hexo里面启动就报错......)自己最好在转换后多检查几下,例如宝塔中编辑md时就会对这些莫名其妙的空格标红处理,还挺方便的。

18.3 对于图片的处理

csdn是有防盗链的,所以你直接复制粘贴放到hexo上图片是加载不出来的。

方法一:另存为后复制粘贴(超级无脑)

方法二:结合之前我写的文章

腾讯云图床(对象存储)+typora+picgo实现图片一键上传-CSDN博客

全自动上传,记得开一下这个设置,会自动进行url替换

18.4 图片压缩

可以使用tx云对象存储自带的压缩,也可以自己手动压缩成webp格式。步骤如下:

Online PNG to WebP image converter

webp的展示效果还是不错的,体积压缩了不少但清晰度还是挺能打的。

后面对该图片替换就可以了~

感谢同事青花🐟的鼎力支持,让我狠狠地白嫖~

友链:www.cyanshark.cn


🌸参考文章: 

Butterfly 安裝文檔(四) 主題配置-2 | Butterfly

hexo butterfly主题添加备案信息_hexo 备案设置-CSDN博客

用Nginx做端口转发(反向代理)_nginx 端口转发-CSDN博客


后话:主题美化目前的精力只搞了这么多,慢更......

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值