fix: resolve actual article source instead of showing aggregator domain
Google News RSS feeds report every article as coming from
"news.google.com" because the source was extracted from the feed URL
rather than the individual article. This adds a multi-strategy
resolver that extracts the real publisher name via:
1. SimplePie <source> element (Google News provides this)
2. Title suffix parsing ("Headline - Source" format)
3. HTTP HEAD redirect resolution as a fallback
Also adds a one-click "Fix Article Sources" backfill button on the
settings page to correct existing articles in the database.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -61,9 +61,10 @@ class Peptide_News_Admin {
|
||||
);
|
||||
|
||||
wp_localize_script( $this->plugin_name . '-admin', 'peptideNewsAdmin', array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'rest_url' => rest_url( 'peptide-news/v1/' ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'rest_url' => rest_url( 'peptide-news/v1/' ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'admin_nonce' => wp_create_nonce( 'peptide_news_admin' ),
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -556,11 +557,42 @@ class Peptide_News_Admin {
|
||||
echo '<h1>' . esc_html( get_admin_page_title() ) . '</h1>';
|
||||
|
||||
// Fetch Now button.
|
||||
echo '<form method="post">';
|
||||
echo '<form method="post" style="display:inline-block;margin-right:12px;">';
|
||||
wp_nonce_field( 'peptide_news_fetch_now_action' );
|
||||
submit_button( __( 'Fetch Articles Now', 'peptide-news' ), 'secondary', 'peptide_news_fetch_now' );
|
||||
submit_button( __( 'Fetch Articles Now', 'peptide-news' ), 'secondary', 'peptide_news_fetch_now', false );
|
||||
echo '</form>';
|
||||
|
||||
// Backfill Sources button (fixes "news.google.com" source labels).
|
||||
echo '<button type="button" id="peptide-backfill-sources" class="button button-secondary">';
|
||||
echo esc_html__( 'Fix Article Sources', 'peptide-news' );
|
||||
echo '</button>';
|
||||
echo '<span id="peptide-backfill-result" style="margin-left:10px;"></span>';
|
||||
?>
|
||||
<script>
|
||||
(function($) {
|
||||
$('#peptide-backfill-sources').on('click', function() {
|
||||
var $btn = $(this), $result = $('#peptide-backfill-result');
|
||||
$btn.prop('disabled', true).text('<?php echo esc_js( __( 'Fixing...', 'peptide-news' ) ); ?>');
|
||||
$result.text('');
|
||||
$.post(peptideNewsAdmin.ajax_url, {
|
||||
action: 'peptide_news_backfill_sources',
|
||||
nonce: peptideNewsAdmin.admin_nonce
|
||||
}, function(response) {
|
||||
$btn.prop('disabled', false).text('<?php echo esc_js( __( 'Fix Article Sources', 'peptide-news' ) ); ?>');
|
||||
if (response.success) {
|
||||
$result.text(response.data.updated + ' article(s) updated.');
|
||||
} else {
|
||||
$result.text('Error: ' + (response.data || 'Unknown error'));
|
||||
}
|
||||
}).fail(function() {
|
||||
$btn.prop('disabled', false).text('<?php echo esc_js( __( 'Fix Article Sources', 'peptide-news' ) ); ?>');
|
||||
$result.text('Request failed.');
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
<?php
|
||||
|
||||
// Last fetch info.
|
||||
$last_fetch = get_option( 'peptide_news_last_fetch' );
|
||||
if ( $last_fetch ) {
|
||||
|
||||
Reference in New Issue
Block a user