Scroll to top

18/08/2021


1 comment: click to read or leave your own

More on post titles

After adding the per-post title toggle I got to wondering how I could make things even simpler. Or, at least, provide more choice.

Inspired by the likes of Drafts and Ulysses, I thought it might be nice to use the first line of a post as the title if it was marked up as a Markdown H1 tag.

First line post title

If a post is written in this way, the blog and drafts pages (along with the RSS feed generators) check the content and separate out the title before reconstructing the remaining text as the content:

$post_array = explode("\n", $content);
$size = sizeof($post_array);
if (substr($post_array[0], 0, 2) == "# ") {
  $length = strlen($post_array[0]);
  $required = $length - 2;
  $post_title = substr($post_array[0], 2, $required);
  $title_in_body = true;
  $content = '';
  for ($i = 2; $i < $size; $i++) {
    $content .= $post_array[$i];
  }
}

It's always good to have a choice.

Leave a reply



You can also:

Click here to reply using email Reply by email Send a webmention Send a Webmention



No comments yet
Leave a reply



You can also:

Click here to reply using email Reply by email Send a webmention Send a Webmention



No comments yet
Leave a reply



You can also:

Click here to reply using email Reply by email Send a webmention Send a Webmention



Close