【问题标题】:Why should I put {% include JB/setup %} in each post in Jekyll bootstrap?为什么我应该在 Jekyll bootstrap 的每个帖子中添加 {% include JB/setup %} ?
【发布时间】:2014-07-13 21:10:47
【问题描述】:

我正在使用Jekyll Bootstrap。而且我可以发布一篇文章,但是我不知道为什么帖子模板在每个帖子降价文件中都放置了{% include JB/setup %}。我对 ruby​​ 和 Jekyll 知之甚少。但是我检查了一些文件,我可以理解一些代码。但我还是不知道这是什么意思:

{% capture jbcache %}
  <!--
  - Dynamically set liquid variables for working with URLs/paths
  -->
  {% if site.JB.setup.provider == "custom" %}
    {% include custom/setup %}
  {% else %}
    {% if site.safe and site.JB.BASE_PATH and site.JB.BASE_PATH != '' %}
      {% assign BASE_PATH = site.JB.BASE_PATH %}
      {% assign HOME_PATH = site.JB.BASE_PATH %}
    {% else %}
      {% assign BASE_PATH = nil %}
      {% assign HOME_PATH = "/" %}
    {% endif %}

    {% if site.JB.ASSET_PATH %}
      {% assign ASSET_PATH = site.JB.ASSET_PATH %}
    {% else %}
      {% capture ASSET_PATH %}{{ BASE_PATH }}/assets/themes/{{ page.theme.name }}{% endcapture %}
    {% endif %}  
  {% endif %}
{% endcapture %}{% assign jbcache = nil %}

我已经检查了这个question。我仍然很困惑。所以这是我的问题:

  1. 为什么我应该在 Jekyll bootstrap 的每个帖子中添加 {% include JB/setup %}?
  2. 我可以修改模板以删除每个帖子中的 {% include JB/setup %} 吗?

【问题讨论】:

    标签: jekyll jekyll-bootstrap


    【解决方案1】:

    这是因为您正在使用命令rake post title="new post name"。

    见 Rakefile here:

    puts "Creating new post: #{filename}"
    open(filename, 'w') do |post|
      post.puts "---"
      post.puts "layout: post"
      post.puts "title: \"#{title.gsub(/-/,' ')}\""
      post.puts 'description: ""'
      post.puts "category: #{category}"
      post.puts "tags: #{tags}"
      post.puts "---"
      post.puts "{% include JB/setup %}"
    end
    

    删除行 post.puts "{% include JB/setup %}" 就可以了。

    【讨论】:

    • 但是,如果我删除该行。没有 CSS 样式和导航。
    • @einverne:我看不出有什么问题。 CSS 和导航已正确呈现。例如,从您现有的任何帖子中删除 {% include JB/setup %}。
    • 实际上,我不想在每个降价文件中放多行。那么有什么方法可以删除那条线。
    • @einverne:就像我说的,从 Rakfile 中删除 post.puts "{% include JB/setup %}"。对于现有帖子,请手动执行。
    • 删除该行之后。我网站上的所有内容都出错了。
    【解决方案2】:

    那是因为 JB/setup 文件设置变量像 BASE_PATH, ASSET_PATH; 假设一个场景:在你的模板文件或html文件中,你有如下代码 那么你会发生错误。 那是因为您得到的 ASSET_PATH 值不正确; 如果您像我一样使用Jekyll Bootstraps,您会在文件“root_directory”/_config.yml 中找到一些 cmets,以便您更好地理解:

    # By default, the asset_path is automatically defined relative to BASE_PATH plus the enabled theme.
    # ex: [BASE_PATH]/assets/themes/[THEME-NAME]
    #
    # Override this by defining an absolute path to assets here.
    # ex:
    #   http://s3.amazonaws.com/yoursite/themes/watermelon
    #   /assets
    #
    ASSET_PATH : false  
    

    【讨论】:

      【解决方案3】:

      不完全是。

      虽然这似乎是正确的,但它永远不会设置,即使在基本布局中,使用资产路径或类似的标签对我也不起作用。我建议删除它。正如它所说的那样添加'/',我已经窃听了,是不正确的。 './' 更正确,但 jekyll 似乎没有看到这些点。 (您指向的是 linux 驱动器的根目录,而文件根本就没有)

      感谢您的澄清。它的存在是没有实际意义的,它是在主题“安装”期间添加的,这真的很浪费。

      如果您想要多个主题可用,您只需要 layouts 文件夹和“theme_packs”。否则,只是布局文件夹。包含用于 JB,正如这里所指出的,它首先存在是没有意义的。

      您需要引导的唯一实例(这在 jekyll 中的实现中是不正确的)是让我们说一个菜单。

      引导 css 文件 javascript文件

      与 jekyll 没有任何联系。您必须自己实现。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-09
        • 2022-01-11
        相关资源
        最近更新 更多