From 85b78651a1ed270d5a316c7abf4bf9060a77e890 Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Mon, 4 May 2020 20:53:33 -0400 Subject: [PATCH] fix: byline, avatar and date in carousel block (#455) * fix: byline, avatar and date in carousel block * feat: real author links for avatar and author name --- class-newspack-blocks-api.php | 8 +++++++ src/blocks/carousel/edit.js | 33 +++++++++---------------- src/blocks/homepage-articles/edit.js | 36 ++++------------------------ src/shared/js/utils.js | 34 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 54 deletions(-) create mode 100644 src/shared/js/utils.js diff --git a/class-newspack-blocks-api.php b/class-newspack-blocks-api.php index abd64694e..8133dbadf 100644 --- a/class-newspack-blocks-api.php +++ b/class-newspack-blocks-api.php @@ -172,6 +172,10 @@ public static function newspack_blocks_get_author_info( $object ) { } else { $author_avatar = coauthors_get_avatar( $author, 48 ); } + $author_link = null; + if ( function_exists( 'coauthors_posts_links' ) ) { + $author_link = get_author_posts_url( $author->ID, $author->user_nicename ); + } $author_data[] = array( /* Get the author name */ 'display_name' => esc_html( $author->display_name ), @@ -179,6 +183,8 @@ public static function newspack_blocks_get_author_info( $object ) { 'avatar' => wp_kses_post( $author_avatar ), /* Get the author ID */ 'id' => $author->ID, + /* Get the author Link */ + 'author_link' => $author_link, ); } else : @@ -189,6 +195,8 @@ public static function newspack_blocks_get_author_info( $object ) { 'avatar' => get_avatar( $object['author'], 48 ), /* Get the author ID */ 'id' => $object['author'], + /* Get the author Link */ + 'author_link' => get_author_posts_url( $object['author'] ), ); endif; diff --git a/src/blocks/carousel/edit.js b/src/blocks/carousel/edit.js index d5f7b072c..364d3a300 100644 --- a/src/blocks/carousel/edit.js +++ b/src/blocks/carousel/edit.js @@ -5,19 +5,20 @@ */ import QueryControls from '../../components/query-controls'; import createSwiper from './create-swiper'; -import classnames from 'classnames'; +import { formatAvatars, formatByline } from '../../shared/js/utils'; /** * External dependencies */ import { isUndefined, pickBy } from 'lodash'; -import moment from 'moment'; +import classnames from 'classnames'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { Component, createRef, Fragment, RawHTML } from '@wordpress/element'; +import { dateI18n, __experimentalGetSettings } from '@wordpress/date'; +import { Component, createRef, Fragment } from '@wordpress/element'; import { InspectorControls } from '@wordpress/editor'; import { PanelBody, @@ -78,6 +79,7 @@ class Edit extends Component { {} ); } + render() { const { attributes, className, setAttributes, latestPosts } = this.props; const { autoPlayState } = this.state; @@ -99,7 +101,7 @@ class Edit extends Component { 'swiper-container', autoplay && autoPlayState && 'wp-block-newspack-blocks-carousel__autoplay-playing' ); - + const dateFormat = __experimentalGetSettings().formats.date; return (
@@ -133,26 +135,13 @@ class Edit extends Component { { decodeEntities( post.title.rendered.trim() ) }
- { showAuthor && showAvatar && post.newspack_author_info.avatar && ( - - { post.newspack_author_info.avatar } - - ) } - { showAuthor && ( - - { __( 'by' ) }{' '} - - - { post.newspack_author_info.display_name } - - - - ) } + { showAuthor && + showAvatar && + formatAvatars( post.newspack_author_info ) } + { showAuthor && formatByline( post.newspack_author_info ) } { showDate && ( ) }
diff --git a/src/blocks/homepage-articles/edit.js b/src/blocks/homepage-articles/edit.js index 302a33e7a..6cbf61715 100644 --- a/src/blocks/homepage-articles/edit.js +++ b/src/blocks/homepage-articles/edit.js @@ -6,6 +6,7 @@ import QueryControls from '../../components/query-controls'; import { STORE_NAMESPACE } from './store'; import { isBlogPrivate, isSpecificPostModeActive, queryCriteriaFromAttributes } from './utils'; +import { formatAvatars, formatByline } from '../../shared/js/utils'; /** * External dependencies @@ -15,7 +16,7 @@ import classNames from 'classnames'; /** * WordPress dependencies */ -import { __, _x } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; import { dateI18n, __experimentalGetSettings } from '@wordpress/date'; import { Component, Fragment, RawHTML } from '@wordpress/element'; import { @@ -178,8 +179,8 @@ class Edit extends Component { ) }
- { showAuthor && showAvatar && this.formatAvatars( post.newspack_author_info ) } - { showAuthor && this.formatByline( post.newspack_author_info ) } + { showAuthor && showAvatar && formatAvatars( post.newspack_author_info ) } + { showAuthor && formatByline( post.newspack_author_info ) } { showDate && (