Banner随机文章展示(轻笑同款)

Banner随机文章展示(轻笑同款)

1.前言

为了把lighthouse的性能优化到极致,所以采用了这种轻笑方案的随机banner来优化

2.添加hometop

1.在 BlogRoot\themes\sxiaohe\scripts\helpers中新建home_random_post.js:

JS
hexo.extend.generator.register('thePosts', function (locals) {
    const jsonData = locals.posts
      .filter(post => post.random !== false)
      .map(post => {
        return {
          title: post.title || "暂无标题",
          abbrlink: post.abbrlink,
          image: post.cover,
          description: post.description || "暂无简介"
        };
      });
  
    return {
      path: 'random.json',
      data: JSON.stringify(jsonData)
    };
  });
  

2.在 BlogRoot\themes\butterfly\layout\includes中新建hometop.pug:

问题

提示:如果在页面中添加js文件,会导致浏览器一直读取js,从而让用户无法看到页面内容,所以这里采用pug内嵌js文件展示出来

3.在自定义css文件中添加:

3.后记

对于一些需要这种方案的以及想要简洁风格的可以根据这篇文章进行修改。

美化文章卡片显示数字
轻笑底部美化

评论区

评论加载中...