diff --git a/.wordpress-org/screenshot-1.png b/.wordpress-org/screenshot-1.png index 12a19e9..1c61680 100644 Binary files a/.wordpress-org/screenshot-1.png and b/.wordpress-org/screenshot-1.png differ diff --git a/inc/class-statify-dashboard.php b/inc/class-statify-dashboard.php old mode 100755 new mode 100644 index 7866274..221fcbd --- a/inc/class-statify-dashboard.php +++ b/inc/class-statify-dashboard.php @@ -252,6 +252,15 @@ private static function select_data(): array { ); } + // Resolve post titles for the top targets. + // This runs over at most `limit` rows and is cached together with the + // rest of the widget data (see get_stats()), so the lookups happen only + // once per cache lifetime instead of on every dashboard render. + foreach ( $data['target'] as &$target ) { + $target['title'] = Statify_Evaluation::post_title( $target['url'] ); + } + unset( $target ); + if ( $show_totals ) { $data['visit_totals'] = array( 'today' => $wpdb->get_var( diff --git a/js/dashboard.js b/js/dashboard.js index f3896cd..c4f4f2b 100644 --- a/js/dashboard.js +++ b/js/dashboard.js @@ -532,8 +532,8 @@ /** * Render top list table. * - * @param {HTMLTableElement} table Table element. - * @param {{count: number, url: string, host: ?string}[]} data Data to display. + * @param {HTMLTableElement} table Table element. + * @param {{count: number, url: string, host: ?string, title: ?string}[]} data Data to display. */ function renderTopList(table, data) { const rows = data.map((r) => { @@ -544,15 +544,16 @@ row.appendChild(col); col = document.createElement('TD'); col.classList.add('t'); + const label = r.title || r.host || r.url; if (/^((https?:)?\/)?\//i.test(r.url)) { const link = document.createElement('A'); link.href = r.url; link.target = '_blank'; link.rel = 'noopener noreferrer'; - link.textContent = r.host || r.url; + link.textContent = label; col.appendChild(link); } else { - col.textContent = r.host || r.url; + col.textContent = label; } row.appendChild(col); return row;