Movable Type QuickPost
Friday, January 18th, 2008 at 10:15 pmI still haven’t finished putting the site back together after upgrading Movable Type, but I really like the new version. The admin interface is a lot cleaner and easier to use, and everything feels…sturdier, I guess.
I’m not sure if QuickPost was a feature in 3.2, but I didn’t know about it if it was. And really, calling it a “feature” is an overstatement. It’s just a bookmarklet that you drop in the bookmarks toolbar of your browser, and it allows you to quickly start a post about the web page you’re looking at. For those of you who ARE using Movable Type (and this post won’t be of much interest to anyone else), there’s a QuickPost link in the Write Entry page, down below the Save and Cancel buttons.
It’s a handy little bookmarklet, but by default, it doesn’t work the way I would like. It pops up a new window with a new blog post that contains the URL of the page you were looking at, two <br>’s, and then any text you had selected on the page.
That’s a good start, but clunkier than I would like, so I changed mine a fair bit. Here’s what I’m using - it’s one long line that won’t fit in your browser, so copying it might be a pain.
javascript:d=document;w=window;t='';if(d.selection)t=d.selection.createRange().text;else{if(d.getSelection)t=d.getSelection();else{if(w.getSelection)t=w.getSelection()}}entryTitle=encodeURIComponent(d.title);if(t=='')entryBody='';else entryBody=encodeURIComponent('<blockquote>') + encodeURIComponent(t) + encodeURIComponent('</blockquote>\n\n');entryBody+=encodeURIComponent('<a href="') + encodeURIComponent(d.location.href) + encodeURIComponent('">Link</a>');url='http://site.com/cgi-bin/mt.cgi?__mode=view&qp=1&_type=entry&blog_id=1&title=' + entryTitle + '&text=' + entryBody;void(w.open(url))
And here’s a more verbose version, so it’s easier to see what’s going on:
d = document;
w = window;
t = '';
if(d.selection) {
t = d.selection.createRange().text;
}
else {
if(d.getSelection) {
t = d.getSelection();
}
else {
if(w.getSelection) {
t = w.getSelection();
}
}
}
entryTitle = encodeURIComponent(d.title);
if(t == '') {
entryBody = '';
}
else {
entryBody = encodeURIComponent('<blockquote>') + encodeURIComponent(t) + encodeURIComponent('</blockquote>\n\n');
}
entryBody += encodeURIComponent('<a href="') + encodeURIComponent(d.location.href) + encodeURIComponent('">Link</a>');
url = 'http://site.com/cgi-bin/mt.cgi?__mode=view&qp=1&_type=entry&blog_id=1&title=';
url += entryTitle + '&text=' + entryBody;
void(w.open(url));
I changed a few things. For one, “_blank” is no longer included in the window open. Under my Firefox configuration, this means that it comes up in a new tab instead of a new window. I also changed the entry body; now, it turns the URL of the page into a link (with the text “Link”), and any selected text goes above that in a <blockquote>. Basically, you get a new post that’s in the format Boing Boing typically uses.
If you want to try it out, do the following:
- Drag the QuickPost link from the Write Entry screen into your bookmarks toolbar.
- Open your favorite text editor - Notepad will do - and copy that first block of code above into it.
- Right-click on the bookmark and select Properties. Copy the Location field into your text editor too.
- You need to pull the URL out of your QuickPost code and put it into mine. Obviously, the domain part won’t be site.com, and the blog_id might be different if you’re running more than one blog in your MT installation.
- Copy the new code with the correct URL into the Location field for the bookmarklet. Make sure there aren’t any line breaks in it.
- That’s it. Test it out by going to any web page, select some text, and click the QuickPost bookmark. You should get a new post that contains the text you had selected.
Drop me a note if you’ve got any questions or suggestions for improvements, or just post a comment here.
Tags: blogging, movabletype, mt
January 21st, 2008 at 4:49 pm
Dear Brock,
You seriously effed up my friends page.
Love,
Manda (posted on LiveJournal)