Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/style: landing page #7

Merged
merged 12 commits into from
Sep 5, 2024
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

# production
/build
/public/categories.json
/public/types-data.json
/public/tag-data.json

# misc
.DS_Store
Expand Down
81 changes: 76 additions & 5 deletions contentlayer.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {
defineDocumentType,
defineNestedType,
makeSource,
} from "contentlayer2/source-files";
import { createSlug } from "./src/utils";
import { defineDocumentType, defineNestedType, makeSource } from "contentlayer2/source-files";
import { writeFileSync } from "fs";
import path from "path";
import { Transcript as ContentTranscriptType } from "./.contentlayer/generated/types";

const Resources = defineNestedType(() => ({
name: "Resources",
Expand All @@ -13,6 +12,63 @@ const Resources = defineNestedType(() => ({
},
}));

/**
* Count the occurrences of all tags across transcripts and write to json file
*/
function createTagCount(allTranscripts: ContentTranscriptType[]) {
const tagCount: Record<string, number> = {};
allTranscripts.forEach((file) => {
if (file.tags) {
file.tags.forEach((tag: string) => {
const formattedTag = createSlug(tag);
if (formattedTag in tagCount) {
tagCount[formattedTag] += 1;
} else {
tagCount[formattedTag] = 1;
}
});
}
});
writeFileSync("./public/tag-data.json", JSON.stringify(tagCount));
}

/**
* Count the occurrences of all types across transcripts and write to json file
*/
const createTypesCount = (allTranscripts: ContentTranscriptType[]) => {
const typesAndCount: Record<string, number> = {};
const relevantTypes = [
"video",
"core-dev-tech",
"podcast",
"conference",
"meeting",
"club",
"meetup",
"hackathon",
"workshop",
"residency",
"developer-tools",
];

allTranscripts.forEach((transcript) => {
if (transcript.categories) {
transcript.categories.forEach((type: string) => {
const formattedType = createSlug(type);
if (relevantTypes.includes(formattedType)) {
if (formattedType in typesAndCount) {
typesAndCount[formattedType] += 1;
} else {
typesAndCount[formattedType] = 1;
}
}
});
}
});

writeFileSync("./public/types-data.json", JSON.stringify(typesAndCount));
};

export const Transcript = defineDocumentType(() => ({
name: "Transcript",
filePathPattern: `**/*.md`,
Expand Down Expand Up @@ -55,4 +111,19 @@ export const Transcript = defineDocumentType(() => ({
export default makeSource({
contentDirPath: path.join(process.cwd(), "public", "bitcoin-transcript"),
documentTypes: [Transcript],
contentDirExclude: [
".github",
".gitignore",
"LICENSE.md",
"README.md",
"STYLE.md",
"twitter_handles.json",
".json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I forgot the contentDirExclude when I did the refactoring.

Does ".json" means that it's excluding all the JSON files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't, this and other things in the contentDirExclude array just excludes files at the root directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it excludes all JSON files in the root directory? If that's the case then you don't need to separate specify "twitter_handles.json"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me tag this comment to the pr in prod

"2018-08-17-richard-bondi-bitcoin-cli-regtest.es.md",
],
onSuccess: async (importData) => {
const { allDocuments } = await importData();
createTagCount(allDocuments);
createTypesCount(allDocuments);
},
});
Loading