import React , {FC} from 'react' import { __, sprintf } from '@wordpress/i18n'; import { RawHTML } from '@wordpress/element'; import { format } from '@wordpress/date'; import { AlgoliaHit, HitItemVisibleConfig } from '../../block.interfaces' const Content: FC<{ hit: Pick; attributes: Pick; }> = ({hit, attributes: { displayPostContentRadio, excerptLength, }}) => { if (displayPostContentRadio === 'hide') return null; if (displayPostContentRadio === 'excerpt') { const excerpt = hit.post_excerpt || hit.content const needsReadMore = excerptLength < excerpt.trim().split( ' ' ).length const postExcerpt = needsReadMore ? ( <> { excerpt .trim() .split( ' ', excerptLength ) .join( ' ' ) } { /* translators: excerpt truncation character, default … */ } { __( ' … ' ) } { __( 'Read more' ) } ) : ( <>{excerpt} ); return (
{postExcerpt}
) } return (
) } export const HitItem: FC<{ hit: AlgoliaHit; attributes: HitItemVisibleConfig }> = ({hit, attributes: { displayPostAuthor, displayPostCategory, displayPostDate, displayPostTags, displayPostContentRadio, excerptLength, }}) => { return ( <> {hit.post_title} {displayPostAuthor ? (
{ sprintf( /* translators: byline. %s: current author. */ __( 'by %s' ), hit.post_author.display_name ) }
): null} {displayPostDate ? ( ): null} {hit.taxonomies ? ( <> {displayPostCategory && hit.taxonomies.category ? (
{__('Categories')}: {hit.taxonomies.category.map(category => ( {category} ))}
): null} {displayPostTags && hit.taxonomies.post_tag ? (
{__('Tags')}: {hit.taxonomies.post_tag.map(tag => ( {tag} ))}
): null} ): null} ) }