Day 25: Auto-schedule HTMLy blog posts

Auto-scheduling posts is awesome. This means you can batch tasks for your blog according to specific days (i.e. outlining on Monday, writing on Tuesday, etc.) and then let the platform publish the posts automatically. It also means you won’t have to click publish each time you want to post that blog entry. Unfortunately, HTMLy doesn’t have this feature yet. So the following code might help you with auto-scheduling your blog posts:

<?php

# Auto-schedule blog posts

# Choose directories
$dir1 = 'content/USERNAME/blog/CATEGORY/draft';
$dir2 = 'content/USERNAME/blog/CATEGORY/post';

# Get current date
date_default_timezone_set('Asia/Manila');
$current = date('Y-m-d');

# Scan drafts folder excluding . and ..
$drafts = array_diff(scandir($dir1), array('..', '.'));

# Show all drafts
foreach ($drafts as $draft) {

  # Find drafts similar to current date
  if (substr($draft, 0, 10)==$current) {

    # Copy drafts to posts folder
    copy ($dir1."/".$draft, $dir2."/".$draft);
  }

}

?>

Note: You need to save this script as a PHP file and run it through a cron task in order to successfully automate the process.


On another note, I’ve also published an automatic backup system to send compressed files of your HTMLy content and settings via email. Still working on other features I could add and, if you’d like to contribute or view the work and awesome people behind the code, check out the HTMLy page on Github right here. I still need to learn more about how I can contribute via Github, though. Turns out I’m a little slow with my coding quests but we’ll get there soon. 🙂