Jekyll:如何在GitHub页面上使用自定义插件? [英] Jekyll: How to use custom plugins with GitHub pages?

查看:190
本文介绍了Jekyll:如何在GitHub页面上使用自定义插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实证明,由于安全问题,自定义ruby插件在GitHub页面上不起作用.

我正在尝试将插件(这一个)添加到我的_plugins文件夹中Jekyll项目,但是当我将其部署到GitHub时,它将被忽略.

I'm trying to add a plugin (this one) to the _plugins folder of my Jekyll project, but when I deploy it to GitHub it is ignored.

问题:是否可以解决此问题?有没有人找到解决方案?

Question: Is there a way to workaround this? Has anyone found a solution?

注意:很明显,我可以在本地生成html文件,并将它们提交到我的存储库中.但这不是我想要的.

Note: Obviously I can generate html files locally and commit them to my repository. But that's not what I want.

推荐答案

没有插件

阅读时间脚本不需要插件.我创建了一个脚本集合,无需使用插件即可添加这些脚本.您可以在此处找到它们. 阅读时间脚本就是其中之一.

Without a plugin

A reading time script does not require a plugin. I have created a collection of scripts that can be added without using a plugin. You can find them here. A reading time script is one of them.

在这里找到代码:

{% capture words %}
{{ content | number_of_words | minus: 180 }}
{% endcapture %}
{% unless words contains '-' %}
{{ words | plus: 180 | divided_by: 180 | append: ' minutes to read' }}
{% endunless %}

请注意,此代码仅包含Liquid,不包含Ruby.因此,它可以在您的布局或包含(无插件)中使用.

Note that this code contains only Liquid and no Ruby. Therefore it can be used in your layout or in an include (without a plugin).

假设您有类似这样的内容:

Suppose you have something like this:

<p>lorem ipsum</p>
<p>lorem ipsum</p>
<code>lorem ipsum</code>
<p>lorem ipsum</p>
<code>lorem ipsum</code>
<p>lorem ipsum</p>

然后您可以像这样删除上面的代码块:

Then you could remove the above code blocks like this:

{% assign preprocessed_content=post.content | replace: '<p>', '__p__' %}
{% assign preprocessed_content=preprocessed_content | replace: '</p>', '__/p__' %}
{% assign truncated_content=preprocessed_content | strip_html %}
{% assign cleaned_content=truncated_content | replace: '__p__', '<p>' %}
{% assign cleaned_content=cleaned_content | replace: '__/p__', '</p>' %}

当然可以扩展以支持更多标签.

Ofcourse this can be extended to support more tags.

如果您真的想使用插件,则可以让您的本地计算机或CloudCannon构建您的站点并将结果推送到Github Pages.另请参阅: https://learn.cloudcannon.com/jekyll/using-jekyll-plugins /

If you REALLY want to use a plugin you can let your local machine or CloudCannon build your site and push the result to Github Pages. See also: https://learn.cloudcannon.com/jekyll/using-jekyll-plugins/

这篇关于Jekyll:如何在GitHub页面上使用自定义插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆