Public preview card

Is there a way to insert a public preview card via an API call? I can easily upload HTML cards with the API, but I’d like to also insert the public preview card in the middle of the post.

Unfortunately it seems that the parser will not presently add a preview card from an html-created post.

My project required this card, so I developed a workaround, posted here. Hopefully you can adapt it to your situation.

Thanks, @Jason ! This looks doable, I’ll port your solution to Python and work on it.

Yes – it worked! Thanks again, @Jason !

This is a simplified version of the Python code which I’m using:

    G = newGhost(site)
    post = G.getPostById(id)
    js = json.loads(post['posts'][0]['mobiledoc'])
    js['cards'].append(['paywall', {}])
    index = len(js['cards'])-1
    js['sections'].insert(1, [10,index])
    newPost = G.updatePost(id, 'mobiledoc', json.dumps(js))

Glad it was helpful! Thanks for contributing your clean code to the discussion.

Just be aware that the code will stop working when the new editor leaves beta because mobiledoc won’t exist.

If you enable the beta now you can use a <!-- members-only --> comment in your HTML to create the public preview card.

2 Likes