【问题标题】:Jekyll's sitemap plugin - exclude assets pagesJekyll 的站点地图插件 - 排除资产页面
【发布时间】:2018-01-09 17:22:30
【问题描述】:

我正在为 Jekyll 使用 jekyll-sitemap 插件。

有没有办法排除 assets 文件夹中的 .html 文件? 其中一些包含一些 HTML 示例,我最终在我的 sitemaps.xml 中包含以下内容,这没有意义:

<url>
<loc>https://example.com/blog/assets/vanilla-lazyload/demos/with_picture.html</loc>
<lastmod>2017-11-18T15:05:22+01:00</lastmod>
</url>

with_picture.html 是一个 Javascript 库的演示文件,使用 npm install 时会附带它(我也懒得每次都为每个库删除它们)

According to the docs,在我们前面的问题中使用sitemap: false 应该可以解决它,但它似乎根本不起作用。

因为我在这些供应商文件中没有任何正面内容,所以我使用Jekyll's Front Matter defaults method 这样做,但没有成功。

# in my _config.yml
defaults:
  - scope:
      path: 'assets/'
    values:
      sitemap: false

我还尝试了以下path,但没有运气:

路径:“资产”

path: 'assets' 可能不会考虑子文件夹吗?

【问题讨论】:

  • 找到解决办法了吗?就我而言,即使是简单的前端问题也不起作用。 :-|
  • 我想我从来没有这样做过。我不得不手动删除它们。
  • 手动,你的意思是sitemap: false?因为它对我不起作用(在ahoxus.org/pt/propostas/naturala 源和站点地图下,如果你想看的话)。仍在试图找出原因。对你起作用吗?或者什么是“手动”?
  • 手动删除我不喜欢出现在站点地图中的条目。

标签: jekyll jekyll-extensions


【解决方案1】:

如果您的 Jekyll 版本是 v3.7.2 或更高版本,而您的 jekyll-sitemap 版本是 v1.2.0 或更高版本,则应该可以:

defaults:
  -
    scope:
      path: 'assets/**'
    values:
      sitemap: false

** 将匹配assets 目录或其任何子目录中的任何文件。

Here's the relevant section in the docs.

【讨论】:

    【解决方案2】:

    在您的 _config.yml 文件中,添加:

    exclude :
     - assets/vanilla-lazyload/demos
    

    【讨论】:

    • 我想排除 assets 中的所有内容,因为这是一个文件夹,我将在其中添加不同的资产,每个资产都可能包含 HTML 文件。因此,我宁愿不必每次添加供应商资产时都修改 _config.yml 文件。
    • 如果设置默认配置不起作用(您尝试过path: 'assets' 吗?),我看不到其他方法。
    • 我做到了。结果相同。没有改变。这些文件仍包含在站点地图中。
    • 不,但如果你愿意,你可以自己测试一下。你肯定会得到同样的结果。
    【解决方案3】:

    您可以在没有插件的情况下轻松创建自己的站点地图:在您的主 jekyll 文件夹中创建一个名为“sitemap.xml”的文件,如 _post、_pages 和 _includes 旁边。

    所有需要包含的文件如下:

    ---
    layout: null
    ---
    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
      {% for post in site.posts %}
        <url>
          <loc>{{ site.url }}{{ post.url }}</loc>
          {% if post.lastmod == null %}
            <lastmod>{{ post.date | date_to_xmlschema }}</lastmod>
          {% else %}
            <lastmod>{{ post.lastmod | date_to_xmlschema }}</lastmod>
          {% endif %}
          <changefreq>monthly</changefreq>
          <priority>1.0</priority>
        </url>
      {% endfor %}
      {% for page in site.pages %}
        {% if page.sitemap != null and page.sitemap != empty %}
          <url>
            <loc>{{ site.url }}{{ page.url }}</loc>
            <lastmod>{{ page.sitemap.lastmod | date_to_xmlschema }}</lastmod>
            <changefreq>{{ page.sitemap.changefreq }}</changefreq>
            <priority>{{ page.sitemap.priority }}</priority>
           </url>
        {% endif %}
      {% endfor %}
    </urlset>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      相关资源
      最近更新 更多