written by
Alan Richardson

Multi-site publishing with StoryChief and static websites

talotics.com 3 min read

Pushing content to multiple platforms is a real pain. What software can help with that?

I'm currently experimenting with StoryChief.io.

Why?

Because I never use Facebook. I forget it is there. I want to automatically publish to facebook.

I also want to make it easier for me to syndicate content to linkedin, medium, etc.

StoryChief.io seems to offer that.

I face one difficulty though. I mostly use static websites as my canonical source:

  • static sites don't have an API
  • StoryChief.io doesn't have a plugin to support them

But it does support web hooks.

So I created a very simple webhook which returns some custom fields for a permalink to try and 'fool' StoryChief into thinking I have a primary website that is using StoryChief normally, even though I'm not.

This post is my first attempt at using it.

StoryChief Config

I order to make my static site the 'primary' site. I used the story chief API to point to a webhook on my site.

And I created two custom fields in StoryChief : postid and posturl

I set the API as the primary personal web site.

When StoryChief tries to post stories it first tries the primary and then posts to every other site.

When StoryChief posts to my primary it basically sends me the content and I respond with the postid and posturl that I configured in the post as permalinks to allow the workflow to proceed.

JSON Message from StoryChief

The JSON Message that StoryChief sends through in the web hook is a little stranger than normal so be aware of the following gotchas:

  • The content is not just the HTML content it also includes a block of JavaScript that you have to parse out out see this link for info
  • The custom fields are not the names you give them, but are instead the unique ids shown in the GUI

e.g. ori8a8l5Cr92A8SUTuer instead of postid

My current workflow

Since I like to write in Markdown. I will continue to write these posts in my normal editor and upload them to my static site.

Once they are generated, I will paste the HTML into StoryChief and add the permalink.

I can use StoryChief to:

  • plan my content
  • syndicate it to all the other sites

I just don't use it to write the content yet. I might have my webhook parse the HTML and convert it to Markdown for my static site.

My web hook code

My Web Hook code is a little hacky:

<?php
$KEY = 'XXXXXXXXXXXXXXX'; // change this to your API key

$body = @file_get_contents('php://input');
$payload = json_decode($body, true);

if (!validateCallback($payload, $KEY)) {
http_response_code(400);
}else{

// postid is XXXXXXID change this to your custom field values
//posturl is XXXXXXURL

$customfields = $payload['data']['custom_fields'];

$id="unknown";
$url="unknown";

foreach ($customfields as $key) {
if(strcmp($key['key'], 'XXXXXXID')==0){
$id = $key['value'];
}
if(strcmp($key['key'], 'XXXXXXURL')==0){
$url = $key['value'];
}
}

$data = array('id' => $id, 'permalink' => $url);

http_response_code(200);
header('Content-Type: application/json');
echo json_encode($data);
}


function validateCallback($payload, $KEY) {
// copy the mac from array
$givenMac = $payload['meta']['mac'];

// removes the mac from array
unset($payload['meta']['mac']);

// recalculate the mac with you key
$calcMac = hash_hmac('sha256', json_encode($payload), $KEY);

// validate that calculated and given mac are the same
return hash_equals($givenMac, $calcMac);
}
?>

Note my code has various debugging output to files which I used to get it all working. But above is a basic dummy hook to allow a permalink to be added to the StoryChief post and manage the canonical post externally.

tools blogging