htmly icon indicating copy to clipboard operation
htmly copied to clipboard

Just a question. How do I import an already made MD into HTMLy?

Open AutomationMan808 opened this issue 4 years ago • 2 comments

Before I asked in issues I did look for a forum.

Rick

AutomationMan808 avatar Jul 29 '21 05:07 AutomationMan808

Please read:

  • https://github.com/danpros/htmly#both-online-or-offline
  • https://github.com/danpros/htmly#category
  • https://github.com/danpros/htmly#file-naming-convention
  • https://github.com/danpros/htmly#content-tags

bttrx avatar May 29 '22 20:05 bttrx

Basically you have to copy and adapt the following code to your needs, add the code to obtain your MD through a form and add a new admin menu item to invoke the importing code from the admin UI. This code will not work for you but I used it in my web site for autoposting:

// Add content function add_my_content($title, $post_tag, $pmid, $content, $description = null, $category, $type) { $post_date = date('Y-m-d-H-i-s');

/* Deal with title */
$post_title = "\n<!--t " . $title . " t-->";

/* Deal with short description */
$post_description = "\n<!--d " . $description . " d-->";

/* Deal with tag */
$posttag = "\n<!--tag " . $post_tag . " tag-->";

/* Deal with desired URL */
$target_URL = preg_replace("/[^A-Za-z0-9]/", '-', $pmid);

/* Deal with content */
$post_content = $post_title . $post_description . $posttag . "\n\n" . $content;
if (!empty($post_title) && !empty($post_tag) && !empty($pmid) && !empty($post_content)) {
    if (get_magic_quotes_gpc()) {
        $post_content = stripslashes($post_content);
    }
    $filename = $post_date . '_' . $post_tag . '_' . $target_URL . '.md';

    $dir = __DIR__ . '/../../content/admin/blog/english/post/';

    // We now search if a file with the same pmid had already been posted

    $matches = glob($dir . '????-??-??-??-??-??_??????_' . $pmid . '.md');

    // If $matches == false, then there is no such file in the content database
    // If $matches != false, there is already a file with this pmid, so we do nothing
    if ($matches == false) {
        if (is_dir($dir)) {
            $resfpc = file_put_contents($dir . $filename, print_r($post_content, true));
            if ($resfpc === false) {
                echo '<br>Failure 1 in writing content at: ' . $dir;
                die();
            }
        } else {
            mkdir($dir, 0775, true);
            $resfpc = file_put_contents($dir . $filename, print_r($post_content, true));
            if ($resfpc === false) {
                echo '<br>Failure 2 in writing content at: ' . $dir;
                die();
            }
        }
        // Clear cache
        $files = glob(__DIR__ . '/../../cache/index/*'); // get all file names
        foreach ($files as $file) { // iterate files
            if (is_file($file)) {
                unlink($file); // delete file
            }
        }
    }
}

// https://yourdomain2021/08/desiredurl
return '/' . date('Y/m') . '/' . $target_URL;

}

Hjertesvikt avatar May 30 '22 07:05 Hjertesvikt

@AutomationMan808 If your question has been answered, please close this issue. Thanks!

bttrx avatar Oct 29 '22 15:10 bttrx