事实证明,由于security concerns,自定义ruby插件在GitHub页面上无法工作。
我试图添加一个插件(this one)到我的Jekyll项目的_plugins
文件夹中,但当我将其部署到GitHub时,它被忽略了。
**问题:**有没有办法解决这个问题?有没有人找到解决方案?
**注意:**显然我可以在本地生成html文件并将其提交到我的仓库。但这不是我想要的。
事实证明,由于security concerns,自定义ruby插件在GitHub页面上无法工作。
我试图添加一个插件(this one)到我的Jekyll项目的_plugins
文件夹中,但当我将其部署到GitHub时,它被忽略了。
**问题:**有没有办法解决这个问题?有没有人找到解决方案?
**注意:**显然我可以在本地生成html文件并将其提交到我的仓库。但这不是我想要的。
5条答案
按热度按时间zmeyuzjn1#
无插件
一个阅读时间脚本不需要插件。我已经创建了一个脚本集合,可以在不使用插件的情况下添加。你可以找到它们here。A reading time script是其中之一。
在这里你可以找到代码:
字符串
请注意,这段代码只包含Liquid而不包含Ruby。因此,它可以用于您的布局或包含(不含插件)。
优化脚本
假设你有这样的东西:
型
然后你可以像这样删除上面的代码块:
型
当然,这可以扩展到支持更多的标签。
还是要使用插件
如果你真的想使用插件,你可以让你的本地机器或CloudCannon构建你的网站,并将结果推送到Github页面。
ryhaxcpt2#
如果你想使用自定义插件,你必须在本地“构建”你的网站,然后自己将其部署到
gh-pages
分支,作为HTML,CSS和其他文件的集合(不再是Markdown文件)。你可能想尝试jgd
命令行来帮助你自动完成这一切。只需安装它,然后运行:字符串
该站点将被打包,然后部署到您的存储库的
gh-pages
分支。r1zhe5dt3#
如果你不喜欢本地解决方案,因为它很耗时,你可以自动化一个过程,这样当你把更改推到master时,它会自动在本地构建你的网站,并把更改推到
gh-pages
分支。您可以通过在repo(
.git/hooks/pre-push
)中创建一个pre-push
钩子来实现这一点,其中包含以下内容:字符串
更多详情请点击see my blog post。
e4eetjau4#
在Github Pages上使用自定义插件的一个更好、更直接的解决方案是使用Github Actions。所有步骤都记录在Jekyll的官方页面上:https://jekyllrb.com/docs/continuous-integration/github-actions/。在这里复制上面文章中的步骤:
1.转到存储库上的设置选项卡。
1.在代码和自动化下,单击页面(最后一个选项)。
1.将构建和部署下的Source从从分支部署更改为GitHub操作。
1.转到存储库上的操作选项卡。
1.启动新工作流,搜索Jekyll。
1.单击【Jekyll】工作流(非【GitHub Pages Jekyll】工作流)下的【配置】。
1.查看更改并单击提交更改。
在将任何本地更改推送到默认分支时,将触发操作并开始构建。
生成可能会因为以下错误而失败:
字符串
要解决这个问题,请将行
exclude: [vendor]
放置在_config.yml
中。更多讨论请参见:https://github.com/jekyll/jekyll/issues/5267。utugiqy65#
你需要一个替代这些插件。
如“Building a Series List with Hugo Shortcodes“中所述:
Ruby插件在Github页面上完全被禁用:
GitHub Pages上的插件GitHub Pages由Jekyll提供支持。
**但是,出于安全原因,所有Pages网站都是使用
-safe
选项来禁用自定义插件的。**不幸的是,这意味着如果您部署到GitHub Pages,您的插件将无法工作。您仍然可以使用GitHub Pages来发布您的网站,但您需要在本地转换网站,并将生成的静态文件推送到您的GitHub存储库,而不是Jekyll源文件。
我知道你提到:
显然,我可以在本地生成html文件并将它们提交到仓库中,但这不是我想要的。
尽管如此,静态网站生成器(与GitHub页面兼容)如**Hugo在您的情况下可以考虑。
R.J Lorimer添加:
Hugo有Shortcodes**的概念,这很像Jekyll中的“液体标签”。
也像Jekyll一样,您可以创建自定义短代码标记。
然而,主要的区别是,在Hugo中,你可以创建它们,而不需要实际编写Go代码-参见Create Your Own Shortcodes。
因为Hugo使用Go Templates来渲染页面,所以简码可以使用其中的任何和所有Go模板函数,以及一系列自定义的Hugo函数。这使得它可以说比liquid模板解决方案更强大,但仍然在一个模板文件中,可以轻松地动态更新。
另外,Hugo确实支持MathJax,如seen in this article。
2018年11月更新:使用Hugo 0.52,此tweet confirms(参考this thread):
inline shortcode类似于Jekyll允许您在Markdown中使用Liquid标签的方式