You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让自定义jQuery脚本在GitHub Pages部署的Jekyll项目中生效

问题与求助

背景情况

  • 基于AcademicPages主题的Jekyll项目,需在Markdown页面添加一段依赖jQuery的交互脚本,实现功能:页面内一组条目,每个条目包含两个初始隐藏的div,点击对应按钮时显示目标div,同时隐藏其他已展开的div。
  • 脚本代码如下:
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
  $(document).ready(function () {
    $('.content-item').hide();

    $('.btn').click(function () {
      var uniqueID = $(this).data('unique-id');
      var target = '#' + $(this).attr('id') + '-content-' + uniqueID;
      $('.content-item').not(target).hide();
      console.log(target)
      $(target).toggle();
    });
  });
</script>
  • 直接将脚本插入Markdown页面时,本地运行完全正常,但部署到GitHub Pages后脚本失效。
  • 尝试将脚本移入/_includes/my_script.html文件,再通过{% include my_script.html %}引入到Markdown页面,部署后问题依旧。
  • 每次部署会收到如下警告:

The github-pages gem can’t satisfy your Gemfile’s dependencies. If you want to use a different Jekyll version or need additional dependencies, consider building Jekyll site with GitHub Actions: https://jekyllrb.com/docs/continuous-integration/github-actions/

求助内容

怎样才能让这段脚本在GitHub Pages上正常运行?或者有没有更合适的替代实现方式?


内容的提问来源于stack exchange,提问作者Leonardo Scommegna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 22:08:13