resolve conversation
This commit is contained in:
parent
335069ff83
commit
2c063df914
|
@ -6,7 +6,7 @@ import { createMemo, For, Match, onMount, Show, Switch } from 'solid-js'
|
||||||
import type { Author, Shout } from '../../graphql/types.gen'
|
import type { Author, Shout } from '../../graphql/types.gen'
|
||||||
import { t } from '../../utils/intl'
|
import { t } from '../../utils/intl'
|
||||||
import MD from './MD'
|
import MD from './MD'
|
||||||
import { SharePopup } from './SharePopup'
|
import { getShareUrl, SharePopup } from './SharePopup'
|
||||||
import { getDescription } from '../../utils/meta'
|
import { getDescription } from '../../utils/meta'
|
||||||
import stylesHeader from '../Nav/Header.module.scss'
|
import stylesHeader from '../Nav/Header.module.scss'
|
||||||
import styles from '../../styles/Article.module.scss'
|
import styles from '../../styles/Article.module.scss'
|
||||||
|
@ -174,7 +174,7 @@ export const FullArticle = (props: ArticleProps) => {
|
||||||
title={props.article.title}
|
title={props.article.title}
|
||||||
description={getDescription(props.article.body)}
|
description={getDescription(props.article.body)}
|
||||||
imageUrl={props.article.cover}
|
imageUrl={props.article.cover}
|
||||||
shareUrl={location.href}
|
shareUrl={getShareUrl()}
|
||||||
containerCssClass={stylesHeader.control}
|
containerCssClass={stylesHeader.control}
|
||||||
trigger={<Icon name="share-outline" class={styles.icon} />}
|
trigger={<Icon name="share-outline" class={styles.icon} />}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Icon } from '../_shared/Icon'
|
import { Icon } from '../_shared/Icon'
|
||||||
import { t } from '../../utils/intl'
|
import { t } from '../../utils/intl'
|
||||||
import { createSocialShare, TWITTER, VK, FACEBOOK, TELEGRAM } from '@solid-primitives/share'
|
import { createSocialShare, TWITTER, VK, FACEBOOK, TELEGRAM } from '@solid-primitives/share'
|
||||||
|
|
||||||
import styles from '../_shared/Popup/Popup.module.scss'
|
import styles from '../_shared/Popup/Popup.module.scss'
|
||||||
import type { PopupProps } from '../_shared/Popup'
|
import type { PopupProps } from '../_shared/Popup'
|
||||||
import { Popup } from '../_shared/Popup'
|
import { Popup } from '../_shared/Popup'
|
||||||
|
@ -13,6 +12,12 @@ type SharePopupProps = {
|
||||||
description: string
|
description: string
|
||||||
} & Omit<PopupProps, 'children'>
|
} & Omit<PopupProps, 'children'>
|
||||||
|
|
||||||
|
export const getShareUrl = (params: { pathname?: string } = {}) => {
|
||||||
|
if (typeof location === 'undefined') return ''
|
||||||
|
const pathname = params.pathname ?? location.pathname
|
||||||
|
return location.origin + pathname
|
||||||
|
}
|
||||||
|
|
||||||
export const SharePopup = (props: SharePopupProps) => {
|
export const SharePopup = (props: SharePopupProps) => {
|
||||||
const [share] = createSocialShare(() => ({
|
const [share] = createSocialShare(() => ({
|
||||||
title: props.title,
|
title: props.title,
|
||||||
|
@ -20,7 +25,7 @@ export const SharePopup = (props: SharePopupProps) => {
|
||||||
description: props.description
|
description: props.description
|
||||||
}))
|
}))
|
||||||
const copyLink = async () => {
|
const copyLink = async () => {
|
||||||
await navigator.clipboard.writeText(window.location.href)
|
await navigator.clipboard.writeText(props.shareUrl)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Popup {...props} variant="bordered">
|
<Popup {...props} variant="bordered">
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { locale } from '../../stores/ui'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { CardTopic } from './CardTopic'
|
import { CardTopic } from './CardTopic'
|
||||||
import { RatingControl } from '../Article/RatingControl'
|
import { RatingControl } from '../Article/RatingControl'
|
||||||
import { SharePopup } from '../Article/SharePopup'
|
import { getShareUrl, SharePopup } from '../Article/SharePopup'
|
||||||
import stylesHeader from '../Nav/Header.module.scss'
|
import stylesHeader from '../Nav/Header.module.scss'
|
||||||
import { getDescription } from '../../utils/meta'
|
import { getDescription } from '../../utils/meta'
|
||||||
|
|
||||||
|
@ -73,12 +73,6 @@ export const ArticleCard = (props: ArticleCardProps) => {
|
||||||
|
|
||||||
const { cover, layout, slug, authors, stat } = props.article
|
const { cover, layout, slug, authors, stat } = props.article
|
||||||
|
|
||||||
const [url, setUrl] = createSignal<string>(null)
|
|
||||||
onMount(() => {
|
|
||||||
const composeUrl = new URL(location.href)
|
|
||||||
setUrl(composeUrl.origin)
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
class={clsx(styles.shoutCard, `${props.settings?.additionalClass || ''}`)}
|
class={clsx(styles.shoutCard, `${props.settings?.additionalClass || ''}`)}
|
||||||
|
@ -203,7 +197,7 @@ export const ArticleCard = (props: ArticleCardProps) => {
|
||||||
title={props.article['title']}
|
title={props.article['title']}
|
||||||
description={getDescription(props.article['body'])}
|
description={getDescription(props.article['body'])}
|
||||||
imageUrl={props.article['cover']}
|
imageUrl={props.article['cover']}
|
||||||
shareUrl={`${url()}/${slug}`}
|
shareUrl={getShareUrl({ pathname: `/${slug}` })}
|
||||||
trigger={
|
trigger={
|
||||||
<button>
|
<button>
|
||||||
<Icon name="share-outline" class={clsx(styles.icon, styles.feedControlIcon)} />
|
<Icon name="share-outline" class={clsx(styles.icon, styles.feedControlIcon)} />
|
||||||
|
|
|
@ -9,7 +9,7 @@ import styles from './Header.module.scss'
|
||||||
import { getPagePath } from '@nanostores/router'
|
import { getPagePath } from '@nanostores/router'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { HeaderAuth } from './HeaderAuth'
|
import { HeaderAuth } from './HeaderAuth'
|
||||||
import { SharePopup } from '../Article/SharePopup'
|
import { getShareUrl, SharePopup } from '../Article/SharePopup'
|
||||||
import { getDescription } from '../../utils/meta'
|
import { getDescription } from '../../utils/meta'
|
||||||
|
|
||||||
const resources: { name: string; route: keyof Routes }[] = [
|
const resources: { name: string; route: keyof Routes }[] = [
|
||||||
|
@ -128,7 +128,7 @@ export const Header = (props: Props) => {
|
||||||
<SharePopup
|
<SharePopup
|
||||||
title={props.title}
|
title={props.title}
|
||||||
imageUrl={props.cover}
|
imageUrl={props.cover}
|
||||||
shareUrl={location.href}
|
shareUrl={getShareUrl()}
|
||||||
description={getDescription(props.articleBody)}
|
description={getDescription(props.articleBody)}
|
||||||
onVisibilityChange={(isVisible) => {
|
onVisibilityChange={(isVisible) => {
|
||||||
setIsSharePopupVisible(isVisible)
|
setIsSharePopupVisible(isVisible)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
export const getDescription = (body: string) => {
|
export const getDescription = (body: string): string => {
|
||||||
if (!body) return null
|
if (!body) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
const descriptionWordsArray = body
|
const descriptionWordsArray = body
|
||||||
.slice(0, 150)
|
.slice(0, 150) // meta description is roughly 155 characters long
|
||||||
.replaceAll(/<[^>]*>/g, '')
|
.replaceAll(/<[^>]*>/g, '')
|
||||||
.split(' ')
|
.split(' ')
|
||||||
return descriptionWordsArray.splice(0, descriptionWordsArray.length - 1).join(' ') + '...'
|
return descriptionWordsArray.splice(0, descriptionWordsArray.length - 1).join(' ') + '...'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user