- {{ post.content | strip_html | truncate: 200 | replace: '&', '&' }} + {% assign _content = post.content %} + {% include no-linenos.html %} + {{ _content | markdownify | strip_html | truncate: 200 }}
From ac9dc4d9acd3bc5b2043a28a0c96f3d0ac2075d0 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 6 May 2020 00:39:28 +0800 Subject: [PATCH] Remove line number from post snippet (#51). Involves: - Home page - relate posts - search results - feed --- _includes/no-linenos.html | 12 ++++++++++++ _includes/related-posts.html | 4 +++- _layouts/home.html | 4 +++- assets/data/search.json | 4 +++- feed.xml | 5 ++++- 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 _includes/no-linenos.html diff --git a/_includes/no-linenos.html b/_includes/no-linenos.html new file mode 100644 index 0000000..0b55105 --- /dev/null +++ b/_includes/no-linenos.html @@ -0,0 +1,12 @@ +{% comment %} + Remove line numbers from code snippets. + v2.2 + https://github.com/cotes2020/jekyll-theme-chirpy + © 2020 Cotes Chung + Published under the MIT License +{% endcomment %} + +{% if _content contains '
' %}
+ {% assign _content = _content | replace: '', '' %}
+{% endif %}
diff --git a/_includes/related-posts.html b/_includes/related-posts.html
index ae34eb9..dcb7992 100644
--- a/_includes/related-posts.html
+++ b/_includes/related-posts.html
@@ -58,7 +58,9 @@
{{ post.title }}
- {{ post.content | markdownify | strip_html | truncate: 200 | replace: '&', '&' }}
+ {% assign content = post.content %}
+ {% include no-linenos.html %}
+ {{ content | markdownify | strip_html | truncate: 200 | replace: '&', '&' }}
diff --git a/_layouts/home.html b/_layouts/home.html
index 3c05220..f549c17 100644
--- a/_layouts/home.html
+++ b/_layouts/home.html
@@ -15,7 +15,9 @@ layout: page
- {{ post.content | strip_html | truncate: 200 | replace: '&', '&' }}
+ {% assign _content = post.content %}
+ {% include no-linenos.html %}
+ {{ _content | markdownify | strip_html | truncate: 200 }}
diff --git a/assets/data/search.json b/assets/data/search.json
index 5627dca..93ef912 100644
--- a/assets/data/search.json
+++ b/assets/data/search.json
@@ -10,7 +10,9 @@ layout: compress
"categories": "{{ post.categories | join: ', '}}",
"tags": "{{ post.tags | join: ', ' }}",
"date": "{{ post.date }}",
- "snippet": "{{ post.content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
+ {% assign content = post.content %}
+ {% include no-linenos.html %}
+ "snippet": "{{ content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]
diff --git a/feed.xml b/feed.xml
index 7701795..30e01fc 100644
--- a/feed.xml
+++ b/feed.xml
@@ -50,7 +50,10 @@ layout: compress
{% if post.summary %}
{{ post.summary | strip }}
{% else %}
- {{ post.content | strip_html | truncate: 200 }}
+
+ {% assign content = post.content %}
+ {% include no-linenos.html %}
+ {{ content | strip_html | truncate: 200 }}
{% endif %}