Skip to content

Commit

Permalink
Refactor readingTime, wordCount, slug, headings, and structuredData r…
Browse files Browse the repository at this point in the history
…esolvers
  • Loading branch information
IgorKowalczyk committed Sep 28, 2024
1 parent b81f7e8 commit a69676a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import remarkGfm from "remark-gfm";
const headersRegex = /(#{1,6})\s+(.+)/g;

const computedFields: ComputedFields = {
readingTime: { type: "json", resolve: (doc: any) => readingTime(doc.body.raw) },
readingTime: { type: "json", resolve: (doc) => readingTime(doc.body.raw) },
wordCount: {
type: "number",
resolve: (doc: any) => doc.body.raw.split(/\s+/gu).length,
resolve: (doc) => doc.body.raw.split(/\s+/gu).length,
},
slug: {
type: "string",
resolve: (doc: any) => doc._raw.sourceFileName.replace(/\.mdx$/, ""),
resolve: (doc) => doc._raw.sourceFileName.replace(/\.mdx$/, ""),
},
};

Expand All @@ -35,7 +35,7 @@ const Blog = defineDocumentType(() => ({
...computedFields,
headings: {
type: "list",
resolve: (doc: any) => {
resolve: (doc) => {
const slugger = new GitHubSlugger();
const headings = Array.from(doc.body.raw.matchAll(headersRegex))
.map((value: RegExpMatchArray) => ({
Expand All @@ -49,7 +49,7 @@ const Blog = defineDocumentType(() => ({
},
structuredData: {
type: "json",
resolve: (doc: any) => ({
resolve: (doc) => ({
"@context": "https://schema.org",
"@type": "BlogPosting",
headline: doc.title,
Expand Down Expand Up @@ -89,7 +89,7 @@ const contentLayerConfig = makeSource({
{
theme: "one-dark-pro",
keepBackground: false,
onVisitLine(node: any) {
onVisitLine(node) {
// Prevent lines from collapsing in `display: grid` mode, and allow empty
// lines to be copy/pasted
if (node.children.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/src/requestGraphql.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable typescript/no-explicit-any */
export async function requestGraphql(query: string, variables: Record<string, any>): Promise<any> {
const response = await fetch("https://api.github.com/graphql", {
method: "POST",
Expand Down
1 change: 1 addition & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const parseISO = (date: string): string => {
})} ${formatted.getUTCDate()}, ${formatted.getFullYear()}`;
};

/* eslint-disable typescript/no-explicit-any */
export function stripTypenames(value: any): any {
if (Array.isArray(value)) {
return value.map(stripTypenames);
Expand Down

0 comments on commit a69676a

Please sign in to comment.