Skip to content

Commit 09728ec

Browse files
committed
change to title logic, check YAML for excerpt too
1 parent 3a106c8 commit 09728ec

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

inc/class-importer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,20 @@ protected function update_post_from_markdown_source( $post_id ) {
294294
}
295295

296296
$title = null;
297+
if ( preg_match( '/^\n*#\s(.+)/', $markdown, $matches ) ) {
298+
$title = $matches[1];
299+
$markdown = preg_replace( '/^\n*#\swp\s(.+)/', '', $markdown );
300+
}
301+
// Allow YAML override.
297302
if ( isset( $yaml['title'] ) ) {
298303
$title = $yaml['title'];
299-
} elseif ( preg_match( '/^\n*#\s(.+)/', $markdown, $matches ) ) {
300-
$title = $matches[1];
301-
$markdown = preg_replace( '/^\n*#\swp\s(.+)/', '', $markdown );
302304
}
303305
$markdown = trim( $markdown );
304306

305307
// Steal the first sentence as the excerpt
306308
$excerpt = '';
307309
if ( preg_match( '/^(.+)/', $markdown, $matches ) ) {
308-
$excerpt = $matches[1];
310+
$excerpt = $matches[1];
309311
$markdown = preg_replace( '/^(.+)/', '', $markdown );
310312
}
311313

@@ -322,6 +324,9 @@ protected function update_post_from_markdown_source( $post_id ) {
322324
if ( ! is_null( $title ) ) {
323325
$post_data['post_title'] = sanitize_text_field( wp_slash( $title ) );
324326
}
327+
if ( isset( $yaml['description'] ) ) {
328+
$post_data['post_excerpt'] = sanitize_text_field( wp_slash( $yaml['description'] ) );
329+
}
325330
if ( isset( $yaml['published'] ) ) {
326331
$post_data['post_status'] = (bool) $yaml['published'] ? 'publish' : 'draft';
327332
}

0 commit comments

Comments
 (0)