Skip to content

Commit

Permalink
Merge branch 'main' into fix/integration-konfidency
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgr authored Jan 21, 2025
2 parents f09604a + a93b388 commit 8aec057
Show file tree
Hide file tree
Showing 28 changed files with 2,157 additions and 134 deletions.
96 changes: 96 additions & 0 deletions blog/loaders/BlogRelatedPosts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @title BlogRelatedPosts
* @description Retrieves a list of blog related posts.
*
* @param props - The props for the blog related post list.
* @param req - The request object.
* @param ctx - The application context.
* @returns A promise that resolves to an array of blog related posts.
*/
import { RequestURLParam } from "../../website/functions/requestToParam.ts";
import { AppContext } from "../mod.ts";
import { BlogPost, SortBy } from "../types.ts";
import handlePosts, { slicePosts } from "../utils/handlePosts.ts";
import { getRecordsByPath } from "../utils/records.ts";

const COLLECTION_PATH = "collections/blog/posts";
const ACCESSOR = "post";

export interface Props {
/**
* @title Items per page
* @description Number of posts per page to display.
*/
count?: number;
/**
* @title Page query parameter
* @description The current page number. Defaults to 1.
*/
page?: number;
/**
* @title Category Slug
* @description Filter by a specific category slug.
*/
slug?: RequestURLParam | string[];
/**
* @title Page sorting parameter
* @description The sorting option. Default is "date_desc"
*/
sortBy?: SortBy;
/**
* @description Overrides the query term at url
*/
query?: string;
/**
* @title Exclude Post Slug
* @description Excludes a post slug from the list
*/
excludePostSlug?: RequestURLParam | string;
}

/**
* @title BlogRelatedPosts
* @description Retrieves a list of blog related posts.
*
* @param props - The props for the blog related post list.
* @param req - The request object.
* @param ctx - The application context.
* @returns A promise that resolves to an array of blog related posts.
*/

export type BlogRelatedPosts = BlogPost[] | null;

export default async function BlogRelatedPosts(
{ page, count, slug, sortBy, query, excludePostSlug }: Props,
req: Request,
ctx: AppContext,
): Promise<BlogRelatedPosts> {
const url = new URL(req.url);
const postsPerPage = Number(count ?? url.searchParams.get("count") ?? 12);
const pageNumber = Number(page ?? url.searchParams.get("page") ?? 1);
const pageSort = sortBy ?? (url.searchParams.get("sortBy") as SortBy) ??
"date_desc";
const term = query ?? url.searchParams.get("q") ?? undefined;

const posts = await getRecordsByPath<BlogPost>(
ctx,
COLLECTION_PATH,
ACCESSOR,
);

const handledPosts = handlePosts(
posts,
pageSort,
slug,
term,
excludePostSlug,
);

if (!handledPosts) {
return null;
}

const slicedPosts = slicePosts(handledPosts, pageNumber, postsPerPage);

return slicedPosts.length > 0 ? slicedPosts : null;
}
2 changes: 1 addition & 1 deletion blog/loaders/BlogpostList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default async function BlogPostList(
ctx: AppContext,
): Promise<BlogPost[] | null> {
const url = new URL(req.url);
const postsPerPage = Number(count ?? url.searchParams.get("count"));
const postsPerPage = Number(count ?? url.searchParams.get("count") ?? 12);
const pageNumber = Number(page ?? url.searchParams.get("page") ?? 1);
const pageSort = sortBy ?? url.searchParams.get("sortBy") as SortBy ??
"date_desc";
Expand Down
2 changes: 2 additions & 0 deletions blog/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as $$$5 from "./loaders/BlogpostListing.ts";
import * as $$$2 from "./loaders/BlogPostPage.ts";
import * as $$$6 from "./loaders/Category.ts";
import * as $$$7 from "./loaders/GetCategories.ts";
import * as $$$8 from "./loaders/BlogRelatedPosts.ts";
import * as $$$$$$0 from "./sections/Seo/SeoBlogPost.tsx";
import * as $$$$$$1 from "./sections/Seo/SeoBlogPostListing.tsx";
import * as $$$$$$2 from "./sections/Template.tsx";
Expand All @@ -24,6 +25,7 @@ const manifest = {
"blog/loaders/BlogPostPage.ts": $$$2,
"blog/loaders/Category.ts": $$$6,
"blog/loaders/GetCategories.ts": $$$7,
"blog/loaders/BlogRelatedPosts.ts": $$$8,
},
"sections": {
"blog/sections/Seo/SeoBlogPost.tsx": $$$$$$0,
Expand Down
2 changes: 2 additions & 0 deletions blog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export interface BlogPost {
* @title Extra Props
*/
extraProps?: ExtraProps[];
/** @hide true */
id?: string;
}

export interface ExtraProps {
Expand Down
32 changes: 27 additions & 5 deletions blog/utils/handlePosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ export const filterPostsByTerm = (posts: BlogPost[], term: string) =>
)
);

/**
* Returns an filtered BlogPost list
*
* @param posts Posts to be handled
* @param slug Category Slug to be filter
*/
export const filterRelatedPosts = (
posts: BlogPost[],
slug: string[],
) =>
posts.filter(
({ categories }) => categories.find((c) => slug.includes(c.slug)),
);

/**
* Returns an filtered and sorted BlogPost list
*
Expand All @@ -77,11 +91,15 @@ export const slicePosts = (

export const filterPosts = (
posts: BlogPost[],
slug?: string,
slug?: string | string[],
term?: string,
): BlogPost[] => {
if (term) return filterPostsByTerm(posts, term);
if (slug) return filterPostsByCategory(posts, slug);
if (typeof slug === "string") return filterPostsByCategory(posts, slug);
if (Array.isArray(slug)) {
return filterRelatedPosts(posts, slug);
}

return posts;
};

Expand All @@ -90,16 +108,20 @@ export const filterPosts = (
*
* @param posts Posts to be handled
* @param sortBy Sort option (must be: "date_desc" | "date_asc" | "title_asc" | "title_desc" )
* @param slug Category slug to be filter
* @param slug Category slug or an array of slugs to be filtered
* @param term Term to be filter
* @param excludePostSlug Post slug to be excluded
*/
export default function handlePosts(
posts: BlogPost[],
sortBy: SortBy,
slug?: string,
slug?: string | string[],
term?: string,
excludePostSlug?: string,
) {
const filteredPosts = filterPosts(posts, slug, term);
const filteredPosts = filterPosts(posts, slug, term).filter(
({ slug: postSlug }) => postSlug !== excludePostSlug,
);

if (!filteredPosts || filteredPosts.length === 0) {
return null;
Expand Down
8 changes: 7 additions & 1 deletion blog/utils/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ export async function getRecordsByPath<T>(
const current = Object.entries(resolvables).flatMap(([key, value]) => {
return key.startsWith(path) ? value : [];
});
return (current as Record<string, T>[]).map((item) => item[accessor]);
return (current as Record<string, T>[]).map((item) => {
const id = (item.name as string).split(path)[1]?.replace("/", "");
return {
...item[accessor],
id,
};
});
}
1 change: 1 addition & 0 deletions deco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const compatibilityApps = [{

const config = {
apps: [
app("google-sheets"),
app("posthog"),
app("decopilot-app"),
app("smarthint"),
Expand Down
1 change: 1 addition & 0 deletions decohub/apps/google-sheets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, preview } from "../../google-sheets/mod.ts";
94 changes: 48 additions & 46 deletions decohub/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ import * as $$$$$$$$$$$4 from "./apps/blog.ts";
import * as $$$$$$$$$$$5 from "./apps/brand-assistant.ts";
import * as $$$$$$$$$$$6 from "./apps/crux.ts";
import * as $$$$$$$$$$$7 from "./apps/emailjs.ts";
import * as $$$$$$$$$$$8 from "./apps/htmx.ts";
import * as $$$$$$$$$$$9 from "./apps/implementation.ts";
import * as $$$$$$$$$$$10 from "./apps/konfidency.ts";
import * as $$$$$$$$$$$11 from "./apps/linx-impulse.ts";
import * as $$$$$$$$$$$12 from "./apps/linx.ts";
import * as $$$$$$$$$$$13 from "./apps/mailchimp.ts";
import * as $$$$$$$$$$$14 from "./apps/nuvemshop.ts";
import * as $$$$$$$$$$$15 from "./apps/posthog.ts";
import * as $$$$$$$$$$$16 from "./apps/power-reviews.ts";
import * as $$$$$$$$$$$17 from "./apps/ra-trustvox.ts";
import * as $$$$$$$$$$$18 from "./apps/resend.ts";
import * as $$$$$$$$$$$19 from "./apps/shopify.ts";
import * as $$$$$$$$$$$20 from "./apps/smarthint.ts";
import * as $$$$$$$$$$$21 from "./apps/sourei.ts";
import * as $$$$$$$$$$$22 from "./apps/streamshop.ts";
import * as $$$$$$$$$$$23 from "./apps/typesense.ts";
import * as $$$$$$$$$$$24 from "./apps/verified-reviews.ts";
import * as $$$$$$$$$$$25 from "./apps/vnda.ts";
import * as $$$$$$$$$$$26 from "./apps/vtex.ts";
import * as $$$$$$$$$$$27 from "./apps/wake.ts";
import * as $$$$$$$$$$$28 from "./apps/wap.ts";
import * as $$$$$$$$$$$29 from "./apps/weather.ts";
import * as $$$$$$$$$$$30 from "./apps/workflows.ts";
import * as $$$$$$$$$$$8 from "./apps/google-sheets.ts";
import * as $$$$$$$$$$$9 from "./apps/htmx.ts";
import * as $$$$$$$$$$$10 from "./apps/implementation.ts";
import * as $$$$$$$$$$$11 from "./apps/konfidency.ts";
import * as $$$$$$$$$$$12 from "./apps/linx-impulse.ts";
import * as $$$$$$$$$$$13 from "./apps/linx.ts";
import * as $$$$$$$$$$$14 from "./apps/mailchimp.ts";
import * as $$$$$$$$$$$15 from "./apps/nuvemshop.ts";
import * as $$$$$$$$$$$16 from "./apps/posthog.ts";
import * as $$$$$$$$$$$17 from "./apps/power-reviews.ts";
import * as $$$$$$$$$$$18 from "./apps/ra-trustvox.ts";
import * as $$$$$$$$$$$19 from "./apps/resend.ts";
import * as $$$$$$$$$$$20 from "./apps/shopify.ts";
import * as $$$$$$$$$$$21 from "./apps/smarthint.ts";
import * as $$$$$$$$$$$22 from "./apps/sourei.ts";
import * as $$$$$$$$$$$23 from "./apps/streamshop.ts";
import * as $$$$$$$$$$$24 from "./apps/typesense.ts";
import * as $$$$$$$$$$$25 from "./apps/verified-reviews.ts";
import * as $$$$$$$$$$$26 from "./apps/vnda.ts";
import * as $$$$$$$$$$$27 from "./apps/vtex.ts";
import * as $$$$$$$$$$$28 from "./apps/wake.ts";
import * as $$$$$$$$$$$29 from "./apps/wap.ts";
import * as $$$$$$$$$$$30 from "./apps/weather.ts";
import * as $$$$$$$$$$$31 from "./apps/workflows.ts";

const manifest = {
"apps": {
Expand All @@ -44,29 +45,30 @@ const manifest = {
"decohub/apps/brand-assistant.ts": $$$$$$$$$$$5,
"decohub/apps/crux.ts": $$$$$$$$$$$6,
"decohub/apps/emailjs.ts": $$$$$$$$$$$7,
"decohub/apps/htmx.ts": $$$$$$$$$$$8,
"decohub/apps/implementation.ts": $$$$$$$$$$$9,
"decohub/apps/konfidency.ts": $$$$$$$$$$$10,
"decohub/apps/linx-impulse.ts": $$$$$$$$$$$11,
"decohub/apps/linx.ts": $$$$$$$$$$$12,
"decohub/apps/mailchimp.ts": $$$$$$$$$$$13,
"decohub/apps/nuvemshop.ts": $$$$$$$$$$$14,
"decohub/apps/posthog.ts": $$$$$$$$$$$15,
"decohub/apps/power-reviews.ts": $$$$$$$$$$$16,
"decohub/apps/ra-trustvox.ts": $$$$$$$$$$$17,
"decohub/apps/resend.ts": $$$$$$$$$$$18,
"decohub/apps/shopify.ts": $$$$$$$$$$$19,
"decohub/apps/smarthint.ts": $$$$$$$$$$$20,
"decohub/apps/sourei.ts": $$$$$$$$$$$21,
"decohub/apps/streamshop.ts": $$$$$$$$$$$22,
"decohub/apps/typesense.ts": $$$$$$$$$$$23,
"decohub/apps/verified-reviews.ts": $$$$$$$$$$$24,
"decohub/apps/vnda.ts": $$$$$$$$$$$25,
"decohub/apps/vtex.ts": $$$$$$$$$$$26,
"decohub/apps/wake.ts": $$$$$$$$$$$27,
"decohub/apps/wap.ts": $$$$$$$$$$$28,
"decohub/apps/weather.ts": $$$$$$$$$$$29,
"decohub/apps/workflows.ts": $$$$$$$$$$$30,
"decohub/apps/google-sheets.ts": $$$$$$$$$$$8,
"decohub/apps/htmx.ts": $$$$$$$$$$$9,
"decohub/apps/implementation.ts": $$$$$$$$$$$10,
"decohub/apps/konfidency.ts": $$$$$$$$$$$11,
"decohub/apps/linx-impulse.ts": $$$$$$$$$$$12,
"decohub/apps/linx.ts": $$$$$$$$$$$13,
"decohub/apps/mailchimp.ts": $$$$$$$$$$$14,
"decohub/apps/nuvemshop.ts": $$$$$$$$$$$15,
"decohub/apps/posthog.ts": $$$$$$$$$$$16,
"decohub/apps/power-reviews.ts": $$$$$$$$$$$17,
"decohub/apps/ra-trustvox.ts": $$$$$$$$$$$18,
"decohub/apps/resend.ts": $$$$$$$$$$$19,
"decohub/apps/shopify.ts": $$$$$$$$$$$20,
"decohub/apps/smarthint.ts": $$$$$$$$$$$21,
"decohub/apps/sourei.ts": $$$$$$$$$$$22,
"decohub/apps/streamshop.ts": $$$$$$$$$$$23,
"decohub/apps/typesense.ts": $$$$$$$$$$$24,
"decohub/apps/verified-reviews.ts": $$$$$$$$$$$25,
"decohub/apps/vnda.ts": $$$$$$$$$$$26,
"decohub/apps/vtex.ts": $$$$$$$$$$$27,
"decohub/apps/wake.ts": $$$$$$$$$$$28,
"decohub/apps/wap.ts": $$$$$$$$$$$29,
"decohub/apps/weather.ts": $$$$$$$$$$$30,
"decohub/apps/workflows.ts": $$$$$$$$$$$31,
},
"name": "decohub",
"baseUrl": import.meta.url,
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"version": "0.64.10"
"version": "0.64.18"
}
5 changes: 5 additions & 0 deletions google-sheets/loaders/doc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AppContext } from "../mod.ts";

export default function doc(_: null, __: Request, ctx: AppContext) {
return ctx.doc;
}
Binary file added google-sheets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions google-sheets/manifest.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// DO NOT EDIT. This file is generated by deco.
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import * as $$$0 from "./loaders/doc.ts";

const manifest = {
"loaders": {
"google-sheets/loaders/doc.ts": $$$0,
},
"name": "google-sheets",
"baseUrl": import.meta.url,
};

export type Manifest = typeof manifest;

export default manifest;
Loading

0 comments on commit 8aec057

Please sign in to comment.