Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions apps/trustlab/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5084,6 +5084,14 @@ export interface Organisation {
)[]
| null;
slug: string;
meta?: {
title?: string | null;
description?: string | null;
/**
* Maximum upload file size: 12MB. Recommended file size for images is <500KB.
*/
image?: (string | null) | Media;
};
updatedAt: string;
createdAt: string;
}
Expand Down Expand Up @@ -9446,6 +9454,13 @@ export interface OrganisationsSelect<T extends boolean = true> {
};
};
slug?: T;
meta?:
| T
| {
title?: T;
description?: T;
image?: T;
};
updatedAt?: T;
createdAt?: T;
}
Expand Down
23 changes: 21 additions & 2 deletions apps/trustlab/src/lib/data/common/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,31 @@ async function getOpportunitiesEntries(api) {
return docsToSitemapEntries(docs, "opportunities");
}

async function getOrganisationsEntries(api) {
const { docs } = await api.getCollection("organisations", {
pagination: false,
select: {
pathname: true,
slug: true,
updatedAt: true,
createdAt: true,
link: true,
includeLink: true,
},
});
const docsWithAPage = docs.filter(
(doc) => doc?.includeLink && doc.link?.linkType === "internal",
);
return docsToSitemapEntries(docsWithAPage, "organisations");
}

async function getSitemapEntries(api) {
const [pages, opportunities] = await Promise.all([
const [pages, opportunities, organisations] = await Promise.all([
getPagesEntries(api),
getOpportunitiesEntries(api),
getOrganisationsEntries(api),
]);
return [...pages, ...opportunities];
return [...pages, ...opportunities, ...organisations];
}

async function buildSitemapXml(api) {
Expand Down
4 changes: 3 additions & 1 deletion apps/trustlab/src/lib/data/pagify/opportunities.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function pagifyOpportunities(collection) {

const doc = docs[0];
const date = formatDate(doc.date);
// opportunities have titles but organisations have name only.
const title = doc.title || doc.name || null;
const contentBlocks = doc.blocks || [];
// blockify is called after pagefy so *MUST* not call it here
const blocks = contentBlocks.filter(Boolean).map((block) => {
Expand All @@ -37,7 +39,7 @@ function pagifyOpportunities(collection) {
}
return block;
});
return { ...doc, blocks, date, parent: parentPage };
return { ...doc, blocks, date, title, parent: parentPage };
};
}

Expand Down
4 changes: 4 additions & 0 deletions apps/trustlab/src/payload/collections/Organisations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { slug, image, richText, linkGroup } from "@commons-ui/payload/fields";
import { appendPathnameToCollection } from "@commons-ui/payload/hooks";

import { anyone, hasEditorAccess } from "@/trustlab/payload/access";
import blocks from "@/trustlab/payload/blocks";
Expand Down Expand Up @@ -66,6 +67,9 @@ const Organisations = {
},
}),
],
hooks: {
afterRead: [appendPathnameToCollection("organisations")],
},
};

export default Organisations;
22 changes: 19 additions & 3 deletions apps/trustlab/src/payload/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ const s3MaxAttempts = Number(process.env.S3_MAX_ATTEMPTS) || 3;
const s3MaxSockets = Number(process.env.S3_MAX_SOCKETS) || 1000;
const s3ConnectionTimeout = Number(process.env.S3_CONNECTION_TIMEOUT) || 5000;

function generateURL({ doc }) {
if (!(doc?.pathname || doc?.slug)) {
return "";
}
// site.url always has a trailing /
const pathname = (doc.pathname || `${doc.slug}`).replace(/^\//, "");
return `${site.url}${pathname}`;
}

const plugins = [
nestedDocsPlugin({
collections: ["pages", "posts"],
Expand Down Expand Up @@ -64,16 +73,23 @@ const plugins = [
}),
seoPlugin({
// helplines don't have individual pages and we don't resources collection
collections: ["opportunities", "pages", "posts", "reports"],
collections: [
"organisations",
"opportunities",
"pages",
"posts",
"reports",
],
generateDescription: ({ doc }) => {
const data = doc?.description || doc?.excerpt;
if (data) {
return convertLexicalToPlaintext({ data });
}
return "";
},
generateTitle: ({ doc }) => doc?.title ?? "",
generateURL: ({ doc }) => (doc?.slug ? `${site.url}${doc.slug}` : ""),
// Organisations don't have title, just name
generateTitle: ({ doc }) => doc?.title ?? doc?.name ?? "",
generateURL,
uploadsCollection: "media",
}),
];
Expand Down