//WORDPRESS //import MorePosts from 'components/Posts/MorePosts' 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 PortableText from 'react-portable-text' import { IoCalendarOutline, IoFolderOutline } from 'react-icons/io5' import { getImageLink } from '../../lib/wordpress.image' import { OpenGlobalEvent } from 'lib/popupimage' import Container from 'components/BlogContainer' import Layout from 'components/Layout' export default function PostWordpress(props) { const { loading, post, preview } = props const [contentHtml, contentHtmlSet] = useState('') const [evenGlobal, eventGlobalSet] = useState(false) //console.log('post contetn', post) //const featImgUrl = post.featured_media const featImgUrl = getImageLink( post._embedded['wp:featuredmedia'], post.featured_media ) const contentPost = parser(contentHtml) //console.log("content: ", contentPost) useEffect(() => { let popupimage = function () { //alert('whoe') } let searchImage = function (docu) { let imgc = [] let caption = [] ;(function sc(doc) { if (doc.tagName != 'IMG') { 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 += `
${(function () { if (caption[i]) { //console.log(caption[i]) return `

${caption[i]}

` } return `` })()}
` }) return { count: num, html: nh, } } let docWp = document.createElement('div') docWp.innerHTML = post.content.rendered //console.log(docWp) let newHtml = '' 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 === 'FIGURE') { let imgContainer = searchImage(content) let num = 3 if (imgContainer.count < 3) { num = imgContainer.count } newHtml += `
${imgContainer.html}
` } }) document.body.addEventListener('click', OpenGlobalEvent, false) contentHtmlSet(newHtml) return function cleanup() { window.removeEventListener('click', OpenGlobalEvent) } }, [contentHtml, post.content.rendered, evenGlobal]) const excerpt = post.excerpt.rendered.replace(/(<([^>]+)>)/gi, '') return ( ]+)>)/gi, '')` description={excerpt} additionalLinkTags={[ { rel: 'icon', href: '../favicon/favicon.ico', }, ]} openGraph={{ title: `${post.title.rendered}`, description: `${excerpt}`, url: 'https://www.gwkbali.com/monthly-release/' + `${post.slug}`, type: 'article', article: { publishedTime: `${post.date}`, // modifiedTime: '2018-01-21T18:04:43Z', // expirationTime: '2022-12-21T22:04:11Z', section: 'Monthly Release', // authors: [ // 'https://www.example.com/authors/@firstnameA-lastnameA', // 'https://www.example.com/authors/@firstnameB-lastnameB', // ], // tags: ['Tag A', 'Tag B', 'Tag C'], }, images: [ { url: featImgUrl, width: 850, height: 650, alt: `${post.title.rendered}`, }, ], }} />

 News & Media  {format(new Date(post.date), 'dd-MM-yyyy')}
{parser(contentHtml)}
{/*
*/}
{/* */}
) } export async function getStaticProps(data) { const post = await fetch( `https://cmswp.gwkbali.com/wp-json/wp/v2/mediacorner?slug=${ data?.params.slug || '' }&_embed` ).then((res) => res.json()) return { props: { post: post[0], }, } } export async function getStaticPaths() { const slugs = await fetch( 'https://cmswp.gwkbali.com/wp-json/wp/v2/mediacorner?_fields=slug&per_page=99' ).then((res) => res.json()) const paths = slugs?.map(({ slug }) => `/media-corner/${slug}`) || [] return { paths, fallback: false, } }