Add post synchronization functionality for Markdown files
- Implemented a parser for YAML front-matter in Markdown files. - Developed functions to convert Markdown content to HTML. - Created a pipeline to sync WordPress posts from a specified folder in a Git repository. - Added media import capabilities to handle images referenced in Markdown. - Implemented author resolution and post slug generation. - Included error handling and logging for sync operations. - Enabled trashing of posts that are no longer present in the repository.
This commit is contained in:
@@ -105,13 +105,16 @@ function oribi_sync_execute_php( string $php_source, string $slug ) {
|
||||
*/
|
||||
function oribi_sync_run( bool $dry_run = false ): array {
|
||||
$result = [
|
||||
'ok' => true,
|
||||
'created' => [],
|
||||
'updated' => [],
|
||||
'trashed' => [],
|
||||
'skipped' => [],
|
||||
'errors' => [],
|
||||
'ok' => true,
|
||||
'created' => [],
|
||||
'updated' => [],
|
||||
'trashed' => [],
|
||||
'skipped' => [],
|
||||
'errors' => [],
|
||||
'theme_updated' => [],
|
||||
'posts_created' => [],
|
||||
'posts_updated' => [],
|
||||
'posts_trashed' => [],
|
||||
];
|
||||
|
||||
// ── Gather settings ────────────────────────────────────────────────────
|
||||
@@ -296,6 +299,18 @@ function oribi_sync_run( bool $dry_run = false ): array {
|
||||
$result['errors'][] = '[theme] ' . $err;
|
||||
}
|
||||
|
||||
// ── Sync posts from repo posts folder ─────────────────────────────────
|
||||
$posts_sync = oribi_sync_run_posts( $api_base, $branch, $provider, $pat, $tree, $dry_run );
|
||||
$result['posts_created'] = $posts_sync['created'];
|
||||
$result['posts_updated'] = $posts_sync['updated'];
|
||||
$result['posts_trashed'] = $posts_sync['trashed'];
|
||||
foreach ( $posts_sync['skipped'] as $sk ) {
|
||||
$result['skipped'][] = '[post] ' . $sk;
|
||||
}
|
||||
foreach ( $posts_sync['errors'] as $err ) {
|
||||
$result['errors'][] = '[post] ' . $err;
|
||||
}
|
||||
|
||||
// ── Record run ─────────────────────────────────────────────────────────
|
||||
if ( ! $dry_run ) {
|
||||
oribi_sync_record_run( $result );
|
||||
@@ -387,6 +402,9 @@ function oribi_sync_record_run( array $result ): void {
|
||||
'skipped' => $result['skipped'],
|
||||
'errors' => $result['errors'],
|
||||
'theme_updated' => $result['theme_updated'] ?? [],
|
||||
'posts_created' => $result['posts_created'] ?? [],
|
||||
'posts_updated' => $result['posts_updated'] ?? [],
|
||||
'posts_trashed' => $result['posts_trashed'] ?? [],
|
||||
] );
|
||||
|
||||
// Keep last 20 entries
|
||||
|
||||
Reference in New Issue
Block a user