//WORDPRESS import parser from 'html-react-parser' import Link from 'next/link' import { useEffect, useState } from 'react' import { NextSeo } from 'next-seo' import { format } from 'date-fns' import { IoCalendarOutline, IoFolderOutline } from 'react-icons/io5' import PortableText from 'react-portable-text' import { getImageLink } from '../../lib/wordpress.image' import { OpenGlobalEvent } from 'lib/popupimage' import Container from 'components/BlogContainer' import Layout from 'components/Layout' import { GetServerSideProps } from 'next' export default function PostWordpress(props) { const { loading, post, preview } = props const [contentHtml, contentHtmlSet] = useState('') const [evenGlobal, eventGlobalSet] = useState(false) const featImgUrl = getImageLink( post._embedded['wp:featuredmedia'], post.featured_media ) // console.log(contentHtml) //let postContentString: string = contentHtml //let postContent: contentHtml = postContentString as contentHtmlSet useEffect(() => { let popupimage = function () { alert('whoe') } let searchImage = function (docu) { let imgc = [] let caption = [] ;(function sc(doc) { if (doc.tagName != 'IMG' && doc.tagName != 'FIGCAPTION') { if (Array.from(doc.children).length > 0) { Array.from(doc.children).forEach(function (e) { sc(e) }) } } else { if (doc.src) { imgc.push(doc.src) } else { caption.push(doc.innerHTML) } } })(docu) let nh = '' let num = 0 imgc.forEach(function (l, i) { num++ nh += `
` }) return { count: num, html: nh, } } let docWp = document.createElement('div') docWp.innerHTML = post.content.rendered let newHtml = '' //console.log(docWp) Array.from(docWp.children).forEach(function (content) { if ( content.tagName === 'H2' || content.tagName === 'H1' || content.tagName === 'H3' || content.tagName === 'H4' || content.tagName === 'H5' || content.tagName === 'H6' ) { content.className = 'text-stone-600 leading-loose font-sans mb-3' newHtml += content.outerHTML } if (content.tagName === 'DIV') { content.className = 'text-stone-600 leading-loose font-sans mb-3' newHtml += content.outerHTML } if (content.tagName === 'P') { content.className = 'text-stone-600 leading-loose font-sans mb-3' newHtml += content.outerHTML } if (content.tagName === 'A') { content.className = 'text-yellow-600 leading-loose font-sans mb-3' newHtml += content.outerHTML } if (content.tagName === 'FIGURE') { let imgContainer = searchImage(content) let num = 3 if (imgContainer.count < 3) { num = imgContainer.count } newHtml += `{children}
), strong: ({ children }) => ( {children} ), li: ({ children }) => (