代码之家  ›  专栏  ›  技术社区  ›  Sasha Shpota A-Bag

Jekyll:如何在GitHub页面中使用自定义插件

  •  5
  • Sasha Shpota A-Bag  · 技术社区  · 7 年前

    security concerns .

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

    有办法解决这个问题吗?有人找到解决办法了吗?

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

    2 回复  |  直到 6 年前
        1
  •  5
  •   Mr. Hugo    7 年前

    没有插件

    阅读时脚本不需要插件。我已经创建了一个脚本集合,可以添加不使用插件。你可以找到他们 here A reading time script 是其中之一。

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

    优化脚本

    假设你有这样的东西:

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

    {% 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>' %}
    

    当然,这可以扩展以支持更多的标记。

    还是要使用插件吗

    https://learn.cloudcannon.com/jekyll/using-jekyll-plugins/

        2
  •  2
  •   yegor256    6 年前

    如果您想使用自定义插件,您必须在本地“构建”站点,然后将其部署到 gh-pages 将自己分支为HTML、CSS和其他文件的集合(不再是降价文件)。你可以试试 jgd 命令行来帮助您自动完成所有操作。只需安装它,然后运行:

    $ jgd
    

    gh页面 你的回购分行。在我的这篇博文中有更多关于它的信息: Deploy Jekyll to GitHub Pages

        3
  •  1
  •   J.T.    5 年前

    如果你想的话 让杰基尔网站像本地网站一样运行 ,例如让自定义插件正常工作, 这里有个很方便的方法

    一个Github操作,可以方便地为Github页面部署Jekyll站点。 https://github.com/jeffreytse/jekyll-deploy-action

        4
  •  0
  •   VonC    7 年前

    详见“ Building a Series List with Hugo Shortcodes

    在Github页面上完全禁用Ruby插件执行:

    GitHub页面上的插件GitHub页面由Jekyll提供支持。
    但是,所有页面站点都是使用 -safe . 不幸的是,这意味着如果您部署到GitHub页面,那么您的插件将无法工作。

    你仍然可以使用GitHub页面发布你的站点, .

    显然,我可以在本地生成html文件并将它们提交到我的存储库中。但那不是我想要的。

    不过,静态网站生成器(与GitHub页面兼容)类似 Hugo 在你的案子中会被考虑。

    R.J Lorimer 添加:

    Shortcodes ,很像Jekyll里的液体标签。

    然而,主要的区别在于,在Hugo中,您可以创建它们,而无需实际编写Go代码-参见 Create Your Own Shortcodes
    因为Hugo使用Go模板来呈现页面,所以shortcode可以使用其中的任何和所有Go模板函数,以及添加到帮助中的所有自定义Hugo函数列表。这使得它可以说比液体模板解决方案更强大,但仍然是在一个模板文件中,可以很容易地在动态更新。

    另外,雨果也是 support MathJax ,作为 seen in this article

    2018年11月更新:使用 Hugo 0.52 tweet confirms (参考 this thread ):

    这个 inline shortcode

        5
  •  0
  •   Nicu Surdu Robert Laverty    6 年前

    如果因为耗时而不使用本地解决方案,那么可以自动化一个过程,这样当您将更改推送到master时,它将自动在本地构建您的网站,并将更改推送到 gh-pages 分支机构。

    pre-push 勾住你的回购( .git/hooks/pre-push )包括以下内容:

    #!/bin/sh
    
    # If any command fails in the bellow script, exit with error
    set -e
    
    # Set the name of the folder that will be created in the parent
    # folder of your repo folder, and which will temporarily
    # hold the generated content.
    temp_folder="_gh-pages-temp"
    
    # Make sure our main code runs only if we push the master branch
    if [ "$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)" == "master" ]; then
        # Store the last commit message from master branch
        last_message=$(git show -s --format=%s master)
    
        # Build our Jekyll site
        jekyll build
    
        # Move the generated site in our temp folder
        mv _site ../${temp_folder}
    
        # Checkout the gh-pages branch and clean it's contents
        git checkout gh-pages
        rm -rf *
    
        # Copy the site content from the temp folder and remove the temp folder
        cp -r ../${temp_folder}/* .
        rm -rf ../${temp_folder}
    
        # Commit and push our generated site to GitHub
        git add -A
        git commit -m "Built \`$last_message\`"
        git push
    
        # Go back to the master branch
        git checkout master
    else
        echo "Not master branch. Skipping build"
    fi
    
    

    更多细节请 see my blog post .

    推荐文章