import { h } from 'preact'; import PropTypes from 'prop-types'; /* global timeAgo */ function userProfilePage(username) { const str = `/${username}`; return str; } function contentAwareComments(comment) { const parser = new DOMParser(); const htmlDoc = parser.parseFromString( comment.safe_processed_html, 'text/html', ); const nodes = htmlDoc.body.childNodes; let text = ''; let nodesSelected = 0; nodes.forEach((node) => { if ( node.outerHTML && (node.tagName === 'P' || node.className.includes('highlight')) && nodesSelected < 2 && node.outerHTML.length > 250 && !node.outerHTML.includes('article-body-image-wrapper') ) { node.innerHTML = `${node.innerHTML.substring(0, 230)}...`; text = `${text} ${node.outerHTML}`; nodesSelected = 2; } else if (node.outerHTML && nodesSelected < 2) { text = text + node.outerHTML; nodesSelected++; } else if (node.outerHTML && nodesSelected < 3) { text = `${text}
See more
`; nodesSelected++; } }); return text; } export const CommentListItem = ({ comment }) => (
{ if (_event.target.closest('a')) { return; } if (_event.which > 1 || _event.metaKey || _event.ctrlKey) { // Indicates should open in _blank window.open(comment.path, '_blank'); } else { const fullUrl = window.location.origin + comment.path; // InstantClick deals with full urls InstantClick.preload(fullUrl); InstantClick.display(fullUrl); } }} >
{comment.username} avatar
); CommentListItem.displayName = 'CommentsListItem'; CommentListItem.propTypes = { comment: PropTypes.shape({ name: PropTypes.string.isRequired, profile_image_90: PropTypes.string.isRequired, published_at_int: PropTypes.number.isRequired, safe_processed_html: PropTypes.string.isRequired, path: PropTypes.string.isRequired, username: PropTypes.string.isRequired, }).isRequired, };