Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.