-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc93367
commit 44bcd00
Showing
17 changed files
with
217 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
/* v8 ignore start */ | ||
// Stryker disable all | ||
|
||
import type { NestedTypeNoiseKeys } from '##/lib/misc/contentlayerCornerCases'; | ||
import type { Author as NestedTypeAuthor } from 'contentlayer/generated'; | ||
|
||
const authors = { | ||
Gustave: { | ||
profilePicUrl: '/assets/medias/img/dev/placeholders/placeholder-54.jpeg', | ||
bio: 'Je suis très chouette' | ||
profilePicUrl: '/assets/medias/img/dev/placeholders/placeholder-54.jpeg' | ||
}, | ||
Arnaud: { | ||
profilePicUrl: '/assets/medias/img/dev/placeholders/placeholder-55.jpeg' | ||
} | ||
} as const satisfies Authors; | ||
} as const satisfies Record<string, Author>; | ||
|
||
export const authorNames = Object.keys(authors) as readonly (keyof typeof authors)[]; | ||
export const authorNames = Object.keys(authors) as readonly AuthorName[]; | ||
|
||
export default authors; | ||
|
||
export type Author = Omit<NestedTypeAuthor, NestedTypeNoiseKeys>; | ||
export type AuthorName = string; | ||
export type Authors = Record<AuthorName, Author>; | ||
export type Author = { | ||
medias?: { | ||
instagram?: undefined | string; | ||
goodreads?: undefined | string; | ||
linkedin?: undefined | string; | ||
twitter?: undefined | string; | ||
keybase?: undefined | string; | ||
reddit?: undefined | string; | ||
medium?: undefined | string; | ||
github?: undefined | string; | ||
}; | ||
profilePicUrl: string; | ||
}; | ||
|
||
export type AuthorName = keyof Authors; | ||
export type Authors = typeof authors; | ||
|
||
// Stryker restore all | ||
/* v8 ignore stop */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* v8 ignore start */ | ||
// Stryker disable all | ||
|
||
import { generateBlogAuthorOptionsVocabSchema, generateIndexedAuthorNames } from '../../../lib/builders/blogAuthorsGenerators'; | ||
import { authorNames } from './authors'; | ||
|
||
export const indexedBlogAuthorNames = generateIndexedAuthorNames(authorNames); | ||
|
||
export const blogAuthorOptionsVocabSchema = generateBlogAuthorOptionsVocabSchema(authorNames); | ||
|
||
// Stryker restore all | ||
/* v8 ignore stop */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
/* v8 ignore start */ | ||
// Stryker disable all | ||
|
||
import { generateBlogTagOptionsVocabSchema, generateIndexedBlogTagOptions } from '../../../lib/builders/blogTagsGenerators'; | ||
import { blogTagOptions } from './blogTags'; | ||
|
||
export const indexedBlogTagOptions = generateIndexedBlogTagOptions(blogTagOptions); | ||
|
||
export const blogTagOptionsVocabSchema = generateBlogTagOptionsVocabSchema(blogTagOptions); | ||
|
||
// Stryker restore all | ||
/* v8 ignore stop */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
interop/lib/builders/blog/computedFields/functions/authors.ts
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
interop/lib/builders/blog/computedFields/functions/authorsIndexes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { DocumentToCompute } from '@rtm/shared-types/ContentlayerConfig'; | ||
import type { MaybeNull } from '@rtm/shared-types/CustomUtilityTypes'; | ||
import type { Index } from 'packages/shared-types/src/Numbers'; | ||
|
||
import { BlogAuthorDuplicates, InvalidBlogAuthor, BULLET } from '../../../unifiedImport'; | ||
|
||
function validateAuthorNames<AuthorName extends string>( | ||
tagsArrayUniq: AuthorName[], | ||
indexedBlogTagOptions: Record<AuthorName, Index>, | ||
blogTagOptions: readonly AuthorName[] | ||
): MaybeNull<InvalidBlogAuthor> { | ||
const defects: string[] = []; | ||
|
||
for (const tag of tagsArrayUniq) { | ||
if (indexedBlogTagOptions[tag] === undefined) { | ||
defects.push(tag); | ||
continue; | ||
} | ||
} | ||
|
||
// eslint-disable-next-line no-magic-numbers | ||
if (defects.length > 0) return new InvalidBlogAuthor(defects, blogTagOptions); | ||
return null; | ||
} | ||
|
||
function validateAuthorsNoDuplicates(authorsNamesArray: string[]): MaybeNull<BlogAuthorDuplicates> { | ||
const authorsMemory: unknown[] = []; | ||
const duplicatesSet = new Set<unknown>(); | ||
|
||
for (const currentName of authorsNamesArray) { | ||
if (authorsMemory.includes(currentName)) { | ||
duplicatesSet.add(currentName); | ||
continue; | ||
} | ||
authorsMemory.push(currentName); | ||
} | ||
|
||
const duplicates = Array.from(duplicatesSet); | ||
// eslint-disable-next-line no-magic-numbers | ||
if (duplicates.length > 0) return new BlogAuthorDuplicates(duplicates); | ||
return null; | ||
} | ||
|
||
/** | ||
* @throws {[InvalidBlogAuthor, BlogAuthorDuplicates]} | ||
*/ | ||
function buildBlogAuthorsFromPostObj<AuthorName extends string>( | ||
authorsNamesArray: AuthorName[], | ||
indexedAuthorsNames: Record<AuthorName, Index>, | ||
authorsNames: readonly AuthorName[] | ||
): Index[] { | ||
const authorsNamesArrayUniq = Array.from(new Set<AuthorName>(authorsNamesArray)); | ||
|
||
const maybeValidateAuthorNamesError = validateAuthorNames(authorsNamesArrayUniq, indexedAuthorsNames, authorsNames); | ||
const maybeValidateAuthorsNoDuplicatesError = validateAuthorsNoDuplicates(authorsNamesArray as string[]); | ||
|
||
const mergedErrors = [maybeValidateAuthorNamesError, maybeValidateAuthorsNoDuplicatesError].filter((e) => e !== null); | ||
|
||
// eslint-disable-next-line no-magic-numbers | ||
if (mergedErrors.length > 0) throw mergedErrors.join('\n' + BULLET + ' '); | ||
|
||
const res: Index[] = []; | ||
for (const authorName of authorsNamesArrayUniq) res.push(indexedAuthorsNames[authorName]); | ||
|
||
return res; | ||
} | ||
|
||
const buildBlogAuthorsIndexes = <AuthorName extends string>( | ||
post: DocumentToCompute, | ||
indexedAuthorsNames: Record<AuthorName, Index>, | ||
authorsNames: readonly AuthorName[] | ||
): Index[] => buildBlogAuthorsFromPostObj(post.authors._array as AuthorName[], indexedAuthorsNames, authorsNames); | ||
|
||
export default buildBlogAuthorsIndexes; |
Oops, something went wrong.