crazyboy

曾梦想仗剑走天涯
后来工作忙没去了

  • 主页
  • 人生啊~
  • 电脑?
  • 神兵利器
  • 工作嘛!
所有文章 友链 关于我 展开
  • 所有文章
  • 友链
  • 关于我
  • 展开

计算机爱好者
云计算
云存储
网络技术
非洲酋长
可爱的胖子
十年攻城狮

tag:

  • 生活
  • 才华
  • 一生所爱
  • -AI
  • 麒麟
  • 计算机技术
  • 工具
  • ssh
  • docker
  • hexo
  • git
  • net
  • ubuntu
  • kernel
  • gdb
  • nodejs
  • USB
  • -计算机技术 -SCSI
  • qemu
  • UVC
  • linux
  • testtool
  • windows
  • python
  • ftp
  • 记录
  • 码云
  • CSDN
  • live
  • test
  • AI
  • kylin
  • it

crazyboy

曾梦想仗剑走天涯<br>后来工作忙没去了

hexo_hid

[busuanzi] 阅读数:3188次 2022-05-09
字数统计: 433字   |   阅读时长≈ 2分

https://vanchchen.github.io/p/7587.html

代码解析

hexo/lib/extend/filter.js

用来实现钩子功能
这里我们主要看
before_generate
这个钩子,以及它的参数

1
hexo.extend.filter.register('before_generate', function () {

调用点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//hexo/lib/hexo/index.js
_generate(options = {}) {
if (this._isGenerating) return;

const useCache = options.cache;

this._isGenerating = true;

this.emit('generateBefore');

// Run before_generate filters
this.log.debug("YGH:data:%s", this.locals.get('data'));
return this.execFilter('before_generate', this.locals.get('data'), { context: this })
.then(() => this._routerReflesh(this._runGenerators(), useCache)).then(() => {
this.emit('generateAfter');

// Run after_generate filters
return this.execFilter('after_generate', null, { context: this });
}).finally(() => {
this._isGenerating = false;
});
}

//hexo/lib/extend/filter.js
exec(type, data, options = {}) {
const filters = this.list(type);
if (filters.length === 0) return Promise.resolve(data);

const ctx = options.context;
console.log("YGH:type:%s locals:%s", type, ctx.locals);
const posts = ctx.locals.get('posts');
if(posts)
console.log("%s", posts);
console.log("%s", ctx.locals.get('posts'));
const args = options.args || [];

args.unshift(data);

return Promise.each(filters, filter => Reflect.apply(Promise.method(filter), ctx, args).then(result => {
args[0] = result == null ? args[0] : result;
return args[0];
})).then(() => args[0]);
}

context

context.locals里面保存有大部分的消息传递

方案改变

由于对消息机制并不是了解太深入,这个方案遇到重大问题,无法实现,后来改用修改yilia-plus主题代码的方式进行了实现

  • blog
    • themes
      • yilia-plus
        • laylout
          • _partial
            • archive.ejs (主窗口索引显示框架,在里面加入了hide的判断)
          • archive.ejs (主窗口索引显示)
          • hide.ejs (隐藏索引显示)
          • category.ejs (组索引显示)
          • tag.ejs(tag索引显示)
        • source-src
          • js
            • slider.js (侧边搜索框结果显示)
    • _config.yml (jsonContent, 加入hide字段)

编译方法

确保node版本 > 12

cnpm webpack -g
cnpm webpack-cli -g
cnpm i -s 下载python包
webpack

  • 本文作者: crazyboy
  • 本文链接: http://crazyboy.www.crazyboy.info/blog/blog/2022/05/09/it/host/hexo/hexo-hid/
  • 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!
  • 计算机技术
  • hexo
test
qemu iso设备使用时,断开链接概率导致崩溃问题
  1. 1. 代码解析
    1. 1.1. hexo/lib/extend/filter.js
  2. 2. context
  3. 3. 方案改变
  4. 4. 编译方法
© 2022-2025 crazyboy
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量3502次 | 本站访客数3502人