【JS】实现一个hexo插件并发布
- hexo插件生成
在你的 hexo blog 目录,找到 node_modules. 新建一个文件夹。然后执行 npm init
npm 会引导你生成 package.json 这是你的包的描述文件。需要注意的是,所有的 hexo 插件必须以 hexo - 开头,否则 hexo 不会加载。 -  
  
- 如果hexo g中没看到插件的调试信息
检查package.json是否写对
插件的index.js是否写对(用node filename检查语法错误),注意最后要调用这个函数
插件是否放入blog/plugins/ 
 - 如果hexo g中没看到插件的调试信息
 
npm init
#修改 hexo 的 package.json, 新增一行到 dependency:
"hexo-remote-writting": "^0.0.1",
#每次执行 hexo g 或者 hexo s, 都会看到插件的 log, 证明插件已经运行了。
 
//index.js
function my_plugin1(hexo) {
    hexo.extend.filter.register('after_generate', function () {
	console.log('66666666666');     
	// 插件加载时输出日志
  	hexo.log.info('Plugin loaded!');
};
//index.js
hexo.extend.filter.register('before_generate', function(){
	console.log("this is from remote writting:");
	console.log(typeof(hexo.locals.get('posts')));//object
	const content=hexo.locals.get('posts').data;
	const dates=[]
	content.forEach(element => {
		//console.log(element.title,element.date.toISOString().substring(0,10));
		dates.push(element.date.toISOString().substring(0,10));
	});
	console.log(dates);
	return dates;
});
 
- 挂在hexo官网上

注意要养成一个良好的习惯就是git add .之前先git pull origin main - 发布在npm上
先注册一个npm账号 
npm login
#如果没有进入正常的登录流程
npm config set registry https://registry.npmjs.org/
#发布
npm publish
#删除包
npm --force unpublish package_name
#废弃不在维护 但仍存在可用
npm deprecate --force js-util-libs@1.0.0 "这个包不在维护了。"
#更新包 先把package.json改version版本号 然后再
npm publish
 
Shields.io之Static Badge
就是这种效果 在readme中注明npm仓库及版本之类的
 
#展示版本

#展示下载次数

 

