diff --git a/components/Obituary/components/ObituaryLarge.tsx b/components/Obituary/components/ObituaryLarge.tsx index f68d35f..da6270f 100644 --- a/components/Obituary/components/ObituaryLarge.tsx +++ b/components/Obituary/components/ObituaryLarge.tsx @@ -29,6 +29,7 @@ export const ObituaryLarge: ObituaryRenderer = ({ initialData: props, }) const { + _id, firstname, name_misc, surname, @@ -51,12 +52,20 @@ export const ObituaryLarge: ObituaryRenderer = ({ } = data const { t } = useTranslation() - const shareToFacebook = useCallback(() => { + const shareToFacebook = useCallback(async () => { + const shareUrl = `${window.location.origin}/${type}/${_id}` window?.FB?.ui({ display: 'popup', method: 'share', - href: window.location.href, + href: shareUrl, }) + // if (navigator?.canShare?.()) { + // await navigator.share({ + // title: 'Herro', + // text: 'Learn web development on MDN!', + // url: 'https://developer.mozilla.org', + // }) + // } }, []) return ( diff --git a/lib/domain/formatLongText.ts b/lib/domain/formatLongText.ts new file mode 100644 index 0000000..b2853b6 --- /dev/null +++ b/lib/domain/formatLongText.ts @@ -0,0 +1,11 @@ +import { IObituary } from './types' +import ReactDOMServer from 'react-dom/server' + +import { render } from 'storyblok-rich-text-react-renderer' + +const htmlTagsRegexp = /<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g + +export const stringifyLongText = (text: IObituary['long_text']): string => + typeof text === 'string' + ? text.replace(htmlTagsRegexp, '') + : ReactDOMServer.renderToString(render(text)).replace(htmlTagsRegexp, '') diff --git a/next.config.js b/next.config.js index e6519bf..0d644f3 100644 --- a/next.config.js +++ b/next.config.js @@ -21,6 +21,15 @@ module.exports = (phase, { defaultConfig }) => { }, ], }, + // { + // source: '/', + // headers: [ + // { + // key: 'Permissions-Policy', + // value: 'web-share=*', + // }, + // ], + // }, ] }, async rewrites() { diff --git a/pages/[category]/[id].tsx b/pages/[category]/[id].tsx index d341f32..3d865fa 100644 --- a/pages/[category]/[id].tsx +++ b/pages/[category]/[id].tsx @@ -13,6 +13,7 @@ import { ObituaryLarge } from '../../components/Obituary/components/ObituaryLarg import { connectToDb } from '../../db' import { createMetaTitle } from '../../lib/domain' import { IObituary } from '../../lib/domain/types' +import { stringifyLongText } from 'lib/domain/formatLongText' const capitalize = (str = '') => str?.[0]?.toLocaleUpperCase() + str.slice(1) @@ -49,8 +50,11 @@ export default function Obituary({ content={typeof image === 'string' ? image : image.filename} /> )} - {typeof long_text === 'string' && ( - + {long_text && ( + )}
+ + {process.env.NODE_ENV === 'production' && ( <> {/* */} @@ -38,27 +65,6 @@ class MyDocument extends Document { )}