Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 31 additions & 61 deletions src/components/NewsPostPreview.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,36 @@ import { formatDateWithoutWeekday } from '../scripts/date.js';

const { entry, n } = Astro.props;
const { frontmatter } = entry;
---

{
n % 2 == 0 && (
<div class="flex flex-wrap -mx-4 mb-20">
<div class="w-full lg:w-1/2 px-4 lg:pr-20 lg:pt-4 order-1 lg:order-0">
<span class="inline-block py-1 px-3 uppercase text-xs font-semibold bg-red-50 rounded-full text-red-600">
<time class="date" datetime={frontmatter.pubDate}>
{formatDateWithoutWeekday(frontmatter.pubDate)}
</time>
</span>
<h3 class="my-4 text-xl md:text-2xl font-bold font-heading">
<a href={entry.url} title={frontmatter.title}>
{frontmatter.title}
</a>
</h3>
<p class="mb-4 text-sm md:text-base leading-loose text-blueGray-500">{frontmatter.description}</p>
<a class="text-base font-semibold text-sourcectl-orange" href={entry.url} title={frontmatter.title}>
<span>Read More</span>
<svg class="inline-block w-4 h-4 ml-1" fill="none" stroke="currentColor" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3" />
</svg>
</a>
</div>
<div class="w-full lg:w-1/2 px-4 mb-8 order-0 lg:order-1">
<a href={entry.url} title={frontmatter.title}>
<img class="w-full h-80 object-cover rounded" src={frontmatter.coverImage} alt={frontmatter.title} title={frontmatter.title} />
</a>
</div>
</div>
)
}
const isEven = n % 2 === 0;
const textPadding = isEven ? 'lg:pr-20' : 'lg:pl-20';
const textOrder = isEven ? 'order-1 lg:order-0' : 'order-1';
const imageOrder = isEven ? 'order-0 lg:order-1' : 'order-0';
---

{
n % 2 > 0 && (
<div class="flex flex-wrap -mx-4 mb-20">
<div class="w-full lg:w-1/2 px-4 lg:pl-20 lg:pt-4 order-1">
<span class="inline-block py-1 px-3 uppercase text-xs font-semibold bg-red-50 rounded-full text-red-600">
<time class="date" datetime={frontmatter.pubDate}>
{formatDateWithoutWeekday(frontmatter.pubDate)}
</time>
</span>
<h3 class="my-4 text-xl md:text-2xl font-bold font-heading">
<a href={entry.url} title={frontmatter.title}>
{frontmatter.title}
</a>
</h3>
<p class="mb-4 text-sm md:text-base leading-loose text-blueGray-500">{frontmatter.description}</p>
<a class="text-base font-semibold text-sourcectl-orange" href={entry.url} title={frontmatter.title}>
<span>Read More</span>
<svg class="inline-block w-4 h-4 ml-1" fill="none" stroke="currentColor" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3" />
</svg>
</a>
</div>
<div class="w-full lg:w-1/2 px-4 mb-8 order-0">
<a href={entry.url} title={frontmatter.title}>
<img class="w-full h-80 object-cover rounded" src={frontmatter.coverImage} alt={frontmatter.title} title={frontmatter.title} />
</a>
</div>
</div>
)
}
<div class="flex flex-wrap -mx-4 mb-20">
<div class={`w-full lg:w-1/2 px-4 ${textPadding} lg:pt-4 ${textOrder}`}>
<span class="inline-block py-1 px-3 uppercase text-xs font-semibold bg-red-50 rounded-full text-red-600">
<time class="date" datetime={frontmatter.pubDate}>
{formatDateWithoutWeekday(frontmatter.pubDate)}
</time>
</span>
<h3 class="my-4 text-xl md:text-2xl font-bold font-heading">
<a href={entry.url} title={frontmatter.title}>
{frontmatter.title}
</a>
</h3>
<p class="mb-4 text-sm md:text-base leading-loose text-blueGray-500">{frontmatter.description}</p>
<a class="text-base font-semibold text-sourcectl-orange" href={entry.url} title={frontmatter.title}>
<span>Read More</span>
<svg class="inline-block w-4 h-4 ml-1" fill="none" stroke="currentColor" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3" />
</svg>
</a>
</div>
<div class={`w-full lg:w-1/2 px-4 mb-8 ${imageOrder}`}>
<a href={entry.url} title={frontmatter.title}>
<img class="w-full h-80 object-cover rounded" src={frontmatter.coverImage} alt={frontmatter.title} title={frontmatter.title} />
</a>
</div>
</div>