Skip to content

Commit 411fb94

Browse files
committed
Code improvement.
Passing parameters to includes
1 parent 560c752 commit 411fb94

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

_includes/fixlinenos.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
https://github.com/penibelst/jekyll-compress-html/issues/101
44
https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901
55
-->
6-
{% if _content contains '<pre class="highlight">' %}
7-
{% assign _content = _content | replace: '<pre class="highlight"><code', '<code' %}
8-
{% assign _content = _content | replace: '</code></pre>', '</code>' %}
9-
{% endif %}
6+
{% if include.content contains '<pre class="highlight">' %}
7+
{% assign content = include.content | replace: '<pre class="highlight"><code', '<code' %}
8+
{% assign content = content | replace: '</code></pre>', '</code>' %}
9+
{{ content }}
10+
{% else %}
11+
{{ include.content }}
12+
{% endif %}

_includes/no-linenos.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{% comment %}
2-
Remove line numbers from code snippets.
2+
Remove the line number of the code snippet.
33
v2.2
44
https://github.com/cotes2020/jekyll-theme-chirpy
55
© 2020 Cotes Chung
66
Published under the MIT License
77
{% endcomment %}
88

9-
{% if _content contains '<td class="rouge-gutter gl"><pre class="lineno">' %}
10-
{% assign _content = _content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
11-
{% assign _content = _content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %}
9+
{% assign content = include.content %}
10+
11+
{% if content contains '<td class="rouge-gutter gl"><pre class="lineno">' %}
12+
{% assign content = content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
13+
{% assign content = content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %}
1214
{% endif %}

_includes/related-posts.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ <h3 class="pt-2 mt-1 mb-4 ml-1" data-toc-skip>{{ site.data.label.post.relate_pos
9999
</span>
100100
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
101101
<div class="text-muted small">
102-
{% assign content = post.content %}
103-
{% include no-linenos.html %}
104-
<p>{{ content | markdownify | strip_html | truncate: 200 | replace: '&', '&amp;' }}</p>
102+
<p>
103+
{% include no-linenos.html content=post.content %}
104+
{{ content | markdownify | strip_html | truncate: 200 }}
105+
</p>
105106
</div>
106107
</div>
107108
</a>

_includes/search-results.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
<div class="col-12 col-xl-11 post-content">
1010
<div id="search-hints">
1111
<h4 class="text-muted mb-4">{{ site.data.label.panel.trending_tags }}</h4>
12+
1213
{% include trending-tags.html %}
14+
1315
{% for tag in trending_tags %}
1416
{% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
1517
<a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a>
16-
{% endfor %}
18+
{% endfor %}
19+
1720
</div>
1821
<div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
1922
</div>

_layouts/default.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@
3636
<div id="main-wrapper">
3737
<div id="main">
3838

39-
{% capture _content %}
40-
{{ content }}
41-
{% endcapture %}
42-
43-
{% include fixlinenos.html %}
44-
{{ _content }}
39+
{% include fixlinenos.html content=content %}
4540

4641
{% include footer.html %}
42+
4743
</div>
44+
4845
{% include search-results.html %}
4946

5047
</div> <!-- #main-wrapper -->

_layouts/home.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ <h1><a href="{{ post.url | relative_url }}">{{ post.title }}</a></h1>
5858
</div>
5959
<div class="post-content">
6060
<p>
61-
{% assign _content = post.content %}
62-
{% include no-linenos.html %}
63-
{{ _content | markdownify | strip_html | truncate: 200 }}
61+
{% include no-linenos.html content=post.content %}
62+
{{ content | markdownify | strip_html | truncate: 200 }}
6463
</p>
6564
</div>
6665

assets/js/data/search.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ layout: compress
1010
"categories": "{{ post.categories | join: ', '}}",
1111
"tags": "{{ post.tags | join: ', ' }}",
1212
"date": "{{ post.date }}",
13-
{% assign _content = post.content %}
14-
{% include no-linenos.html %}
15-
"snippet": "{{ _content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
13+
{% include no-linenos.html content=post.content %}
14+
"snippet": "{{ content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
1615
}{% unless forloop.last %},{% endunless %}
1716
{% endfor %}
1817
]

0 commit comments

Comments
 (0)