Liquid 标签在某些页面上扩展,而不是在其他页面上扩展
Liquid tags expanding on some pages, not on others
我网站homepage上的liquid标签没有展开(具体看描述标签):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- If the post has an empty title (because it's a "short") then don't add it to the title of the page. -->
<title>Alex Learns Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{% for post in paginator.posts %} {{ post.date | date: site.date_format }} {{ post.title }} {% if post.summary %} {% if post.image %} {% endif %} {{ post.summary }} Read more → {% elsif post.content contains site.excerpt_separator %} {{ post.excerpt }} Read more → {% else %} {{ post.content }}...">
<meta name="author" content="Alex Johnson">
<link rel="canonical" href="http://code.alxmjo.com/">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for Alex Learns Programming" href="/feed.xml" />
...
但是,在 posts 上,液体标签展开得很好:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- If the post has an empty title (because it's a "short") then don't add it to the title of the page. -->
<title>Insitu: Week Five – Alex Learns Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Today I finish my fifth week at Insitu. I was supposed to be on a bus headed out to watch a test flight today, but that trip was postponed because of a nearby wildfire. So instead I’m sitting in my usual coffee shop in White Salmon, thinking back on the...">
<meta name="author" content="Alex Johnson">
<meta name="keywords" content="Insitu">
<link rel="canonical" href="http://code.alxmjo.com/insitu-week-five">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for Alex Learns Programming" href="/feed.xml" />
...
根据我的研究,我知道 Liquid 标签需要 YAML frontmatter 才能正确扩展。但我相信我把它们放在了正确的地方。
我不确定它是否与这个问题相关,但我认为以下是与此问题有关的文件:
就其价值而言,这是一个主要库存的、最新的 Jekyll 安装。
知道我做错了什么吗?
问题出在 _includes/head.html
中的这一行:
<meta name="description" content="{% if page.summary %}{{ page.summary | strip_html | strip_newlines }}{% else %}{{ page.content | strip_html | truncatewords: 50 }}{% endif %}">
主页没有摘要,所以它转到 if 语句的第二部分,只是拉入页面的内容。那恰好是原始液体,因此它是如何显示在上面的。
通过将该行修改为以下内容来解决此问题:
<meta name="description" content="{% if page.url == "/" %}{{ site.description }}{% elsif page.summary %}{{ page.summary | strip_html | strip_newlines }}{% else %}{{ page.content | strip_html | truncatewords: 50 }}{% endif %}">
有点麻烦,但它确实有效。
我网站homepage上的liquid标签没有展开(具体看描述标签):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- If the post has an empty title (because it's a "short") then don't add it to the title of the page. -->
<title>Alex Learns Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{% for post in paginator.posts %} {{ post.date | date: site.date_format }} {{ post.title }} {% if post.summary %} {% if post.image %} {% endif %} {{ post.summary }} Read more → {% elsif post.content contains site.excerpt_separator %} {{ post.excerpt }} Read more → {% else %} {{ post.content }}...">
<meta name="author" content="Alex Johnson">
<link rel="canonical" href="http://code.alxmjo.com/">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for Alex Learns Programming" href="/feed.xml" />
...
但是,在 posts 上,液体标签展开得很好:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- If the post has an empty title (because it's a "short") then don't add it to the title of the page. -->
<title>Insitu: Week Five – Alex Learns Programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Today I finish my fifth week at Insitu. I was supposed to be on a bus headed out to watch a test flight today, but that trip was postponed because of a nearby wildfire. So instead I’m sitting in my usual coffee shop in White Salmon, thinking back on the...">
<meta name="author" content="Alex Johnson">
<meta name="keywords" content="Insitu">
<link rel="canonical" href="http://code.alxmjo.com/insitu-week-five">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for Alex Learns Programming" href="/feed.xml" />
...
根据我的研究,我知道 Liquid 标签需要 YAML frontmatter 才能正确扩展。但我相信我把它们放在了正确的地方。
我不确定它是否与这个问题相关,但我认为以下是与此问题有关的文件:
就其价值而言,这是一个主要库存的、最新的 Jekyll 安装。
知道我做错了什么吗?
问题出在 _includes/head.html
中的这一行:
<meta name="description" content="{% if page.summary %}{{ page.summary | strip_html | strip_newlines }}{% else %}{{ page.content | strip_html | truncatewords: 50 }}{% endif %}">
主页没有摘要,所以它转到 if 语句的第二部分,只是拉入页面的内容。那恰好是原始液体,因此它是如何显示在上面的。
通过将该行修改为以下内容来解决此问题:
<meta name="description" content="{% if page.url == "/" %}{{ site.description }}{% elsif page.summary %}{{ page.summary | strip_html | strip_newlines }}{% else %}{{ page.content | strip_html | truncatewords: 50 }}{% endif %}">
有点麻烦,但它确实有效。