补坑

之前写过一篇icarus添加看板娘的教程但是版本是<Icarus3的 Icarus3改版很大,完全使用了jsx来代替了ejs,不过添加看板娘不管是jsx还是ejs差别都不大

icarus3之前的教程博客 传送门

上一篇博客那时候拉的live2D还需要导入jQuery 2020年1月1日起,项目不再依赖于 jQuery。

这次我把live2d直接放到了主题文件夹下的source下面 跟js/css/img同级

下载live2D

进入博客根目录

cd theme/icarus/source && git clone https://github.com/stevenjoezhang/live2d-widget.git

修改配置

1. 导入css依赖

找到theme/icarus/layout/common/head.jsx 插入css依赖

大概是在一百四十多行的样子吧 或者可以在head.jsx内搜索<link>标签 然后插入这行

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>

修改后完整的head.jsx

const { Component } = require('inferno');
const MetaTags = require('hexo-component-inferno/lib/view/misc/meta');
const OpenGraph = require('hexo-component-inferno/lib/view/misc/open_graph');
const StructuredData = require('hexo-component-inferno/lib/view/misc/structured_data');
const Plugins = require('./plugins');function getPageTitle(page, siteTitle, helper) {let title = page.title;if (helper.is_archive()) {title = helper._p('common.archive', Infinity);if (helper.is_month()) {title += ': ' + page.year + '/' + page.month;} else if (helper.is_year()) {title += ': ' + page.year;}} else if (helper.is_category()) {title = helper._p('common.category', 1) + ': ' + page.category;} else if (helper.is_tag()) {title = helper._p('common.tag', 1) + ': ' + page.tag;} else if (helper.is_categories()) {title = helper._p('common.category', Infinity);} else if (helper.is_tags()) {title = helper._p('common.tag', Infinity);}return [title, siteTitle].filter(str => typeof str !== 'undefined' && str.trim() !== '').join(' - ');
}module.exports = class extends Component {render() {const { env, site, config, helper, page } = this.props;const { url_for, cdn, fontcdn, iconcdn, is_post } = helper;const {url,meta_generator = true,head = {},article,highlight,variant = 'default'} = config;const {meta = [],open_graph = {},structured_data = {},canonical_url = page.permalink,rss,favicon} = head;const language = page.lang || page.language || config.language;const fontCssUrl = {default: fontcdn('Ubuntu:wght@400;600&family=Source+Code+Pro', 'css2'),cyberpunk: fontcdn('Oxanium:wght@300;400;600&family=Roboto+Mono', 'css2')};let hlTheme, images;if (highlight && highlight.enable === false) {hlTheme = null;} else if (article && article.highlight && article.highlight.theme) {hlTheme = article.highlight.theme;} else {hlTheme = 'atom-one-light';}if (typeof page.og_image === 'string') {images = [page.og_image];} else if (helper.has_thumbnail(page)) {images = [helper.get_thumbnail(page)];} else if (article && typeof article.og_image === 'string') {images = [article.og_image];} else if (page.content && page.content.includes('<img')) {let img;images = [];const imgPattern = /<img [^>]*src=['"]([^'"]+)([^>]*>)/gi;while ((img = imgPattern.exec(page.content)) !== null) {images.push(img[1]);}} else {images = [url_for('/img/og_image.png')];}let adsenseClientId = null;if (Array.isArray(config.widgets)) {const widget = config.widgets.find(widget => widget.type === 'adsense');if (widget) {adsenseClientId = widget.client_id;}}let openGraphImages = images;if ((typeof open_graph === 'object' && open_graph !== null)&& ((Array.isArray(open_graph.image) && open_graph.image.length > 0) || typeof open_graph.image === 'string')) {openGraphImages = open_graph.image;} else if ((Array.isArray(page.photos) && page.photos.length > 0) || typeof page.photos === 'string') {openGraphImages = page.photos;}let structuredImages = images;if ((typeof structured_data === 'object' && structured_data !== null)&& ((Array.isArray(structured_data.image) && structured_data.image.length > 0) || typeof structured_data.image === 'string')) {structuredImages = structured_data.image;} else if ((Array.isArray(page.photos) && page.photos.length > 0) || typeof page.photos === 'string') {structuredImages = page.photos;}return <head><meta charset="utf-8" />{meta_generator ? <meta name="generator" content={`Hexo ${env.version}`} /> : null}<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />{meta && meta.length ? <MetaTags meta={meta} /> : null}<meta name="baidu-site-verification" content="mhWv4NNMfG" /><meta name="google-site-verification" content="aNBCEhnauRjyRi2s55JA4LemtzHTmgcHT43vigw9Qek" /><title>{getPageTitle(page, config.title, helper)}</title>{typeof open_graph === 'object' && open_graph !== null ? <OpenGraphtype={open_graph.type || (is_post(page) ? 'article' : 'website')}title={open_graph.title || page.title || config.title}date={page.date}updated={page.updated}author={open_graph.author || config.author}description={open_graph.description || page.description || page.excerpt || page.content || config.description}keywords={page.keywords || (page.tags && page.tags.length ? page.tags : undefined) || config.keywords}url={open_graph.url || page.permalink || url}images={openGraphImages}siteName={open_graph.site_name || config.title}language={language}twitterId={open_graph.twitter_id}twitterCard={open_graph.twitter_card}twitterSite={open_graph.twitter_site}googlePlus={open_graph.google_plus}facebookAdmins={open_graph.fb_admins}facebookAppId={open_graph.fb_app_id} /> : null}{typeof structured_data === 'object' && structured_data !== null ? <StructuredDatatitle={structured_data.title || config.title}description={structured_data.description || page.description || page.excerpt || page.content || config.description}url={structured_data.url || page.permalink || url}author={structured_data.author || config.author}date={page.date}updated={page.updated}images={structuredImages} /> : null}{canonical_url ? <link rel="canonical" href={canonical_url} /> : null}{rss ? <link rel="alternative" href={url_for(rss)} title={config.title} type="application/atom+xml" /> : null}{favicon ? <link rel="icon" href={url_for(favicon)} /> : null}<link rel="stylesheet" href={iconcdn()} />{hlTheme ? <link rel="stylesheet" href={cdn('highlight.js', '9.12.0', 'styles/' + hlTheme + '.css')} /> : null}<link rel="stylesheet" href={fontCssUrl[variant]} /><link rel="stylesheet" href={url_for('/css/' + variant + '.css')} />{/* 这行是live2d需要的css依赖 */}<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/><Plugins site={site} config={config} helper={helper} page={page} head={true} />{adsenseClientId ? <script data-ad-client={adsenseClientId}src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" async={true}></script> : null}</head>;}
};
2. 修改刚下载的live2d-widget 下的autoload.js

注释掉第二行 //const live2d_path = "https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/";

放开第三行 const live2d_path = "/live2d-widget/";

修改后的autoload.js

// 注意:live2d_path 参数应使用绝对路径
//const live2d_path = "https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/";
const live2d_path = "/live2d-widget/";// 封装异步加载资源的方法
function loadExternalResource(url, type) {return new Promise((resolve, reject) => {let tag;if (type === "css") {tag = document.createElement("link");tag.rel = "stylesheet";tag.href = url;}else if (type === "js") {tag = document.createElement("script");tag.src = url;}if (tag) {tag.onload = () => resolve(url);tag.onerror = () => reject(url);document.head.appendChild(tag);}});
}// 加载 waifu.css live2d.min.js waifu-tips.js
if (screen.width >= 768) {Promise.all([loadExternalResource(live2d_path + "waifu.css", "css"),loadExternalResource(live2d_path + "live2d.min.js", "js"),loadExternalResource(live2d_path + "waifu-tips.js", "js")]).then(() => {initWidget({waifuPath: live2d_path + "waifu-tips.json",//apiPath: "https://live2d.fghrsh.net/api/",cdnPath: "https://cdn.jsdelivr.net/gh/fghrsh/live2d_api/"//cdnPath: "https://live2d.fghrsh.net/api/"});});
}
// initWidget 第一个参数为 waifu-tips.json 的路径,第二个参数为 API 地址
// API 后端可自行搭建,参考 https://github.com/fghrsh/live2d_api
// 初始化看板娘会自动加载指定目录下的 waifu-tips.json
3. 在主题内导入autoload.js

前提是 live2d-widget 的位置在theme/icarus/source

找到theme/icarus/layout/common/scripts.jsx 在末尾处 <Fragment>标签内添加

<script src={url_for('/live2d-widget/autoload.js')}></script>

添加后完整的scripts.jsx

const {Component, Fragment} = require('inferno');
const Plugins = require('./plugins');module.exports = class extends Component {render() {const {site, config, helper, page} = this.props;const {url_for, cdn} = helper;const {external_link, article} = config;const language = page.lang || page.language || config.language || 'en';let externalLink;if (typeof external_link === 'boolean') {externalLink = {enable: external_link, exclude: []};} else {externalLink = {enable: typeof external_link.enable === 'boolean' ? external_link.enable : true,exclude: external_link.exclude || []};}let fold = 'unfolded';let clipboard = true;if (article && article.highlight) {if (typeof article.highlight.clipboard !== 'undefined') {clipboard = !!article.highlight.clipboard;}if (typeof article.highlight.fold === 'string') {fold = article.highlight.fold;}}const embeddedConfig = `var IcarusThemeSettings = {site: {url: '${config.url}',external_link: ${JSON.stringify(externalLink)}},article: {highlight: {clipboard: ${clipboard},fold: '${fold}'}}};`;return <Fragment><script src={cdn('jquery', '3.3.1', 'dist/jquery.min.js')}></script><script src={cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')}></script><script dangerouslySetInnerHTML={{__html: `moment.locale("${language}");`}}></script><script dangerouslySetInnerHTML={{__html: embeddedConfig}}></script>{clipboard ? <script src={cdn('clipboard', '2.0.4', 'dist/clipboard.min.js')} defer={true}></script> : null}<Plugins site={site} config={config} page={page} helper={helper} head={false}/><script src={url_for('/js/main.js')} defer={true}></script><script src={url_for('/live2d-widget/autoload.js')}></script></Fragment>;}
};
4. 开启live2d

编辑主题配置文件_config.yml 添加

live2d:enable: true

大功告成!

备注

看板娘到这儿应该就可以出来了 但是会发现在icarus的样式下面 这时候需要把看板娘给置顶

找到live2d-widget 下的waifu.css 修改33行 id为#waifu的样式 把z-index:1 修改为z-index:1000;

修改后的waifu.css

#waifu-toggle {background-color: #fa0;border-radius: 5px;bottom: 66px;color: #fff;cursor: pointer;font-size: 12px;left: 0;margin-left: -100px;padding: 5px 2px 5px 5px;position: fixed;transition: margin-left 1s;width: 60px;writing-mode: vertical-rl;
}#waifu-toggle.waifu-toggle-active {margin-left: -50px;
}#waifu-toggle.waifu-toggle-active:hover {margin-left: -30px;
}#waifu {bottom: -1000px;left: 0;line-height: 0;margin-bottom: -10px;position: fixed;transform: translateY(3px);transition: transform .3s ease-in-out, bottom 3s ease-in-out;z-index: 1000;
}#waifu:hover {transform: translateY(0);
}#waifu-tips {animation: shake 50s ease-in-out 5s infinite;background-color: rgba(236, 217, 188, .5);border: 1px solid rgba(224, 186, 140, .62);border-radius: 12px;box-shadow: 0 3px 15px 2px rgba(191, 158, 118, .2);font-size: 14px;line-height: 24px;margin: -30px 20px;min-height: 70px;opacity: 0;overflow: hidden;padding: 5px 10px;position: absolute;text-overflow: ellipsis;transition: opacity 1s;width: 250px;word-break: break-all;
}#waifu-tips.waifu-tips-active {opacity: 1;transition: opacity .2s;
}#waifu-tips span {color: #0099cc;
}#waifu #live2d {cursor: grab;height: 280px;position: relative;width: 280px;
}#waifu #live2d:active {cursor: grabbing;
}#waifu-tool {color: #aaa;opacity: 0;position: absolute;right: -10px;top: 70px;transition: opacity 1s;
}#waifu:hover #waifu-tool {opacity: 1;
}#waifu-tool span {color: #7b8c9d;cursor: pointer;display: block;line-height: 30px;text-align: center;transition: color .3s;
}#waifu-tool span:hover {color: #0684bd; /* #34495e */
}@keyframes shake {2% {transform: translate(.5px, -1.5px) rotate(-.5deg);}4% {transform: translate(.5px, 1.5px) rotate(1.5deg);}6% {transform: translate(1.5px, 1.5px) rotate(1.5deg);}8% {transform: translate(2.5px, 1.5px) rotate(.5deg);}10% {transform: translate(.5px, 2.5px) rotate(.5deg);}12% {transform: translate(1.5px, 1.5px) rotate(.5deg);}14% {transform: translate(.5px, .5px) rotate(.5deg);}16% {transform: translate(-1.5px, -.5px) rotate(1.5deg);}18% {transform: translate(.5px, .5px) rotate(1.5deg);}20% {transform: translate(2.5px, 2.5px) rotate(1.5deg);}22% {transform: translate(.5px, -1.5px) rotate(1.5deg);}24% {transform: translate(-1.5px, 1.5px) rotate(-.5deg);}26% {transform: translate(1.5px, .5px) rotate(1.5deg);}28% {transform: translate(-.5px, -.5px) rotate(-.5deg);}30% {transform: translate(1.5px, -.5px) rotate(-.5deg);}32% {transform: translate(2.5px, -1.5px) rotate(1.5deg);}34% {transform: translate(2.5px, 2.5px) rotate(-.5deg);}36% {transform: translate(.5px, -1.5px) rotate(.5deg);}38% {transform: translate(2.5px, -.5px) rotate(-.5deg);}40% {transform: translate(-.5px, 2.5px) rotate(.5deg);}42% {transform: translate(-1.5px, 2.5px) rotate(.5deg);}44% {transform: translate(-1.5px, 1.5px) rotate(.5deg);}46% {transform: translate(1.5px, -.5px) rotate(-.5deg);}48% {transform: translate(2.5px, -.5px) rotate(.5deg);}50% {transform: translate(-1.5px, 1.5px) rotate(.5deg);}52% {transform: translate(-.5px, 1.5px) rotate(.5deg);}54% {transform: translate(-1.5px, 1.5px) rotate(.5deg);}56% {transform: translate(.5px, 2.5px) rotate(1.5deg);}58% {transform: translate(2.5px, 2.5px) rotate(.5deg);}60% {transform: translate(2.5px, -1.5px) rotate(1.5deg);}62% {transform: translate(-1.5px, .5px) rotate(1.5deg);}64% {transform: translate(-1.5px, 1.5px) rotate(1.5deg);}66% {transform: translate(.5px, 2.5px) rotate(1.5deg);}68% {transform: translate(2.5px, -1.5px) rotate(1.5deg);}70% {transform: translate(2.5px, 2.5px) rotate(.5deg);}72% {transform: translate(-.5px, -1.5px) rotate(1.5deg);}74% {transform: translate(-1.5px, 2.5px) rotate(1.5deg);}76% {transform: translate(-1.5px, 2.5px) rotate(1.5deg);}78% {transform: translate(-1.5px, 2.5px) rotate(.5deg);}80% {transform: translate(-1.5px, .5px) rotate(-.5deg);}82% {transform: translate(-1.5px, .5px) rotate(-.5deg);}84% {transform: translate(-.5px, .5px) rotate(1.5deg);}86% {transform: translate(2.5px, 1.5px) rotate(.5deg);}88% {transform: translate(-1.5px, .5px) rotate(1.5deg);}90% {transform: translate(-1.5px, -.5px) rotate(-.5deg);}92% {transform: translate(-1.5px, -1.5px) rotate(1.5deg);}94% {transform: translate(.5px, .5px) rotate(-.5deg);}96% {transform: translate(2.5px, -.5px) rotate(-.5deg);}98% {transform: translate(-1.5px, -1.5px) rotate(-.5deg);}0%, 100% {transform: translate(0, 0) rotate(0);}
}

Hexo+Icarus3+live2d给博客添加看板娘相关推荐

  1. 用html5看板娘,HEXO+icarus主题 给博客添加看板娘(Live2D)

    最近在很多博客左下角或者右下角有看到小人(看板娘),折腾了一番搜到的都没有达到预期的效果,并且大多数教程都是基于Next来做的,本人使用的主题是Icarus,跟Next有细微的区别.后面找到了大神的作 ...

  2. (三) 给你的博客添加看板娘(Live2D)HEXO+icarus

    HEXO+icarus主题 给博客添加看板娘(Live2D) 最近在很多博客左下角或者右下角有看到小人(看板娘),折腾了一番搜到的都没有达到预期的效果,并且大多数教程都是基于Next来做的,本人使用的 ...

  3. Hexo 博客添加看板娘

    Hexo 博客添加看板娘 相信看到这里的小伙伴都有属于自己的hexo博客了吧,废话不多说,我们直接进入主题 我的博客:传送门 1.安装模块 在hexo根目录下用Git执行命令 npm install ...

  4. WordPress博客添加看板娘

    效果如下: WordPress博客添加看板娘(送37套服饰) 1.  从我的github下载压缩包 该压缩包已经自带37套服饰.支持换装功能.支持经典动漫台词展示.未来还会支持钉宫日语50音发声喔~ ...

  5. 给你的网页添加看板娘(以给博客园博客添加看板娘为例)(保姆级图文)

    步骤 系列文章 前言 1.下载看板娘资源 2.上传资源到文件 3.在设置中调用资源 4.看看效果 总结 系列文章 提示:转到日常小技巧专栏,观看更多内容! 点我直达–>日常小技巧专栏 前言 给你 ...

  6. 如何给博客添加看板娘详解(面向新手)

    1.在我的博客页面,点击"管理",进入博客园后台. 2.选择"文件",从本地上传四个文件 flat-ui.min.css (看板娘的侧边选项栏) live2d. ...

  7. Hexo + yilia 主题 +githubpages博客添加友言评论功能

    前言 Hexo博客的Yilia主题中评论系统只提供了畅言.网易云跟帖.多说和Disqus. 由于多说评论.网易云跟帖已经关闭系统,畅言需要域名备案,而github是国外的,没有备案,所以尝试了其他第三 ...

  8. hexo next主题为博客添加分享功能

    今天心血来潮,决定给博客添加分享功能,百度上首先是找到了使用shareSDK的分享功能,最后在实践的过程中发现它添加时步骤比较多,添加完成后效果比较丑(就是一个长条的浅蓝色按钮),而且点击后想要退出分 ...

  9. 如何给自己的个人博客添加一个呆萌的live-2d博客精灵/看板娘

    live2d看板娘一览图 1. 引入live-2d相关js <!--Live-2D看板娘模型--> <script src="https://eqcn.ajz.miesnf ...

  10. 在博客园给自己的博客加入看板娘

    具体效果如右下角 需要三个文件和一个可选文件 waifu.css(看板娘在页面的位置以及大小) waifu-tips.js(看板娘的语言设置) live2d.min.js(一些点击之后的动作) *fl ...

最新文章

  1. 如何让pm2支持es6
  2. linux系统下如何创建二级域名和删除这个目录文件
  3. OnScrollListener
  4. oracle spatial 数据导入_Oracle Spatial导入shp数据
  5. SCM供应链管理的背景及意义
  6. 电影票APP原型设计分享– Movie Booking
  7. 【音频处理】使用 Adobe Audition 录制电脑内部声音 ( 启用电脑立体声混音 | Adobe Audition 中设置音频设备 | Adobe Audition 内录 )
  8. Java实现mds降维_降维算法MDS
  9. Cisco路由器重要存储设备Flash和NVRAM
  10. 地鼠君黑盒测试--小白功能测试避雷经验分享
  11. 帆软报表配置入门(一丶普通报表和决策报表 )
  12. 软件与硬件的兼容性如何测试,怎么检测电脑硬件兼容问题
  13. 如何将多个pdf合成一个pdf?
  14. ECharts统计图使用
  15. Error:Cannot run program XXX (in directory C:\Users\Administrator\.IntelliJIdeaXXX
  16. 苏州大学应用技术学院计算机二级,苏州大学应用技术学院怎么样_苏州大学一本与二本有什么差别...
  17. Cityscapes数据集(智能驾驶场景的语义分割)
  18. -bash: ./mysqld: No such file or directory
  19. 高仿iReader书架效果
  20. 克鲁斯卡尔算法(Kruskal)详解

热门文章

  1. Excel VBA——两种获取使用最大行数的方法
  2. 商汤科技Java面试题(含答案)
  3. 通过 TensorFlow 实现 AI 语音降噪提升 QQ 音视频通话质量
  4. Codeforces Gym 100015H Hidden Code 暴力
  5. Gym 100015 F Fighting for Triangles 博弈,状压dp
  6. python掷骰子实验_Python基础(十二) 模拟掷骰子demo
  7. php base64 转 amr,base64转amr文件
  8. ESP32学习笔记(29)——BLE iBeacon广播
  9. Interpreter
  10. Pale Moon 15.1 发布,苍月浏览器