Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Created June 1, 2019 08:02
Show Gist options
  • Save daviddarnes/1c5734645821ca0862e188f51580467e to your computer and use it in GitHub Desktop.
Save daviddarnes/1c5734645821ca0862e188f51580467e to your computer and use it in GitHub Desktop.
Eleventy blog from API
<h1>API post list</h1>
<ul>
{% for post in posts %}
<li>
<a href="/posts/{{ post.id }}/">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
---
pagination:
data: posts
size: 1
alias: post
permalink: posts/{{ post.id }}/
---
<h1>{{ post.title }}</h1>
{{ post.body | safe }}
// Placed in _data/posts.js
const fetch = require("node-fetch");
module.exports = async function() {
const data = await fetch('https://jsonplaceholder.typicode.com/posts');
const json = await data.json().then(data => data);
return json;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment