Skip to content

Commit ea09b42

Browse files
committed
update content filters
1 parent 5a60319 commit ea09b42

9 files changed

Lines changed: 185 additions & 143 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
authors:
3+
- alex-patterson
4+
cloudinary_convert: false
5+
cover: 'https://media.codingcat.dev/image/upload/v1683910220/main-codingcatdev-photo/Firebase-App-Check.png'
6+
devto:
7+
excerpt: Learn how to add Firebase App Check using reCAPTCHA v3, to your next website and block those malicious requests!
8+
hashnode:
9+
published: published
10+
slug: firebase-app-check-web
11+
start: May 12, 2023
12+
title: Firebase App Check
13+
youtube: https://youtu.be/bpTw4aMxCU8
14+
---
15+
16+
## Adding App Check
17+
18+
With just a few lines of code you can include app check into your website
19+
20+
```ts
21+
import { initializeAppCheck, ReCaptchaV3Provider } from 'firebase/app-check';
22+
23+
if (import.meta.env.DEV) {
24+
// @ts-ignore
25+
self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;
26+
}
27+
28+
initializeAppCheck(app, {
29+
provider: new ReCaptchaV3Provider('6LdAIqQlAAAAAC4kq-bag4J-HmAAVe_pu7T75QOf'),
30+
isTokenAutoRefreshEnabled: true
31+
});
32+
```
33+
34+
## Full Repo
35+
36+
You can clone the full repo from [GitHub](https://github.com/CodingCatDev/firebase-app-check).
37+
38+
<section class=" aspect-video">
39+
<iframe
40+
title="stackblitz for firebase app check"
41+
src="https://stackblitz.com/github/CodingCatDev/firebase-app-check?embed=1&file=src/App.svelte"
42+
frameborder="0"
43+
height="100%"
44+
width="100%"
45+
loading="lazy"
46+
/>
47+
</section>

apps/codingcatdev/src/lib/server/content.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ export const filterContent = async <T extends Content>({
126126
preview ?
127127
() => true
128128
:
129-
(c) => c?.start ? new Date(c.start) <= new Date() : false &&
130-
c.published === ContentPublished.published
129+
(c) => c.published === ContentPublished.published &&
130+
c?.start ? new Date(c.start) <= new Date() : false
131+
131132
)
132133
?.sort((a, b) => a?.start && b?.start && new Date(b.start).valueOf() - new Date(a.start).valueOf())
133134
?.map((c: Course) => {
@@ -138,7 +139,7 @@ export const filterContent = async <T extends Content>({
138139
preview ?
139140
() => true
140141
:
141-
(l) => new Date(l.start) <= new Date() && l.published === ContentPublished.published
142+
(l) => l.published === ContentPublished.published && new Date(l.start) <= new Date()
142143
)
143144
.sort((a, b) => a.weight && b.weight ? a.weight - b.weight : -1)
144145
};
@@ -163,8 +164,9 @@ export const listContentByAuthor = async <T extends Content>({ authorSlug, conte
163164
:
164165
(c) =>
165166
c.authors?.filter((g) => g == authorSlug)?.length &&
166-
new Date(c.start) <= new Date() &&
167-
c.published === ContentPublished.published
167+
c.published === ContentPublished.published &&
168+
c?.start ? new Date(c.start) <= new Date() : false
169+
168170
)
169171
return [
170172
...content,
@@ -186,8 +188,8 @@ export const listContentBySponsor = async <T extends Content>({ sponsorSlug, con
186188
:
187189
(c) =>
188190
c.sponsors?.filter((g) => g == sponsorSlug)?.length &&
189-
new Date(c.start) <= new Date() &&
190-
c.published === ContentPublished.published
191+
c.published === ContentPublished.published &&
192+
c?.start ? new Date(c.start) <= new Date() : false
191193
)
192194
return [
193195
...content,
@@ -210,8 +212,8 @@ export const listContentByGuest = async ({ slug, podcastItems }:
210212
:
211213
(c) =>
212214
c.guests?.filter((g) => g == slug)?.length &&
213-
new Date(c.start) <= new Date() &&
214-
c.published === ContentPublished.published
215+
c.published === ContentPublished.published &&
216+
c?.start ? new Date(c.start) <= new Date() : false
215217
)
216218
.sort((a, b) => new Date(b.start).valueOf() - new Date(a.start).valueOf())
217219

apps/codingcatdev/src/routes/(content-single)/(non-course)/+layout.server.ts

Lines changed: 109 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3,148 +3,143 @@ import { filterContent, getContentTypeDirectory, getContentTypePath, listContent
33
import { ContentType, type Content, type Course, type Author, type Podcast, type Sponsor } from '$lib/types';
44

55
export const load = (async (params) => {
6-
try {
7-
const splitPath = params.url.pathname.split('/');
8-
const contentType = splitPath.at(1)
9-
const path = splitPath.at(2)
10-
11-
if (!contentType || !path) throw error(404);
12-
const md = await getContentTypePath<Content & Podcast & Author & Sponsor>(contentType as ContentType, path);
13-
if (!md) throw error(404);
14-
15-
const contentItems = await filterContent({ contentItems: [md] })
16-
const content = contentItems?.at(0);
17-
if (!content) throw error(404);
18-
19-
// Content is good, fetch surrounding items
20-
const authors: Author[] = [];
21-
if (content?.authors) {
22-
for (const authorSlug of content.authors) {
23-
const author = await getContentTypePath<Author>(ContentType.author, authorSlug);
24-
if (author) authors.push(author)
25-
}
6+
const splitPath = params.url.pathname.split('/');
7+
const contentType = splitPath.at(1)
8+
const path = splitPath.at(2)
9+
10+
if (!contentType || !path) throw error(404);
11+
const md = await getContentTypePath<Content & Podcast & Author & Sponsor>(contentType as ContentType, path);
12+
if (!md) throw error(404);
13+
14+
const contentItems = await filterContent({ contentItems: [md] })
15+
const content = contentItems?.at(0);
16+
if (!content) throw error(404);
17+
18+
// Content is good, fetch surrounding items
19+
const authors: Author[] = [];
20+
if (content?.authors) {
21+
for (const authorSlug of content.authors) {
22+
const author = await getContentTypePath<Author>(ContentType.author, authorSlug);
23+
if (author) authors.push(author)
2624
}
27-
const guests: Author[] = [];
28-
if (content?.guests) {
29-
for (const guestSlug of content.guests) {
30-
const guest = await getContentTypePath<Author>(ContentType.guest, guestSlug);
31-
if (guest) guests.push(guest)
32-
}
25+
}
26+
const guests: Author[] = [];
27+
if (content?.guests) {
28+
for (const guestSlug of content.guests) {
29+
const guest = await getContentTypePath<Author>(ContentType.guest, guestSlug);
30+
if (guest) guests.push(guest)
3331
}
32+
}
3433

35-
const sponsors: Sponsor[] = [];
36-
if (content?.sponsors) {
37-
for (const sponsorSlug of content.sponsors) {
38-
const sponsor = await getContentTypePath<Sponsor>(ContentType.sponsor, sponsorSlug);
39-
if (sponsor) sponsors.push(sponsor)
40-
}
34+
const sponsors: Sponsor[] = [];
35+
if (content?.sponsors) {
36+
for (const sponsorSlug of content.sponsors) {
37+
const sponsor = await getContentTypePath<Sponsor>(ContentType.sponsor, sponsorSlug);
38+
if (sponsor) sponsors.push(sponsor)
4139
}
40+
}
4241

43-
// Static last 3 content
44-
const post = (await listContent<Content>({
45-
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
46-
limit: 3
47-
})).content
42+
// Static last 3 content
43+
const post = (await listContent<Content>({
44+
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
45+
limit: 3
46+
})).content
47+
48+
const course = (await listContent<Course>({
49+
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
50+
limit: 3
51+
})).content
52+
53+
54+
const podcast = (await listContent<Content>({
55+
contentItems: await getContentTypeDirectory<Content>(ContentType.podcast),
56+
limit: 3
57+
})).content
58+
59+
const baseContent = {
60+
content, // Main Content
61+
authors, // Possibly Empty
62+
guests, // Possibly Empty
63+
sponsors, // Possibly Empty
64+
course, // Top 3
65+
podcast, // Top 3
66+
post, // Top 3
67+
}
4868

49-
const course = (await listContent<Course>({
69+
if (content.type === ContentType.author) {
70+
const allCourses = (await listContent<Course>({
5071
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
51-
limit: 3
52-
})).content
53-
54-
55-
const podcast = (await listContent<Content>({
56-
contentItems: await getContentTypeDirectory<Content>(ContentType.podcast),
57-
limit: 3
58-
})).content
59-
60-
const baseContent = {
61-
content, // Main Content
62-
authors, // Possibly Empty
63-
guests, // Possibly Empty
64-
sponsors, // Possibly Empty
65-
course, // Top 3
66-
podcast, // Top 3
67-
post, // Top 3
68-
}
72+
limit: 10000,
73+
})).content;
6974

70-
if (content.type === ContentType.author) {
71-
const allCourses = (await listContent<Course>({
72-
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
73-
limit: 10000,
74-
})).content;
75+
const authorCourses = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allCourses })
7576

76-
const authorCourses = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allCourses })
77-
78-
const allPosts = (await listContent<Content>({
79-
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
80-
limit: 10000,
81-
})).content;
77+
const allPosts = (await listContent<Content>({
78+
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
79+
limit: 10000,
80+
})).content;
8281

83-
const authorPosts = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allPosts })
82+
const authorPosts = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allPosts })
8483

8584

86-
return {
87-
...baseContent,
85+
return {
86+
...baseContent,
8887

89-
// Author Specific
90-
authorCourses,
91-
authorPosts
92-
}
88+
// Author Specific
89+
authorCourses,
90+
authorPosts
9391
}
92+
}
9493

95-
if (content.type === ContentType.guest) {
96-
const allPodcasts = (await listContent<Podcast>({
97-
contentItems: await getContentTypeDirectory<Podcast>(ContentType.podcast),
98-
limit: 10000,
99-
})).content;
94+
if (content.type === ContentType.guest) {
95+
const allPodcasts = (await listContent<Podcast>({
96+
contentItems: await getContentTypeDirectory<Podcast>(ContentType.podcast),
97+
limit: 10000,
98+
})).content;
10099

101-
const guestPodcasts = await listContentByGuest({ slug: content.slug, podcastItems: allPodcasts })
100+
const guestPodcasts = await listContentByGuest({ slug: content.slug, podcastItems: allPodcasts })
102101

103-
return {
104-
...baseContent,
102+
return {
103+
...baseContent,
105104

106-
// Guest Specific
107-
guestPodcasts
108-
}
105+
// Guest Specific
106+
guestPodcasts
109107
}
108+
}
110109

111-
if (content.type === ContentType.sponsor) {
112-
const allCourses = (await listContent<Course>({
113-
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
114-
limit: 10000,
115-
})).content;
110+
if (content.type === ContentType.sponsor) {
111+
const allCourses = (await listContent<Course>({
112+
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
113+
limit: 10000,
114+
})).content;
116115

117-
const sponsorCourses = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allCourses })
116+
const sponsorCourses = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allCourses })
118117

119-
const allPosts = (await listContent<Content>({
120-
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
121-
limit: 10000,
122-
})).content;
118+
const allPosts = (await listContent<Content>({
119+
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
120+
limit: 10000,
121+
})).content;
123122

124-
const sponsorPosts = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allPosts })
123+
const sponsorPosts = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allPosts })
125124

126-
const allPodcasts = (await listContent<Podcast>({
127-
contentItems: await getContentTypeDirectory<Podcast>(ContentType.podcast),
128-
limit: 10000,
129-
})).content;
125+
const allPodcasts = (await listContent<Podcast>({
126+
contentItems: await getContentTypeDirectory<Podcast>(ContentType.podcast),
127+
limit: 10000,
128+
})).content;
130129

131-
const sponsorPodcasts = await listContentBySponsor({ sponsorSlug: content.slug, contentItems: allPodcasts })
130+
const sponsorPodcasts = await listContentBySponsor({ sponsorSlug: content.slug, contentItems: allPodcasts })
132131

133132

134-
return {
135-
...baseContent,
133+
return {
134+
...baseContent,
136135

137-
// Sponsor Specific
138-
sponsorCourses,
139-
sponsorPosts,
140-
sponsorPodcasts
141-
}
136+
// Sponsor Specific
137+
sponsorCourses,
138+
sponsorPosts,
139+
sponsorPodcasts
142140
}
143-
144-
return baseContent;
145-
}
146-
catch (e) {
147-
console.error(e)
148-
throw error(404)
149141
}
142+
143+
return baseContent;
144+
150145
})

apps/codingcatdev/src/routes/(content-single)/(non-course)/post/alex-test/+page.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/codingcatdev/src/routes/(content-single)/(non-course)/post/angular-pwa-to-google-play-store-using-trusted-web-activity/+page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ devto: https://dev.to/codingcatdev/angular-pwa-to-google-play-store-using-truste
88
excerpt: Add your PWA to Google Play Store today!
99
hashnode: https://hashnode.codingcat.dev/tutorial-angular-pwa-to-google-play-store-using-trusted-web-activity
1010
preview: https://codingcat.dev/api/preview?secret=7tjQhb1qQlS3FtyV3b0I&selectionType=tutorial&selectionSlug=angular-pwa-to-google-play-store-using-trusted-web-activity&_id=c9c11b5cfd37469791c90454c4d2e472
11-
published: published
11+
published: archived
1212
slug: angular-pwa-to-google-play-store-using-trusted-web-activity
1313
start: May 22, 2022
1414
title: Angular PWA to Google Play store, using Trusted Web Activity

apps/codingcatdev/src/routes/(content-single)/(non-course)/post/npm-tips-and-tricks/+page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ hashnode: https://hashnode.codingcat.dev/tutorial-npm-tips-and-tricks
1010
preview: https://codingcat.dev/api/preview?secret=7tjQhb1qQlS3FtyV3b0I&selectionType=tutorial&selectionSlug=npm-tips-and-tricks&_id=06b5369e5b7846a9ab2d0f4180e8d526
1111
published: published
1212
slug: npm-tips-and-tricks
13-
start: May 17, 2022
13+
start: May 17, 2019
1414
title: NPM Tips and Tricks
1515
youtube: https://youtu.be/eWc0bg9KMQQ
1616
---

0 commit comments

Comments
 (0)