Enhance Gitea support by improving base64 decoding and UTF-8 encoding handling
This commit is contained in:
@@ -858,8 +858,9 @@ function oribi_sync_trash_removed_posts( array $current_slugs ): array {
|
||||
function oribi_sync_generate_post_markdown( WP_Post $post ): string {
|
||||
$fm = "---\n";
|
||||
|
||||
// Title (escape newlines)
|
||||
$fm .= 'title: ' . str_replace( [ "\r", "\n" ], ' ', $post->post_title ) . "\n";
|
||||
// Title — decode HTML entities (WP stores & etc. in DB) so the YAML
|
||||
// file contains the literal character. On pull-back WP re-encodes correctly.
|
||||
$fm .= 'title: ' . str_replace( [ "\r", "\n" ], ' ', html_entity_decode( $post->post_title, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ) . "\n";
|
||||
$fm .= 'slug: ' . $post->post_name . "\n";
|
||||
$fm .= 'status: ' . $post->post_status . "\n";
|
||||
|
||||
@@ -874,27 +875,27 @@ function oribi_sync_generate_post_markdown( WP_Post $post ): string {
|
||||
$fm .= 'author: ' . $author->user_login . "\n";
|
||||
}
|
||||
|
||||
// Categories
|
||||
// Categories — decode HTML entities stored by WP
|
||||
$cats = get_the_category( $post->ID );
|
||||
if ( ! empty( $cats ) ) {
|
||||
$fm .= "categories:\n";
|
||||
foreach ( $cats as $cat ) {
|
||||
$fm .= ' - ' . $cat->name . "\n";
|
||||
$fm .= ' - ' . html_entity_decode( $cat->name, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Tags
|
||||
// Tags — decode HTML entities stored by WP
|
||||
$post_tags = get_the_tags( $post->ID );
|
||||
if ( ! empty( $post_tags ) ) {
|
||||
$fm .= "tags:\n";
|
||||
foreach ( $post_tags as $tag ) {
|
||||
$fm .= ' - ' . $tag->name . "\n";
|
||||
$fm .= ' - ' . html_entity_decode( $tag->name, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Excerpt
|
||||
// Excerpt — decode HTML entities stored by WP
|
||||
if ( ! empty( $post->post_excerpt ) ) {
|
||||
$fm .= 'excerpt: ' . str_replace( [ "\r", "\n" ], ' ', $post->post_excerpt ) . "\n";
|
||||
$fm .= 'excerpt: ' . str_replace( [ "\r", "\n" ], ' ', html_entity_decode( $post->post_excerpt, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ) . "\n";
|
||||
}
|
||||
|
||||
// Featured image (absolute URL so it round-trips cleanly)
|
||||
|
||||
Reference in New Issue
Block a user