From 209058b84a80a63b20c4137611982b97b140431b Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:41:49 +0800 Subject: [PATCH] Code improvement. Passing parameters to includes --- _includes/fixlinenos.html | 11 +++++++---- _includes/no-linenos.html | 10 ++++++---- _includes/related-posts.html | 7 ++++--- _includes/search-results.html | 5 ++++- _layouts/default.html | 9 +++------ _layouts/home.html | 5 ++--- assets/js/data/search.json | 5 ++--- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/_includes/fixlinenos.html b/_includes/fixlinenos.html index 2f88865..e736923 100644 --- a/_includes/fixlinenos.html +++ b/_includes/fixlinenos.html @@ -3,7 +3,10 @@ https://github.com/penibelst/jekyll-compress-html/issues/101 https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901 --> -{% if _content contains '
' %}
- {% assign _content = _content | replace: '
', '' %}
-{% endif %}
\ No newline at end of file
+{% if include.content contains '' %}
+ {% assign content = include.content | replace: '
', '' %}
+ {{ content }}
+{% else %}
+ {{ include.content }}
+{% endif %}
diff --git a/_includes/no-linenos.html b/_includes/no-linenos.html
index 0b55105..0b3a1ec 100644
--- a/_includes/no-linenos.html
+++ b/_includes/no-linenos.html
@@ -1,12 +1,14 @@
{% comment %}
- Remove line numbers from code snippets.
+ Remove the line number of the code snippet.
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: '', '' %}
+{% assign content = include.content %}
+
+{% if content contains ' ' %}
+ {% assign content = content | replace: '', '' %}
{% endif %}
diff --git a/_includes/related-posts.html b/_includes/related-posts.html
index d61f90f..bfe4e49 100644
--- a/_includes/related-posts.html
+++ b/_includes/related-posts.html
@@ -99,9 +99,10 @@
{{ post.title }}
- {% assign content = post.content %}
- {% include no-linenos.html %}
- {{ content | markdownify | strip_html | truncate: 200 | replace: '&', '&' }}
+
+ {% include no-linenos.html content=post.content %}
+ {{ content | markdownify | strip_html | truncate: 200 }}
+
diff --git a/_includes/search-results.html b/_includes/search-results.html
index a11832d..078f425 100644
--- a/_includes/search-results.html
+++ b/_includes/search-results.html
@@ -9,11 +9,14 @@
{{ site.data.label.panel.trending_tags }}
+
{% include trending-tags.html %}
+
{% for tag in trending_tags %}
{% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
{{ tag | replace: '-', ' ' }}
- {% endfor %}
+ {% endfor %}
+
diff --git a/_layouts/default.html b/_layouts/default.html
index e0740cc..8c78a51 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -36,15 +36,12 @@ layout: compress
- {% capture _content %}
- {{ content }}
- {% endcapture %}
-
- {% include fixlinenos.html %}
- {{ _content }}
+ {% include fixlinenos.html content=content %}
{% include footer.html %}
+
+
{% include search-results.html %}
diff --git a/_layouts/home.html b/_layouts/home.html
index 3184071..c6ce1ce 100644
--- a/_layouts/home.html
+++ b/_layouts/home.html
@@ -58,9 +58,8 @@ layout: page
- {% assign _content = post.content %}
- {% include no-linenos.html %}
- {{ _content | markdownify | strip_html | truncate: 200 }}
+ {% include no-linenos.html content=post.content %}
+ {{ content | markdownify | strip_html | truncate: 200 }}
diff --git a/assets/js/data/search.json b/assets/js/data/search.json
index de8111d..87badba 100644
--- a/assets/js/data/search.json
+++ b/assets/js/data/search.json
@@ -10,9 +10,8 @@ layout: compress
"categories": "{{ post.categories | join: ', '}}",
"tags": "{{ post.tags | join: ', ' }}",
"date": "{{ post.date }}",
- {% assign _content = post.content %}
- {% include no-linenos.html %}
- "snippet": "{{ _content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
+ {% include no-linenos.html content=post.content %}
+ "snippet": "{{ content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]