---
import Layout from "../layouts/Layout.astro";
import { getConfig } from '../../utils/config'
import '../assets/css1/style.css'
import '../assets/css1/style5.css'
import { newsIndex } from "../../utils/rpc";
import { Image } from "astro:assets";
const config = getConfig(Astro)

const {code, data} = await newsIndex(config.id);

if (!data || code !== 0) {
  return Astro.redirect('/404');
}

---
<Layout>
    <div class="site-content">
        <!-- Page-Header Section STARTS Here -->
        <div class="page-header text-center">
            <div class="container">
                <h1 class="page-title">新闻中心</h1>
                <ul id="breadcrumbs" class="breadcrumbs">
                    <li>             
                    <a href='/' class='crumb'>首页</a> &gt; <a href='/news' class='crumb'>新闻中心</a>
                    </li>
                </ul>
            </div>
        </div>
        <!-- Page-Header Section End Here -->
        <!-- Blog Grid Section Start Here -->
        <section class="blog-page">
            <div class="container">
                <div class="row">
                    {
                        data?.map(e => {
                            return <div class="col-lg-4 col-md-6">
                                <div class="post-inner">
                                    <div class="entry-media">                           
                                        <a  href={`/news/${e.id}`} title={`${e.title}`}>
                                            <Image loading="eager" style={`aspect-ratio: 4 / 3;object-fit: cover;`} src={e.cover} alt={e.title} width={100} height={100} />
                                        </a>
                                    </div>
                                    <div class="inner-post">
                                        <div class="entry-header">
                                            <div class="entry-meta">                                    
                                                <span class="posted-on">
                                                    <span><time class="entry-date published">{e.created_at}</time></span>
                                                </span>
                                            </div>    
                                            <a href={`/news/${e.id}`} title={`${e.title}`} class="entry-title">{e.title}</a>
                                        </div>
                                        <p class="entry-summary">{e.description}</p>
                                    </div>
                                </div>
                            </div>
                        })
                    }
                </div>
            </div>
        </section>
        <!-- Blog Grid Section End Here -->
    </div>
</Layout>