Last active
February 4, 2018 14:33
-
-
Save brunoventura/e567d4523a08925f504a5d2495969547 to your computer and use it in GitHub Desktop.
Gist to demonstrate how integrate medium posts with wix collection
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
import { fetch } from 'wix-fetch'; | |
import data from 'wix-data'; | |
const USER = 'cecosmos'; | |
const POST_BASE_PATH = `https://medium.com/${USER}/`; | |
const FEED_PATH = `${POST_BASE_PATH}latest?format=json`; | |
const IMG_CND_BASE_PATH = `https://cdn-images-1.medium.com/max/500/`; | |
const savePost = post => data.save('posts', { | |
_id: post.id, | |
title: post.title, | |
link: `${POST_BASE_PATH}${post.uniqueSlug}`, | |
image: `${IMG_CND_BASE_PATH}${post.virtuals.previewImage.imageId}` | |
}); | |
export async function load() { | |
const feed = await fetch(FEED_PATH); | |
const body = JSON.parse((await feed.text()).slice(16)); | |
await Promise.all(body.payload.posts.map(savePost)); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment