Code improvement.

Passing parameters to includes
This commit is contained in:
Cotes Chung 2020-07-22 21:41:49 +08:00
parent 562fcd4fd8
commit 209058b84a
7 changed files with 28 additions and 24 deletions

View file

@ -3,7 +3,10 @@
https://github.com/penibelst/jekyll-compress-html/issues/101 https://github.com/penibelst/jekyll-compress-html/issues/101
https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901 https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901
--> -->
{% if _content contains '<pre class="highlight">' %} {% if include.content contains '<pre class="highlight">' %}
{% assign _content = _content | replace: '<pre class="highlight"><code', '<code' %} {% assign content = include.content | replace: '<pre class="highlight"><code', '<code' %}
{% assign _content = _content | replace: '</code></pre>', '</code>' %} {% assign content = content | replace: '</code></pre>', '</code>' %}
{% endif %} {{ content }}
{% else %}
{{ include.content }}
{% endif %}

View file

@ -1,12 +1,14 @@
{% comment %} {% comment %}
Remove line numbers from code snippets. Remove the line number of the code snippet.
v2.2 v2.2
https://github.com/cotes2020/jekyll-theme-chirpy https://github.com/cotes2020/jekyll-theme-chirpy
© 2020 Cotes Chung © 2020 Cotes Chung
Published under the MIT License Published under the MIT License
{% endcomment %} {% endcomment %}
{% if _content contains '<td class="rouge-gutter gl"><pre class="lineno">' %} {% assign content = include.content %}
{% assign _content = _content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
{% assign _content = _content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %} {% if content contains '<td class="rouge-gutter gl"><pre class="lineno">' %}
{% assign content = content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
{% assign content = content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %}
{% endif %} {% endif %}

View file

@ -99,9 +99,10 @@
</span> </span>
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3> <h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
<div class="text-muted small"> <div class="text-muted small">
{% assign content = post.content %} <p>
{% include no-linenos.html %} {% include no-linenos.html content=post.content %}
<p>{{ content | markdownify | strip_html | truncate: 200 | replace: '&', '&amp;' }}</p> {{ content | markdownify | strip_html | truncate: 200 }}
</p>
</div> </div>
</div> </div>
</a> </a>

View file

@ -9,11 +9,14 @@
<div class="col-12 col-xl-11 post-content"> <div class="col-12 col-xl-11 post-content">
<div id="search-hints"> <div id="search-hints">
<h4 class="text-muted mb-4">{{ site.data.label.panel.trending_tags }}</h4> <h4 class="text-muted mb-4">{{ site.data.label.panel.trending_tags }}</h4>
{% include trending-tags.html %} {% include trending-tags.html %}
{% for tag in trending_tags %} {% for tag in trending_tags %}
{% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %} {% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
<a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a> <a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a>
{% endfor %} {% endfor %}
</div> </div>
<div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div> <div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
</div> </div>

View file

@ -36,15 +36,12 @@ layout: compress
<div id="main-wrapper"> <div id="main-wrapper">
<div id="main"> <div id="main">
{% capture _content %} {% include fixlinenos.html content=content %}
{{ content }}
{% endcapture %}
{% include fixlinenos.html %}
{{ _content }}
{% include footer.html %} {% include footer.html %}
</div> </div>
{% include search-results.html %} {% include search-results.html %}
</div> <!-- #main-wrapper --> </div> <!-- #main-wrapper -->

View file

@ -58,9 +58,8 @@ layout: page
</div> </div>
<div class="post-content"> <div class="post-content">
<p> <p>
{% assign _content = post.content %} {% include no-linenos.html content=post.content %}
{% include no-linenos.html %} {{ content | markdownify | strip_html | truncate: 200 }}
{{ _content | markdownify | strip_html | truncate: 200 }}
</p> </p>
</div> </div>

View file

@ -10,9 +10,8 @@ layout: compress
"categories": "{{ post.categories | join: ', '}}", "categories": "{{ post.categories | join: ', '}}",
"tags": "{{ post.tags | join: ', ' }}", "tags": "{{ post.tags | join: ', ' }}",
"date": "{{ post.date }}", "date": "{{ post.date }}",
{% assign _content = post.content %} {% include no-linenos.html content=post.content %}
{% include no-linenos.html %} "snippet": "{{ content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
"snippet": "{{ _content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
}{% unless forloop.last %},{% endunless %} }{% unless forloop.last %},{% endunless %}
{% endfor %} {% endfor %}
] ]