Skip to content

Commit

Permalink
Hide outdated content from UI (#15)
Browse files Browse the repository at this point in the history
* Fix badly named variable

* Remove TODO, we have priority which means we don't need featured.

* Remove dead code

* Add isHidden

* Hide outdated courses
  • Loading branch information
mikemaccana authored Aug 20, 2024
1 parent 69e2893 commit bac46e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/pages/developers/courses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,44 @@ export async function getStaticProps({ locale }) {
}

export default function DeveloperCoursesIndex({
// todo: featured,
records,
records: courseRecords,
}: InferGetStaticPropsType<typeof getStaticProps>) {
const { t } = useTranslation("common");

// Sort the course records by their priority
// Eg, 'intro' courses should be listed first before more advanced topics.
records.sort((a, b) => a.priority - b.priority);
const results: DefaultCard[] = records.map((record) => {
return {
type: "blog",
eyebrow: record.lessons.length > 0 && `${record.lessons.length} Lessons`,
// publishedDate?: string;
// heading: record.title,
// headingAs?: ElementType;
body: record.description,
callToAction: {
hierarchy: "link",
size: "md",
label: "Start Course",
endIcon: "arrow-up-right",
iconSize: "sm",
url: record.href,
},
backgroundImage: {
src: record.image || `/opengraph/developers/courses/${record.slug}`,
},
isFeatured: false,
};
});
let filteredCourseRecords = courseRecords
// Remove any courses with the isHidden flag
// Note: we don't remove the routing to them as there's currently a CFP to
// update these courses, and we want people working on these updates to
// browse their content if they know the URL.
.filter((courseRecord) => {
return !courseRecord.isHidden;
})
// Sort the course records by their priority
// Eg, 'intro' courses should be listed first before more advanced topics.
.sort((a, b) => a.priority - b.priority);

const courseCards: Array<DefaultCard> = filteredCourseRecords.map(
(record) => {
return {
type: "blog",
eyebrow:
record.lessons.length > 0 && `${record.lessons.length} Lessons`,
body: record.description,
callToAction: {
hierarchy: "link",
size: "md",
label: "Start Course",
endIcon: "arrow-up-right",
iconSize: "sm",
url: record.href,
},
backgroundImage: {
src: record.image || `/opengraph/developers/courses/${record.slug}`,
},
isFeatured: false,
};
},
);

return (
<DevelopersLayout>
Expand All @@ -73,7 +81,7 @@ export default function DeveloperCoursesIndex({
description={t("developers.guides.seo-description")}
/>

<CardDeck numCols={3} cards={results} isListing />
<CardDeck numCols={3} cards={courseCards} isListing />

<div className={classNames(styles["developers-content-page"])}>
{/* @ts-expect-error */}
Expand Down
4 changes: 4 additions & 0 deletions src/types/content-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export type ContentRecordBase = ContentApiNavItem & {
// Priority
priority?: number | undefined;

// Only hides from UI, as there's a CFP to update it and people
// that know the URL should still be able to access it.
isHidden?: boolean | undefined;

/** The next record */
next?: ContentApiNavItem;
/** The previous record */
Expand Down

0 comments on commit bac46e0

Please sign in to comment.