Skip to content

Commit

Permalink
Reading all stores instead of only one for collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveed committed Dec 9, 2024
1 parent dcd4516 commit fda3c48
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 25 deletions.
18 changes: 11 additions & 7 deletions src/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Tag from './Tag.astro';
import type { SEO } from '../interfaces/Article';
import { Fragment } from 'react';

export interface Props {
href?: string;
Expand Down Expand Up @@ -61,15 +62,18 @@ export default function Card({ href, frontmatter, tags, secHeading = true }: Pro
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 7l5 5-5 5M6 7l5 5-5 5" />
</svg>
</div>
<ul>
{tags?.map((tag) => {
if (!tag) return null;
return <Tag tag={tag || 'x'} size="sm" />;
})}
</ul>
{/* <ul>
{
tags?.map((tag: string, index: number) => (
<Fragment key={index}>
{tag && <Tag tag={tag} size="sm" />}
</Fragment>
))
}
</ul> */}
</div>
</a>
</article>
</li>
);
}
}
13 changes: 8 additions & 5 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ export type activeNav = "tags" | "about" | "search" | "pages" | "blog";
export interface Props {
activeNav?: activeNav;
store?: Store;
store?: {
data: Store;
};
}
const { activeNav, store } = Astro.props;
console.log({ store, logo: store?.data.Logo });
---

<header>
Expand All @@ -20,14 +23,14 @@ const { activeNav, store } = Astro.props;
<div class="top-nav-wrap">
<a href="/" class="logo brand-magenta whitespace-nowrap">
{
store?.Logo?.formats?.small ? (
store?.data?.Logo?.url ? (
<img
src={`${store.Logo.formats.small.url}`}
alt={store.title}
src={`${store?.data?.Logo.url}`}
alt={store?.data?.title || store?.data?.SEO?.metaTitle}
width={120}
/>
) : (
store?.title
store?.data?.title || store?.data?.SEO?.metaTitle || SITE.title
)
}
</a>
Expand Down
10 changes: 6 additions & 4 deletions src/components/Tag.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
export interface Props {
tag: string;
tag?: string;
size?: "sm" | "lg";
}
const { tag, size = "sm" } = Astro.props;
const { tag = "", size = "sm" } = Astro.props;
---

<li
Expand All @@ -20,9 +20,11 @@ const { tag, size = "sm" } = Astro.props;
<svg
xmlns="http://www.w3.org/2000/svg"
class={`${size === "sm" ? " scale-75" : "scale-110"}`}
><path
>
<path
d="M16.018 3.815 15.232 8h-4.966l.716-3.815-1.964-.37L8.232 8H4v2h3.857l-.751 4H3v2h3.731l-.714 3.805 1.965.369L8.766 16h4.966l-.714 3.805 1.965.369.783-4.174H20v-2h-3.859l.751-4H21V8h-3.733l.716-3.815-1.965-.37zM14.106 14H9.141l.751-4h4.966l-.752 4z"
></path>
>
</path>
</svg>
&nbsp;<span>{tag}</span>
</a>
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export default interface Store {
slug: string;
products: { data: [] };
URLS: { Label: string, URL: string, }[];
SEO: {};
SEO: {
metaTitle: string,
metaDescription: string,
};
Logo: {
id: string,
url: string,
Expand Down
5 changes: 4 additions & 1 deletion src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import HeroImage from "@components/HeroImage.astro";
import { BlocksRenderer } from "@strapi/blocks-react-renderer";
import { getCollection } from "astro:content";
import type Store from "../interfaces/Store";
import { markketplace } from "@config";
const stores = await getCollection("stores");
const store = stores?.[0]?.data as unknown as Store;
const store = stores.find(
(store: Store) => store.data.slug === markketplace.STORE_SLUG
);
export interface Props {
post: CollectionEntry<"posts">;
Expand Down
12 changes: 9 additions & 3 deletions src/layouts/Posts.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import Pagination from "@components/Pagination.astro";
import Card from "@components/Card";
import { SITE } from "@config";
import type Page from "@interfaces/Page";
import { BlocksRenderer } from "@strapi/blocks-react-renderer";
import {
BlocksRenderer,
type BlocksContent,
} from "@strapi/blocks-react-renderer";
import HeroImage from "@components/HeroImage.astro";
import Hr from "@components/Hr.astro";
import { markketplace } from "@config";
export interface Props {
currentPage: number;
Expand All @@ -23,7 +27,9 @@ import type Store from "../interfaces/Store";
import { slugifyStr } from "@utils/slugify";
const stores = await getCollection("stores");
const store = stores?.[0]?.data as unknown as Store;
const store = stores.find(
(store: Store) => store.data.slug === markketplace.STORE_SLUG
);
const { currentPage, totalPages, paginatedPosts } = Astro.props;
Expand Down Expand Up @@ -73,7 +79,7 @@ const blogPage: { data: Page } | undefined = pages.find(
tags={data.Tags.map((tag: { Label: string }) => tag.Label)}
frontmatter={{
author: "x",
title: data.Title || "---",
title: data.Title || data.SEO?.metaTitle || "",
pubDatetime: new Date(data.createdAt),
modDatetime: new Date(data.updatedAt),
description: data.SEO?.metaDescription || "",
Expand Down
5 changes: 4 additions & 1 deletion src/pages/404.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import Footer from "@components/Footer.astro";
import LinkButton from "@components/LinkButton.astro";
import { getCollection } from "astro:content";
import type Store from "../interfaces/Store";
import { markketplace } from "@config";
const stores = await getCollection("stores");
const store = stores?.[0]?.data as unknown as Store;
const store = stores.find(
(store: Store) => store.data.slug === markketplace.STORE_SLUG
);
---

<Layout title={`404 Not Found | ${SITE.title}`}>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Header, { type activeNav } from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import Breadcrumbs from "@components/Breadcrumbs.astro";
import Hr from "@components/Hr.astro";
import { markketplace } from "@config";
export interface Props {
page: CollectionEntry<"pages">;
Expand All @@ -26,7 +27,9 @@ export async function getStaticPaths() {
}
const stores = await getCollection("stores");
const store = stores?.[0]?.data as unknown as Store;
const store = stores.find(
(store: Store) => store.data.slug === markketplace.STORE_SLUG
);
const { page } = Astro.props;
---
Expand Down
5 changes: 4 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import {
type BlocksContent,
} from "@strapi/blocks-react-renderer";
import { slugifyStr } from "@utils/slugify";
import { markketplace } from "@config";
const stores = await getCollection("stores");
const store = stores?.[0]?.data as unknown as Store;
const store = stores.find(
(store: Store) => store.data.slug === markketplace.STORE_SLUG
);
const posts = await getCollection("posts");
Expand Down
5 changes: 4 additions & 1 deletion src/pages/pages.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { SITE } from "@config";
import Footer from "@components/Footer.astro";
import Header from "@components/Header.astro";
import type Store from "@interfaces/Store";
import { markketplace } from "@config";
const stores = await getCollection("stores");
const store = stores?.[0]?.data as Store;
const store = stores.find(
(store: Store) => store.data.slug === markketplace.STORE_SLUG
);
let pages = await getCollection("pages");
pages = pages.sort(
Expand Down

0 comments on commit fda3c48

Please sign in to comment.