---
import Layout from '@/layouts/Layout.astro'
import Footer from '@/components/Footer.astro'
import Navbar from '@/components/Navbar.astro'
import ScrollingNavbar from '@/components/ScrollingNavbar.astro'
import { getPostById } from '@/services/apis'
const { lang = 'zh' } = Astro.params
console.log('---------fff------>', lang)
var url = new URL(Astro.request.url)
var id = url.searchParams.get('id')
// const post = await getPostById(id)
function getContent(item = {}) {
  return (
    item[`content${lang.charAt(0).toUpperCase() + lang.slice(1)}`] ||
    item.contentEn ||
    item.contentZh
  )
}

// 使用中文标题即ID
// 保存所有生成的 id
const ids = []

function appendHId(html) {
  const reg = /(<)(h\d)(>(.*?)<\/h\d>)/g

  return html.replaceAll(reg, (_, p1, p2, p3, p4) => {
    ids.push(p4)
    return `${p1}${p2} id="${p4}"${p3}`
  })
}

// let contentHtml = getContent(post)
// contentHtml = appendHId(contentHtml)
---

<Layout>
  <Navbar lang={lang} />
  <ScrollingNavbar sNav={ids} />
  <div class="container-fulid" style="margin-top: 9rem;background-color:#fff">
    <div class="container">
      <div style="word-break:break-word">
        <!-- <Fragment set:html={contentHtml} /> -->
      </div>
    </div>
  </div>
  <Footer lang={lang} />
</Layout>
