//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 += `
${(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 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 += `
${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}`, }, ], }} />

 Monthly Update  {format(new Date(post.date), 'dd-MM-yyyy')}
{parser(contentHtml)}
{/* (

{children}

), strong: ({ children }) => ( {children} ), li: ({ children }) => (
  • {children}
  • ), }} /> */}
    {/* */}
    ) } export const el = function (el = 'div') { let f = document.createElement(el) as HTMLElement return f } export const getServerSideProps: GetServerSideProps = async (data) => { const post = await fetch( `https://cmswp.gwkbali.com/wp-json/wp/v2/monthly-release?slug=${ data?.params.slug || '' }&_embed` ).then((res) => res.json()) //console.log(post); return { props: { post: post[0], }, } } // export async function getStaticPaths() { // const slugs = await fetch( // 'https://cmswp.gwkbali.com/wp-json/wp/v2/monthly-release?_fields=slug&per_page=99' // ).then((res) => res.json()) // const paths = slugs?.map(({ slug }) => `/monthly-release/${slug}`) || [] // return { // paths, // fallback: false, // } // }