I’ve had Indieweb integration get under my skin the last couple of weeks…so here’s another post.

The Problem - Now that I have webmention sending and receiving integrated into my site, I have turned my attention towards meeting standards for POSSE’d content. Unfortunately I have found no easy way to add the u-syndicated links to posts without publishing the post first, then posting the POSSE’d copies, then adding the links to the original post and republishing the whole thing again manually. This is compounded by the fact I am using a static site - the post needs to be published before it can be syndicated, so getting a POSSE’d content link in advance is impossible!

I’m sure anyone skilled in writing javascript could hack something together that could parse the urls of POSSE’d content from brid.gy or my Mastodon RSS feed and embed a widget into a static html page…but that is way beyond my skill and dedication.

There are a few things I’ve added to my site that have made things easier that are worth documenting however - if only so I remember what I’ve done in the future! Who knows, maybe someone else will find it useful.

Additions to my post templates

Adding syndication links to my templates comes directly from Ana Ulin’s post- without this I don’t think I would have bothered so I’m grateful it was shared.

To note on the page (and add the crucial u-syndicated class to posts) I added the following to my post template:

{{ if .Params.syndication_urls }}
  <div class="syndication">
      <a href="https://brid.gy/publish/mastodon"></a>
      <i class="fas fa-link"></i>
      This post was syndicated to:
      {{- range $index, $url := .Params.syndication_urls }}
        {{- $parsed_url := urls.Parse $url -}}
        {{- if $index }}, {{- end }}
        <a class="u-syndication" href="{{ $url }}" rel="syndication">{{ $parsed_url.Host }}</a>
      {{- end }}
  </div>
  {{ else }}
    <div class="nosyndication">
      This post has not been syndicated.
    </div>
{{ end }}

The only real difference I made to Ana’s example is to add the nosyndication class. Check below for what to add to posts archetypes to get this working fully.

p-summary for POSSE’d social media posts

By default brid.gy does not post the entire content of a blog post to Mastodon - this would look rubbish given the character limit! I guess the same is true of twitter. In the case of Mastodon, brid.gy would look for other h-entry information as detailed here. p-summary is looked for by brid.gy as the social media post text, so it’s possible to write out the POSSE’d post in advance on the blog post!

I wanted it to be separate to the main body of the post and part of the top matter. Creating this as a parameter is the same as the syndication_urls parameter above. I just had to add:

<a hidden class="p-summary">{{ .Params.syndication_description }}</a>

inside the h-entry of the posts template.

To then activate the u-syndicated and p-summary sections you only need to add the following to the posts archetype…

Additions to my post Archetypes

syndication_urls = [""]**DELETE "" TO NOT SYNDICATE TO MASTODON**
syndication_description = ""

This was easy enough - the syndication_urls can be left as [""] for the first deployment of the site if it’s going to be syndicated. Once it’s deployed, a webmention will be sent to brid.gy, this will then toot the post to Mastodon and I can get the toot link. This can then be pasted into the top matter and the site redeployed.

If the post isn’t going to be syndicated, just remove the [""] so it becomes:

syndication_urls = []

The the post will build with “This post has not been syndicated” instead.

The manual nature of this still annoyed me for a while and I haven’t found a better way to automate that than the slightly kludgy solution below…

The syndication_description is simply what you want the social media post text to be. It’s entirely possible to make the default site description a p-summary class instead, but I found this showed up in my RSS feed - I might want the option of having different text for the social media post to the RSS feed.

Scripts and workflow

This is where things get a bit sketchy…for the site to be syndicated and posts to have the u-syndicated microformat it needs to be deployed twice. I was doing this manually with the transmit SFTP client (which is a great bit of software!). However, it seemed to much effort to drag the hugo public folder to my webserver and copy it to the right folder for Apache to pick up every single time. I used a similar trick to scripting remote Synology shutdowns.

First I wrote a script to run from a local terminal to send my built site via SFTP to my webserver:

#!/bin/bash

echo "changing into "$1""
cd $1

### Check if the public folder exists
FILE=$1/public
while :
do
if [ -d "$FILE" ]; then
    echo "Public folder exists...removing this."
    echo ""
    rm -r $1/public
    sleep 1s
else
echo "building site..."
hugo
sleep 3s
echo ""

echo "SCP'ing files to webserver..."
scp -r $1/public/ user@webserver/ip/address:/path/to/home
echo ""
echo "Files transferred"

##login to webserver and touch file to trigger deployment script
ssh user@webserver/ip/address touch path/to/home/.deploy_site
break

fi
done

This can be run with:

$ path/to/script.sh path/to/hugo/folder

Once the script puts the folder on my webserver and touches the .deploy_site file, a script running on the webserver will react to file and deploy the site.

#!/bin/bash

TAG=path/to/home/.deploy_site

if [ -r $TAG ]
then
  # Removes the tag from the file after it has been read
  rm $TAG
  # Deploys the site
  rm -r /path/to/old/version/of/site
  chown -R www-data:www-data path/to/home/public
  mv path/to/home/public /path/to/site ##this is probably something like /var/www/
  sleep 1s
  systemctl restart apache2
fi

This script is added to the root crontab and moves the site to the correct folder and restarts apache.

The whole process takes about 15 seconds. I was so lazy I even alias’d the first script to make it faster to call in the terminal.

Once it has been done once, brid.gy is pretty fast at sending out a toot and I can paste the link into the top matter of the post and redeploy.

Is this all a massive hack job? Yes. Yes it is. Does it work? Well…yeah. Just about. It’ll have to do for now!