Skip to content

Commit

Permalink
feat(@galactiks/contentlayer): add place content type
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Sep 26, 2023
1 parent 552a004 commit 7b41e4a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/contentlayer/src/configs/source-files.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ContentLayerOrganizationFields,
ContentLayerPageFields,
ContentLayerPersonFields,
ContentLayerPlaceFields,
} from '../fields.mjs';

export const ArticleDocumentType = defineDocumentType(() => ({
Expand All @@ -26,6 +27,12 @@ export const PersonDocumentType = defineDocumentType(() => ({
contentType: 'mdx',
}));

export const PlaceDocumentType = defineDocumentType(() => ({
...ContentLayerPlaceFields,
filePathPattern: 'places/**/*.mdx',
contentType: 'mdx',
}));

export const OrganizationDocumentType = defineDocumentType(() => ({
...ContentLayerOrganizationFields,
filePathPattern: 'organizations/**/*.mdx',
Expand Down
28 changes: 27 additions & 1 deletion packages/contentlayer/src/fields.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum pageDocumentTypes {
Organization = 'organizations',
Page = 'pages',
Person = 'people',
Place = 'place',
Tag = 'tags',
}

Expand All @@ -18,6 +19,7 @@ export enum documentTypes {
Organization = pageDocumentTypes.Organization,
Page = pageDocumentTypes.Page,
Person = pageDocumentTypes.Person,
Place = pageDocumentTypes.Place,
Tag = pageDocumentTypes.Tag,
WebPageElement = 'webPageElements',
Website = 'websites',
Expand Down Expand Up @@ -127,7 +129,6 @@ export const ContentLayerPersonFields: DocumentTypeDef = {
...galactiksFields,
...creativeWorkFields,
dateCreated: { type: 'date', required: false },

additionalName: { type: 'string', required: false },
email: { type: 'string', required: false },
familyName: { type: 'string', required: false },
Expand All @@ -137,6 +138,31 @@ export const ContentLayerPersonFields: DocumentTypeDef = {
},
};

const postalAddress = defineNestedType(() => ({
name: 'PostalAddress',
fields: {
addressCountry: { type: 'string', required: true },
addressLocality: { type: 'string', required: false },
addressRegion: { type: 'string', required: false },
postOfficeBoxNumber: { type: 'string', required: false },
postalCode: { type: 'string', required: false },
streetAddress: { type: 'string', required: false },
},
}));

export const ContentLayerPlaceFields: DocumentTypeDef = {
name: 'Place',
fields: {
...galactiksFields,
...creativeWorkFields,
address: { type: 'nested', of: postalAddress },
latitude: { type: 'string', required: false },
longitude: { type: 'string', required: false },
keywords: { type: 'list', required: false, of: { type: 'string' } },
telephone: { type: 'string', required: false },
},
};

export const ContentLayerOrganizationFields: DocumentTypeDef = {
name: 'Organization',
fields: {
Expand Down
83 changes: 81 additions & 2 deletions packages/contentlayer/src/types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@ export type Person = {
body: MDX;
};

export type Place = {
/** File path relative to `contentDirPath` */
_id: string;
_raw: Local.RawDocumentData;
type: 'Place';
listingPage: boolean;
slug?: string | undefined;
path?: string | undefined;
name: string;
description: string;
url?: string | undefined;
identifier: string;
image?: any | undefined;
sameAs?: string | undefined;
author?: string | undefined;
headline?: string | undefined;
dateCreated: IsoDateTimeString;
dateModified?: IsoDateTimeString | undefined;
datePublished?: IsoDateTimeString | undefined;
isPartOf?: string | undefined;
inLanguage?: string | undefined;
translationOfWork?: Id | undefined;
workTranslation?: Id | undefined;
keywords?: string[] | undefined;
address?: PostalAddress | undefined;
latitude?: string | undefined;
longitude?: string | undefined;
telephone?: string | undefined;
/** MDX file body */
body: MDX;
};

export type WebPageElement = {
/** File path relative to `contentDirPath` */
_id: string;
Expand Down Expand Up @@ -186,6 +218,19 @@ export type ItemListElement = {
itemListElement?: ItemListElement[] | undefined;
};

export type PostalAddress = {
/** File path relative to `contentDirPath` */
_id: string;
_raw: Local.RawDocumentData;
type: 'PostalAddress';
addressCountry: string;
addressLocality?: string | undefined;
addressRegion?: string | undefined;
postOfficeBoxNumber?: string | undefined;
postalCode?: string | undefined;
streetAddress?: string | undefined;
};

/** Helper types */

export type AllTypes = DocumentTypes | NestedTypes;
Expand All @@ -196,25 +241,59 @@ export type DocumentTypes =
| Organization
| Page
| Person
| Place
| WebPageElement
| Website;
export type DocumentTypeNames =
| 'Article'
| 'Organization'
| 'Page'
| 'Person'
| 'Place'
| 'WebPageElement'
| 'Website';

export type NestedTypes = never;
export type NestedTypeNames = never;
export type NestedTypes = Id | ItemListElement | PostalAddress;
export type NestedTypeNames = 'Id' | 'ItemListElement' | 'PostalAddress';

export type DataExports = {
allDocuments: DocumentTypes[];
allArticles: Article[];
allOrganizations: Organization[];
allPages: Page[];
allPeople: Person[];
allPlaces: Place[];
allWebsites: Website[];
allWebPageElements: WebPageElement[];
};

export interface ContentlayerGenTypes {
documentTypes: DocumentTypes;
documentTypeMap: DocumentTypeMap;
documentTypeNames: DocumentTypeNames;
nestedTypes: NestedTypes;
nestedTypeMap: NestedTypeMap;
nestedTypeNames: NestedTypeNames;
allTypeNames: AllTypeNames;
dataExports: DataExports;
}

declare global {
interface ContentlayerGen extends ContentlayerGenTypes {}
}

export type DocumentTypeMap = {
Article: Article;
Organization: Organization;
Page: Page;
Person: Person;
Place: Place;
WebPageElement: WebPageElement;
Website: Website;
};

export type NestedTypeMap = {
Id: Id;
ItemListElement: ItemListElement;
PostalAddress: PostalAddress;
};

0 comments on commit 7b41e4a

Please sign in to comment.