Created
June 1, 2019 08:02
-
-
Save daviddarnes/1c5734645821ca0862e188f51580467e to your computer and use it in GitHub Desktop.
Eleventy blog from API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>API post list</h1> | |
<ul> | |
{% for post in posts %} | |
<li> | |
<a href="/posts/{{ post.id }}/">{{ post.title }}</a> | |
</li> | |
{% endfor %} | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
pagination: | |
data: posts | |
size: 1 | |
alias: post | |
permalink: posts/{{ post.id }}/ | |
--- | |
<h1>{{ post.title }}</h1> | |
{{ post.body | safe }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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