shunn ([personal profile] shunn) wrote2011-12-07 11:59 pm

The stations of the crossposter

First, let me say that most of you aren't going to care about this.

To the few of you who do, let me say that my long LiveJournal nightmare is over.

Not that I have as bad an opinion of LiveJournal as some, but the fact that it had been my primary blogging platform for so long was holding me back from bringing all my blogs together under one roof. As I posted on Saturday, I'd written scripts a long time ago to let me crosspost my LiveJournal entries to my Movable Type blog, but now I wanted to switch that around and go the other direction. I wanted to be able to use Movable Type's superior content management system to work on more than one entry at a time, and to schedule them for automatic posting at future dates. It was only once I began looking into my options that I realized finding a solution would mean I could crosspost to LiveJournal from all my blogs. Bonus.

Interestingly, it was people I know who led me to the answer. My very first Google search led me to this 2008 post from Ben Rosenbaum, who was looking for a similar solution, and Tempest Bradford served it up in the very first comment. She pointed me toward a Movable Type plugin by Chip Marshall called ljcrosspost that sounded perfect. Several other sites praised it highly. The only problem was, site where the source code was archived no longer existed.

I tried a couple of other plugins I ran across, but when I tested them they were kind of iffy. I kept coming back to ljcrosspost in my Google searches, but was frustrated by the elusiveness of the source archive. If only I'd embarked on this project in 2008!

But then I realized I could probably get the code from the Wayback Machine. Bingo! There it was.

So finally I made some time today to familiarize myself with the code and to write a few test scripts. The ljcrosspost plugin works by communicating with LiveJournal.com via XML-RPC, and that makes it startlingly easy to post LiveJournal entries from a Perl script. (In fact, I probably annoyed the hell out of my LJ friends with all the placeholder entries I posted then deleted this afternoon.) Once I had the basic concepts down, I made some tweaks of my own to Mr. Marshall's code, and I was off to the races.

The cool thing about ljcrosspost (and forgive me if I get too geeky) is that it not only lets you crosspost but also crossedit. When you first publish a blog entry on the Movable Type end, the plugin opens an RPC channel to LiveJournal, posts the entry there, and gets back a couple of unique identifiers which it then stores with the Movable Type entry's metadata. If you should ever go back and edit that entry, Movable Type sees from the metadata that a copy already exists at LiveJournal, so it posts an RPC request to update the LiveJournal entry with the altered text. Very slick.

Another consequence of ljcrosspost's design is that, once you've installed it, if you republish your entire Movable Type blog, all the existing entries will get posted to LiveJournal. I actually did that with my Proper Manuscript Format and Signs of Yesteryear blogs, which you can now see neatly mirrored here and here.

Of course, as you might guess, I made some of my own little tweaks to ljcrosspost. First, I enabled the list of categories associated with a Movable Type entry to be translated into LiveJournal tags and passed to the remote server.

I also extended the <MTLJCrosspost> tag so I can pass it an explicit list of categories to be added to all entries mirrored from a given blog. (This is how, for instance, I can give all the entries from my formatting blog the LiveJournal tag "manuscript format," even though that's not a category associated with any of the original Movable Type entries.)

And finally I inserted a little message at the end of each mirrored entry which incorporates the name of the originating blog and links back to the original version of the post.

You might think that's a lot of trouble to go to just to be able to send content to a site that doesn't entirely suit me anymore, and you'd be right. But the fact is, I still have a lot of great friends at LiveJournal, and I like interacting with them there even if the other aspects of the site aren't what they used to be. We've got a lot of history, and I'm glad I'll finally be able to put some of my other content in front of them without a lot of annoying crosslinking.

So anyway, I've tested my new setup pretty thoroughly, but this will be the first real new entry that I post with it. I'm going to schedule it to go live just before midnight. Then I'm going to cross my fingers and hope it gets to you LiveJournal folks.


Crossposted from Inhuman Swill

[identity profile] benrosenbaum.livejournal.com 2011-12-08 09:20 am (UTC)(link)
Huh. How easy do you think this would be for me to drop into my MT installation? Do you have everything all set up for that?

[identity profile] shunn.livejournal.com 2011-12-08 03:11 pm (UTC)(link)
Yes and no. You could just take the original code I found in the zip files on archive.org and install them, and it should work for you. But then you wouldn't have any of the extra little customizations I wrote, like category support.

As-is, you wouldn't be able to take my tweaked code and drop it into your installation and have it work. It's all mixed up now with a custom plugin I wrote for myself, and there are too many attachments to other code of mine.

But, it wouldn't be very hard for me to pull just the crossposting stuff out into a standalone plugin that contained my enhancements. If you're interested, I'll do that, though it might take me a few days.

And I would post it online for other people to use, if more folks are interested.

[identity profile] benrosenbaum.livejournal.com 2011-12-08 05:35 pm (UTC)(link)
Hmm.... I don't use categories much, so if that is the only added feature I don't want to put you to the trouble. Did you find the original code easy to drop in? Did you have to write any glue around it just to get it to work, other than your custom extensions?

[identity profile] shunn.livejournal.com 2011-12-08 09:07 pm (UTC)(link)
Hey, there didn't turn out to be all that much to do after all. I put everything necessary in a zip file:

NearlyLiveJournal.zip (http://www.shunn.net/toolbox/NearlyLiveJournal.zip)

There's a readme inside to explain most things, but you basically just insert the contents of the zip file into your $MTDIR directory on your web server. The folder structure in the zip file is the same as what you need on your server.

When the files are installed, you need to go to System Overview -> Tools -> Plugins in your MT dashboard. If the installation was successful, you'll see NearlyLiveJournal 1.0 listed with your plugins, enabled. (If there's a problem, it will probably be there, but disabled. You can get details about the problem in the Activity Log.)

If it's installed correctly, you then just follow the instructions in the readme to add the <$MTCrosspost$> tag with appropriate attributes to your Individual Entry Archive template.

It should work out of the box. I didn't have to write any glue around it. Let me know if you have any problems.

[identity profile] ecmyers.livejournal.com 2011-12-08 10:37 am (UTC)(link)
It worked! You totally earned it :)

[identity profile] shunn.livejournal.com 2011-12-08 03:12 pm (UTC)(link)
By "it," you mean a whisky, right? ;-)

[identity profile] ecmyers.livejournal.com 2011-12-09 05:43 am (UTC)(link)
Of course! Two, even. :)

[identity profile] le-trombone.livejournal.com 2011-12-08 06:18 pm (UTC)(link)
Nice work. I have friends who do similar things with Google Plus.

I'm a perl programmer myself. Is your version of the code open to be viewed? (For what it's worth, I'm on github and have some open projects there).

[identity profile] shunn.livejournal.com 2011-12-08 09:09 pm (UTC)(link)
I'm not on github myself, and I've never done any officially open-source programming (i.e., where I submit it to any archives). I really don't know that world well.

But you can take a look at the code here:

NearlyLiveJournal.zip (http://www.shunn.net/toolbox/NearlyLiveJournal.zip)

Any advice about submitting it anywhere would be welcome.

[identity profile] le-trombone.livejournal.com 2011-12-09 09:48 pm (UTC)(link)
Thanks, I'll take a look.

For what it's worth, one can open a free github account (no private projects, some limitations on size). So if you have a project you don't mind making visible, have the time, and want to practice, go for it.

[identity profile] shunn.livejournal.com 2011-12-09 10:50 pm (UTC)(link)
And thanks for the tip!