Skip to content

Commit 3b30065

Browse files
author
Daveed
committed
Configuring markket in the content layer
1 parent 3dbd146 commit 3b30065

File tree

10 files changed

+999
-594
lines changed

10 files changed

+999
-594
lines changed

.github/workflows/test_pr.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ permissions:
1515

1616
env:
1717
BUILD_PATH: "." # default value when not using subfolders
18+
PUBLIC_URL : ${{ secrets.PUBLIC_URL }}
1819

1920
jobs:
2021
test:
@@ -40,7 +41,7 @@ jobs:
4041
echo "PUBLIC_MARKKET_URL=${{ secrets.PUBLIC_MARKKET_URL }}" >> .env
4142
echo "PUBLIC_STORE_SLUG=${{ secrets.PUBLIC_STORE_SLUG }}" >> .env
4243
echo "PUBLIC_POSTHOG_KEY=${{ secrets.PUBLIC_POSTHOG_KEY }}" >> .env
43-
echo "PUBLIC_URL=https://sell.markket.place" >> .env
44+
echo "PUBLIC_URL=${{secrets.PUBLIC_URL}}" >> .env
4445
working-directory: ${{ env.BUILD_PATH }}
4546

4647
- name: Test Build with Astro

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist/
88
package-lock.json
99
.astro/
1010
*.local
11+
*.backup

astro.config.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { defineConfig } from 'astro/config';
33
// https://astro.build/config
44
import react from "@astrojs/react";
55

6+
const PUBLIC_URL = process.env.PUBLIC_URL || 'https://express.markket.place';
7+
68
// https://astro.build/config
79
export default defineConfig({
810
integrations: [react()],
9-
site: 'https://creativetimofficial.github.io',
10-
base: '/astro-ecommerce'
11-
});
11+
site: PUBLIC_URL,
12+
base: '/'
13+
});

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"@types/react": "^18.0.21",
1616
"@types/react-dom": "^18.0.6",
1717
"astro": "^5.5.5",
18+
"cafecito": "^0.12.2",
1819
"forward-ref": "^1.0.0",
1920
"json-server": "^0.17.0",
21+
"marked": "^16.3.0",
2022
"react": "^18.2.0",
2123
"react-bootstrap": "^2.6.0",
2224
"react-dom": "^18.2.0"

public/data.json

Lines changed: 222 additions & 194 deletions
Large diffs are not rendered by default.

src/content/config.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { defineCollection } from "astro:content";
2+
3+
import {
4+
fetchStrapiContent,
5+
fetchStrapiSchema,
6+
type StrapiQueryOptions,
7+
type StrapiConfig
8+
} from 'cafecito';
9+
10+
const config: StrapiConfig = {
11+
store_slug: import.meta.env.PUBLIC_STORE_SLUG || 'express',
12+
api_url: import.meta.env.PUBLIC_MARKKET_URL || 'https://api.markket.place',
13+
sync_interval: 6000,
14+
};
15+
16+
// @TODO: Find a better type to avoid excessively deep and possibly infinite errors
17+
type Loader = any;
18+
19+
20+
/**
21+
* Creates a Strapi content loader for Astro
22+
* @param contentType The Strapi content type to load
23+
* @param filter The filter to apply to the content &filters[store][id][$eq]=${STRAPI_STORE_ID}
24+
* @returns An Astro loader for the specified content type
25+
*/
26+
function strapiLoader(query: StrapiQueryOptions) {
27+
return {
28+
name: `strapi-${query.contentType}`,
29+
schema: async () => await fetchStrapiSchema(query.contentType, config.api_url),
30+
31+
async load({ store, logger, meta }) {
32+
const lastSynced = meta.get("lastSynced");
33+
if (lastSynced && Date.now() - Number(lastSynced) < config.sync_interval) {
34+
logger.info("Skipping sync");
35+
return;
36+
}
37+
38+
const posts = await fetchStrapiContent(query, config);
39+
40+
store.clear();
41+
posts.forEach((item: any) => store.set({ id: item.id, data: item }));
42+
meta.set("lastSynced", String(Date.now()));
43+
},
44+
};
45+
};
46+
47+
const pages = defineCollection({
48+
loader: strapiLoader({
49+
contentType: "page",
50+
sort: 'slug:DESC',
51+
filter: `filters[store][slug][$eq]=${config.store_slug}`,
52+
populate: 'SEO.socialImage,albums,albums.tracks,albums.cover'
53+
}) as Loader,
54+
});
55+
56+
57+
const store = defineCollection({
58+
loader: strapiLoader({
59+
contentType: "store",
60+
filter: `filters[slug][$eq]=${config.store_slug}`,
61+
populate: 'SEO.socialImage,Logo,URLS,Favicon,Cover'
62+
}) as Loader,
63+
});
64+
65+
const stores = defineCollection({
66+
loader: strapiLoader({
67+
contentType: "store",
68+
filter: `filters[active]=true`,
69+
populate: 'SEO.socialImage,Logo,URLS,Favicon'
70+
}) as Loader,
71+
});
72+
73+
const products = defineCollection({
74+
loader: strapiLoader({
75+
contentType: "product",
76+
filter: `filters[stores][slug][$eq]=${config.store_slug}`,
77+
sort: 'slug:DESC',
78+
populate: 'SEO,SEO.socialImage,Thumbnail,Slides,PRICES'
79+
}) as Loader,
80+
});
81+
82+
const posts = defineCollection({
83+
loader: strapiLoader({
84+
contentType: "article",
85+
filter: `filters[store][slug][$eq]=${config.store_slug}`,
86+
populate: 'SEO.socialImage,Tags,store,cover',
87+
sort: 'createdAt:DESC',
88+
paginate: {
89+
limit: 100,
90+
}
91+
}) as Loader,
92+
});
93+
94+
const events = defineCollection({
95+
loader: strapiLoader({
96+
contentType: "event",
97+
filter: `filters[stores][slug][$eq]=${config.store_slug}`,
98+
populate: 'SEO,SEO.socialImage,Tag,Thumbnail,Slides,stores'
99+
}) as Loader,
100+
});
101+
102+
export const collections = { posts, pages, stores, products, events, store };

src/layouts/Layout.astro

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,92 @@
11
---
22
export interface Props {
3-
title: string;
3+
title: string;
4+
canonical?: string;
5+
description?: string;
6+
keywords?: string;
7+
author?: string;
8+
ogImage?: string;
9+
favicon?: string;
410
}
511
6-
const { title } = Astro.props;
12+
const { title, canonical, description, keywords, author, ogImage, favicon } =
13+
Astro.props;
714
---
815

9-
<!DOCTYPE html>
16+
<!doctype html>
1017
<html lang="en">
11-
<head>
12-
<meta charset="UTF-8" />
13-
<meta name="viewport" content="width=device-width" />
14-
<link rel="icon" type="image/svg+xml" href={`${import.meta.env.BASE_URL}favicon.svg`} />
18+
<head>
19+
<meta charset="UTF-8" />
20+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
21+
22+
<!-- SEO Meta Tags -->
23+
<title>{title}</title>
24+
{description && <meta name="description" content={description} />}
25+
{keywords && <meta name="keywords" content={keywords} />}
26+
{author && <meta name="author" content={author} />}
27+
<meta name="generator" content={Astro.generator} />
28+
29+
<!-- Canonical URL -->
30+
{canonical && <link rel="canonical" href={canonical} />}
31+
32+
<!-- Open Graph Meta Tags -->
33+
<meta property="og:title" content={title} />
34+
{description && <meta property="og:description" content={description} />}
35+
<meta property="og:type" content="website" />
36+
{canonical && <meta property="og:url" content={canonical} />}
37+
{ogImage && <meta property="og:image" content={ogImage} />}
38+
39+
<!-- Twitter Card Meta Tags -->
40+
<meta name="twitter:card" content="summary_large_image" />
41+
<meta name="twitter:title" content={title} />
42+
{description && <meta name="twitter:description" content={description} />}
43+
{ogImage && <meta name="twitter:image" content={ogImage} />}
44+
45+
<!-- Favicon -->
46+
<link
47+
rel="icon"
48+
type="image/png"
49+
href={favicon || `${import.meta.env.BASE_URL}favicon.svg`}
50+
/>
51+
52+
<!-- Fonts -->
1553
<link
1654
href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Noto+Sans:300,400,500,600,700,800|PT+Mono:300,400,500,600,700"
1755
rel="stylesheet"
1856
/>
19-
<meta name="generator" content={Astro.generator} />
20-
<title>{title}</title>
21-
<link rel="canonical" href="https://www.creative-tim.com/astro/" />
22-
<!-- Google Tag Manager -->
23-
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
24-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
25-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
26-
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
27-
})(window,document,'script','dataLayer','GTM-NKDMSK6');</script>
28-
<!-- End Google Tag Manager -->
29-
30-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
31-
32-
</head>
33-
<body>
34-
<!-- Google Tag Manager (noscript) -->
35-
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NKDMSK6"
36-
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
37-
<!-- End Google Tag Manager (noscript) -->
38-
<slot />
39-
</body>
57+
58+
<!-- Bootstrap Icons -->
59+
<link
60+
rel="stylesheet"
61+
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"
62+
/>
63+
</head>
64+
<body>
65+
<slot />
66+
</body>
4067

4168
<!-- Bootstrap JavaScript Bundle with Popper -->
42-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
69+
<script
70+
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
71+
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
72+
crossorigin="anonymous"
73+
>
74+
</script>
4375
<!-- Product JavaScript -->
4476
<script>
45-
import "/assets/js/astro-ecommerce.js"
77+
import "/assets/js/astro-ecommerce.js";
4678
</script>
4779
</html>
4880
<style is:global>
49-
code {
50-
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
51-
Bitstream Vera Sans Mono, Courier New, monospace;
52-
}
81+
code {
82+
font-family:
83+
Menlo,
84+
Monaco,
85+
Lucida Console,
86+
Liberation Mono,
87+
DejaVu Sans Mono,
88+
Bitstream Vera Sans Mono,
89+
Courier New,
90+
monospace;
91+
}
5392
</style>

0 commit comments

Comments
 (0)