Great
script by Amit to get the post URL of earlier articles. The date-part in his script inspires me to construct a proper date for my WordPress publishing. We're all building together here.
#
How should I call the script? WordPress
has a history of naming their releases after famous jazz musicians. Since we are on the Drummer here. I feel there has to be some sort of jazz-related connection in the name of the script.
#
I added a few more items to
my improvised DrummerWP-backlog. It's great to write a script. It's another thing to publish it and see what can be improved. I also started
a thread on the Drummer RFC. Feel free to discuss and bring your ideas to the table.
#
I have to be honest, it's great to see this script
used in the wild only an hour or so after publishing. Thanks for the support John!
#
- Why not crosspost to your WordPress blog with your Drummer CMS? When you publish a new thought on your Drummer blog, you can also post it on WordPress? I think I have a first version of a script in Drummer that makes this possible. It makes use of the global root object to store sensitive data of your WordPress installation, like the endpoint and an authorization password. #
- Here is a short video how the script works (for some reason the embedded version doesn't work. Probably some https-hoopla).#
- Update nov 25th: Check out my follow-up post with slight improvements to the original script!#
- Caveat: I am not a programmer, the loop I wrote is pretty crude and could be done more efficient and nicer I think. #
- So first in Drummer, you need to open your root-file through File > Special Files #
- Create a data-object called env and add your endpoint and WordPress Application Password in the format user:password.#
- Add this script to your Scripts menu and name it whatever you like. You could comment out line 42 (xhr.send(JSON.stringify(data));) to play around with the script first and see what it does.#
- First, the script checks if you're on the headline where the title of your post goes. If the cursor is on the right place, it takes all the children of this node and loops over them. If it's not, you'll get a warning and loop out of the script. #
- The loop also checks if there is an image or inlineImage present in the attributes. #
- Next I build the data-object I want to send to my WordPress endpoint. #
- I set up an XMLHttp request. Again, many roads lead to the same result. This is just an example I found online and re-used it. #
- When the call to WordPress is successful, I use the response from WordPress to open the new post in Draft mode in a new tab. I could also open it in the editor, whatever your choice is. #
- I also add an attribute to the headline with the WordPress id. This might come in handy later for updates or any other connection between Drummer and WordPress.#
- This is all very much work in progress. A lot of stuff is not ironed out yet. Again, I am not a programmer. I just Stack-Overflow my way around here...What needs to be done:#
- I only go one level deep to get all the text. I need some sort of recursion when I walk through the outline to get all the text.#
- In the loop to create the text, I check for image and inlineImage in two separate if's. I feel this can be done more gentle. #
- I don't check for other attributes like urlVideo or enclosure. #
- I'd love to add the publish date from Drummer as the date in WordPress as well. But dates in Javascript are not my cup of tea.#
- I post everything in one category. It would be nice to choose a category before publishing.#
- No tags. Yet. #
- I post everything in Draft first. It could toggle between draft and publish immediately. Use the OPML attributes for the headline to do this.#
- When you secure your WordPress installation and disable the REST API for unauthorized visitors, the script doesn't work. Need to figure this out.#
- This script only works when your Drummer post has a title. A micropost gives an error. #
- No real error-handling. The browser console is your friend, as is console.log. #
- So there you have it. This is the first version of my Drummer to WordPress script. Let me know what you think and especially what should be improved!#
- Yes, this post is also published (and slightly editted) on my WordPress blog!#