chore: add tags to collections

This commit is contained in:
Corbin Crutchley
2023-08-18 02:15:23 -07:00
parent d88d9a4af9
commit 4c6a4825ea
10 changed files with 58 additions and 16 deletions

View File

@@ -4,7 +4,7 @@
description: "Learn the beginnings of data pack development in Minecraft - using positions, entity selectors, and conditional logic in commands!",
published: '2022-06-15T21:12:03.284Z',
authors: ['fennifith'],
tags: [],
tags: ["minecraft"],
attached: [],
license: 'cc-by-nc-sa-4',
collection: "minecraft-data-packs",

View File

@@ -4,7 +4,7 @@
description: "Learn the beginnings of data pack development in Minecraft - using commands and functions to add custom behavior from scratch!",
published: '2022-06-14T21:12:03.284Z',
authors: ['fennifith'],
tags: [],
tags: ["minecraft"],
attached: [],
license: 'cc-by-nc-sa-4',
collection: "minecraft-data-packs",

View File

@@ -4,7 +4,7 @@
description: "Learn data pack development in Minecraft - using player scoreboards, variables, and operations!",
published: '2022-08-20T19:10:03.284Z',
authors: ['fennifith'],
tags: [],
tags: ["minecraft"],
attached: [],
license: 'cc-by-nc-sa-4',
collection: "minecraft-data-packs",

View File

@@ -4,6 +4,7 @@
associatedSeries: "Minecraft Data Pack Programming",
description: "Learn to build unique game behavior in Minecraft - using functions, entity selectors, NBT data, and more!",
authors: ["fennifith"],
tags: ["minecraft"],
coverImg: "./cover.png",
published: "2022-06-14T20:54:00.284Z",
buttons: [{ text: "Read now", url: "/posts/minecraft-data-packs-introduction" }, {text: "Download ePub", url: "/minecraft-data-packs.epub"} ],

View File

@@ -4,6 +4,7 @@
associatedSeries: "Web Components 101",
description: "Learn the history of web components, alongside how to use them with both Lit and Vanilla JavaScript.",
authors: ["crutchcorn"],
tags: ["webdev", "lit"],
coverImg: "./cover.png",
published: "2022-03-14T13:45:00.284Z",
buttons: [{ text: "Read now", url: "/posts/web-components-101-history" }],

View File

@@ -107,6 +107,10 @@
"displayName": "Lit",
"image": "/stickers/lit.svg"
},
"minecraft": {
"displayName": "Minecraft",
"emoji": "🟩"
},
"mongodb": {
"displayName": "MongoDB",
"image": "/stickers/mongodb.svg"

View File

@@ -9,6 +9,7 @@ export interface RawCollectionInfo {
coverImg: string;
socialImg?: string;
type?: "book";
tags: string[];
published: string;
buttons: Array<{ text: string; url: string }>;
chapterList?: Array<{

View File

@@ -221,19 +221,19 @@ function getPosts(): Array<PostInfo> {
const posts = getPosts();
const tags = [
...posts.reduce((set, post) => {
for (const tag of post.tags || []) set.add(tag);
return set;
}, new Set<string>()),
];
collections = collections.map((collection: Omit<CollectionInfo, "posts">) => ({
...collection,
posts: posts.filter((post) => post.collection === collection.slug),
})) as CollectionInfo[];
const tags = [
...[...posts, ...collections].reduce((set, item) => {
for (const tag of item.tags || []) set.add(tag);
return set;
}, new Set<string>()),
];
export {
aboutRaw as about,
fullUnicorns as unicorns,

View File

@@ -54,6 +54,13 @@ export const FilterDisplay = ({
tagToPostNumMap.set(tag, numPosts + 1);
});
});
collections.forEach((collection) => {
collection.tags.forEach((tag) => {
tags.add(tag);
});
});
return Array.from(tags)
.sort((a, b) => a.localeCompare(b))
.map((tag) => ({

View File

@@ -253,6 +253,34 @@ function SearchPageBase({ unicornProfilePicMap }: SearchPageProps) {
});
}, [data, page, sort, selectedUnicorns, selectedTags]);
const filteredAndSortedCollections = useMemo(() => {
return [...data.collections]
.sort(
(a, b) =>
(sort === "newest" ? -1 : 1) *
(new Date(a.published).getTime() - new Date(b.published).getTime()),
)
.filter((collection) => {
if (
selectedTags.length > 0 &&
!collection.tags.some((tag) => selectedTags.includes(tag))
) {
return false;
}
if (
selectedUnicorns.length > 0 &&
!collection.authors.some((unicorn) =>
selectedUnicorns.includes(unicorn),
)
) {
return false;
}
return true;
});
}, [data, page, sort, selectedUnicorns, selectedTags]);
/**
* Paginate posts
*/
@@ -289,11 +317,11 @@ function SearchPageBase({ unicornProfilePicMap }: SearchPageProps) {
enabled &&
!isContentLoading &&
((posts.length === 0 && showArticles && !showCollections) ||
(data.collections.length === 0 && showCollections && !showArticles) ||
(filteredAndSortedCollections.length === 0 && showCollections && !showArticles) ||
(showCollections &&
showArticles &&
posts.length === 0 &&
data.collections.length === 0));
filteredAndSortedCollections.length === 0));
return (
<div className={style.fullPageContainer} role="search">
@@ -377,7 +405,7 @@ function SearchPageBase({ unicornProfilePicMap }: SearchPageProps) {
{enabled &&
!isContentLoading &&
showCollections &&
Boolean(data.collections.length) && (
Boolean(filteredAndSortedCollections.length) && (
<Fragment>
<SubHeader
tag="h1"
@@ -390,7 +418,7 @@ function SearchPageBase({ unicornProfilePicMap }: SearchPageProps) {
role="list"
className={style.collectionsGrid}
>
{data.collections.map((collection) => (
{filteredAndSortedCollections.map((collection) => (
<li>
<CollectionCard
unicornProfilePicMap={unicornProfilePicMap}
@@ -404,7 +432,7 @@ function SearchPageBase({ unicornProfilePicMap }: SearchPageProps) {
{enabled &&
!isContentLoading &&
showArticles &&
Boolean(data.posts.length) && (
Boolean(posts.length) && (
<Fragment>
<SubHeader
tag="h1"