How to suppress blank line in Jekyll?

后端 未结 5 2066
梦谈多话
梦谈多话 2021-02-04 00:49

I use GitHub Pages for my blog, and am running into a problem with Jekyll. My post.html has a block like this:

{%    for testpost in site.posts   %}
{%                  


        
5条回答
  •  半阙折子戏
    2021-02-04 01:11

    There is Jekyll plugin that strips the whitespace.

    Jekyll plugins by Aucor: Plugins for eg. trimming unwanted newlines/whitespace and sorting pages by weight attribute.

    You can get it directly from its Github repository. So basically you wrap your code with {% strip %}{% endstrip %}. Even if this doesn't suit you needs, you can easily change the ruby script.

    For example:

    {% strip %}
        {%    for testpost in site.posts   %}
        {%           four                  %}
        {%          lines of               %}
        {%         processing              %}
        {%         goes here               %}
        {%    endfor                       %}
    {% endstrip %}
    

    However, please remember the nature of Jekyll plugins, you can't run them on the Github Pages server.

    Quote from Jekyll Doccumentation:

    GitHub Pages is powered by Jekyll, however all Pages sites are generated using the --safe option to disable custom plugins for security reasons. Unfortunately, this means your plugins won’t work if you’re deploying to GitHub Pages.

    You can still use GitHub Pages to publish your site, but you'll need to convert the site locally and push the generated static files to your GitHub repository instead of the Jekyll source files.

提交回复
热议问题