Skip to content

Instantly share code, notes, and snippets.

@bienvenuelisis
Last active March 28, 2022 01:14
Show Gist options
  • Save bienvenuelisis/8fb776b80eafc89a86369ee2cbb286a6 to your computer and use it in GitHub Desktop.
Save bienvenuelisis/8fb776b80eafc89a86369ee2cbb286a6 to your computer and use it in GitHub Desktop.
Jekyll Posts API Models, with Liquid Filters.
---
layout: null
permalink: /api/
#So your API will be accessible at <mydomain>/api
# newline_to_br - replace each newline (\n) with html break
# replace - replace each occurrence e.g. {{ 'foofoo' | replace:'foo','bar' }} #=> 'barbar'
# prepend - prepend a string e.g. {{ 'bar' | prepend:'foo' }} #=> 'foobar'
# append - append a string e.g. {{ 'foo' | append:'bar' }} #=> 'foobar'
---
{
"homepage" : "{{ site.baseurl }}",
"version" : "1",
"last_update" : "{{ site.time | date_to_xmlschema }}",
"name": {{ site.name | smartify | jsonify}},
"description": "{{ site.description }}",
"logo": "{{ site.logo }}",
"expired": false,
"favicon": "{{ site.favicon }}",
"url": "{{ site.baseurl }}",
"disqus": "{{ site.disqus }}",
"email": "{{ site.email }}",
"paginate": "{{ site.paginate }}",
"authors": {{ site.authors | jsonify}},
"posts" : [{% for post in site.posts %}
{
"id":"{{post.id | slugify: "latin"}}",
"slug":"{{post.title | slugify}}",
"url":"{{site.baseurl}}{{post.url}}",
"media":"MEDIA_NAME",
"title":"{{post.title}}",
"featured":{%if post.featured == nil || post.featured == '' %}false{% else %}{{post.featured}}{% endif %},
"premium":{%if post.premium == nil || post.premium == '' %}false{% else %}{{post.premium}}{% endif %},
"sticky":{%if post.premium == nil || post.premium == '' %}false{% else %}{{post.premium}}{% endif %},
"date":"{{post.date}}",
"image":{% if post.image contains '://' %} "{{post.image}}" {% else %} "{{ site.baseurl }}/{{post.image}}" {% endif %},
"author":{{site.authors[post.author] | jsonify}},
"read_time":"{{post.content | number_of_words | divided_by:180 }}",
"date_iso":"{{ post.date | date_to_xmlschema }}",
"date_en" : {
"day" : "{{ post.date | date: "%d" }}",
"month" : "{{ post.date | date: "%B" }}",
"year" : "{{ post.date | date: "%Y" }}",
"complete" : "{{ post.date | date: "%B, %d %Y" }}"
},
"date_fr" : {
"day" : "{{ post.date | date: "%d" }}",
"month" : {% assign m = post.date | date: "%-m" %}{% case m %}{% when '1' %}"Janvier"{% when '2' %}"Février"{% when '3' %}"Mars"{% when '4' %}"Avril"{% when '5' %}"Mai"{% when '6' %}"Juin"{% when '7' %}"Juillet"{% when '8' %}"Août"{% when '9' %}"Septembre"{% when '10' %}"Octobre"{% when '11' %}"Novembre"{% when '12' %}"Décembre"{% endcase %},
"year" : "{{ post.date | date: "%Y" }}",
"complete" : "{{ post.date | date: "%d" }} {% assign m = post.date | date: "%-m" %}{% case m %}{% when '1' %}Janvier{% when '2' %}Février{% when '3' %}Mars{% when '4' %}Avril{% when '5' %}Mai{% when '6' %}Juin{% when '7' %}Juillet{% when '8' %}Août{% when '9' %}Septembre{% when '10' %}Octobre{% when '11' %}Novembre{% when '12' %}Décembre{% endcase %} {{ post.date | date: "%Y" }}"
},
"category_main" : "{{post.categories | first }}",
"categories" : {{post.categories | jsonify }},
"tags" : {{post.tags | jsonify }},
{%if post.next == nil %}"next" : {}, {% else %}"next" : {
"id":"{{post.next.id | slugify: "latin"}}",
"slug":"{{post.next.title | slugify}}",
"url":"{{site.url}}{{post.next.url}}",
"title":"{{post.next.title}}",
"image":{% if post.next.image contains '://' %} "{{post.next.image}}" {% else %} "{{ site.baseurl }}/{{post.next.image}}" {% endif %},
"author":{{site.authors[post.next.author] | jsonify}},
"read_time":"{{post.next.content | number_of_words | divided_by:180 }}",
"date_iso":"{{ post.next.date | date_to_xmlschema }}",
"date_fr" : "{{ post.next.date | date: "%B, %d %Y" }}",
"date_en" : "{{ post.next.date | date: "%d" }} {% assign m = post.next.date | date: "%-m" %}{% case m %}{% when '1' %}Janvier{% when '2' %}Février{% when '3' %}Mars{% when '4' %}Avril{% when '5' %}Mai{% when '6' %}Juin{% when '7' %}Juillet{% when '8' %}Août{% when '9' %}Septembre{% when '10' %}Octobre{% when '11' %}Novembre{% when '12' %}Décembre{% endcase %} {{ post.next.date | date: "%Y" }}",
"category_main" : "{{post.next.categories | first }}",
"type":"{{post.next.layout}}",
"tags" : {{post.next.tags | jsonify }}
}, {% endif %}
{%if post.previous == nil %}"previous" : {}, {% else %}"previous" : {
"id":"{{post.previous.id | slugify: "latin"}}",
"slug":"{{post.previous.title | slugify}}",
"url":"{{site.url}}{{post.previous.url}}",
"title":"{{post.previous.title}}",
"image":{% if post.previous.image contains '://' %} "{{post.previous.image}}" {% else %} "{{ site.baseurl }}/{{post.previous.image}}" {% endif %},
"author":{{site.authors[post.previous.author] | jsonify}},
"read_time":"{{post.previous.content | number_of_words | divided_by:180 }}",
"date_iso":"{{ post.previous.date | date_to_xmlschema }}",
"date_fr" : "{{ post.previous.date | date: "%B, %d %Y" }}",
"date_en" : "{{ post.previous.date | date: "%d" }} {% assign m = post.previous.date | date: "%-m" %}{% case m %}{% when '1' %}Janvier{% when '2' %}Février{% when '3' %}Mars{% when '4' %}Avril{% when '5' %}Mai{% when '6' %}Juin{% when '7' %}Juillet{% when '8' %}Août{% when '9' %}Septembre{% when '10' %}Octobre{% when '11' %}Novembre{% when '12' %}Décembre{% endcase %} {{ post.previous.date | date: "%Y" }}",
"category_main" : "{{post.previous.categories | first }}",
"type":"{{post.previous.layout}}",
"tags" : {{post.previous.tags | jsonify }}
}, {% endif %}
"comments" : "",
"summary":{{post.excerpt | smartify | jsonify }},
"content":{{post.content | jsonify }}
} {% unless forloop.last %},{% endunless %}
{% endfor %}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment