feat: add some article-related functions
These functions include get_article_excerpt and get_article_words.
This commit is contained in:
parent
48d4da4f1b
commit
a037056663
2 changed files with 61 additions and 0 deletions
35
_includes/functions/get_article_excerpt.html
Normal file
35
_includes/functions/get_article_excerpt.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% if include.params.article %}
|
||||
{% assign article = include.params.article %}
|
||||
{% endif %}
|
||||
|
||||
{% if include.params.lang %}
|
||||
{% assign lang = include.params.lang %}
|
||||
{% else %}
|
||||
{% assign lang = lang | default: site.lang | default: "en" %}
|
||||
{% endif %}
|
||||
|
||||
{% if include.params.excerpt_size %}
|
||||
{% assign excerpt_size = include.params.excerpt_size %}
|
||||
{% else %}
|
||||
{% assign excerpt_size = excerpt_size | default: 800 %}
|
||||
{% endif %}
|
||||
|
||||
{%- include functions.html func='get_article_words' -%}
|
||||
{% assign words = return %}
|
||||
|
||||
{% assign _article = article | strip_html %}
|
||||
{% assign _words = _article | size %}
|
||||
|
||||
{% if lang != "en" %}
|
||||
{% assign _size = words
|
||||
| times: 1.0
|
||||
| divided_by: _words
|
||||
| times: excerpt_size
|
||||
| round %}
|
||||
{% endif %}
|
||||
|
||||
{% if _size > excerpt_size %}
|
||||
{% assign _size = excerpt_size %}
|
||||
{% endif %}
|
||||
|
||||
{% assign return = _article | truncate: _size %}
|
26
_includes/functions/get_article_words.html
Normal file
26
_includes/functions/get_article_words.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
{% if include.params.article %}
|
||||
{% assign article = include.params.article %}
|
||||
{% endif %}
|
||||
|
||||
{% if include.params.lang %}
|
||||
{% assign lang = include.params.lang %}
|
||||
{% else %}
|
||||
{% assign lang = lang | default: site.lang | default: "en" %}
|
||||
{% endif %}
|
||||
|
||||
{% assign words = article | number_of_words %}
|
||||
|
||||
{% if lang != "en" %}
|
||||
{% assign words = words
|
||||
| times: 0.6
|
||||
| round %}
|
||||
{% assign words = article
|
||||
| strip_html
|
||||
| strip_newlines
|
||||
| size
|
||||
| times: 0.4
|
||||
| plus: words
|
||||
| round %}
|
||||
{% endif %}
|
||||
|
||||
{% assign return = words %}
|
Loading…
Reference in a new issue