Skip to content

Commit

Permalink
Merge pull request #72 from thegalactiks/place-contenttype
Browse files Browse the repository at this point in the history
Place contenttype
  • Loading branch information
emmanuelgautier authored Sep 26, 2023
2 parents 552a004 + eaadfa2 commit 4ee160c
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 4 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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const getWebPageDocuments = async (): Promise<Content[]> => {
documents: new Array<ContentlayerWebPageDocument>()
.concat(generated.allPages)
.concat(generated.allArticles)
.concat(generated.allPeople),
.concat(generated.allPeople)
.concat(generated.allPlaces),
people: generated.allPeople,
});

Expand Down
20 changes: 20 additions & 0 deletions packages/explorer/src/core/content/types/_schemas.mts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ const itemListSchema = thingSchema.extend({
),
});

// Schema: https://schema.org/PostalAddress
export const postalAddressSchema = thingSchema.extend({
addressCountry: z.string(),
addressLocality: z.string().optional(),
addressRegion: z.string().optional(),
postOfficeBoxNumber: z.string().optional(),
postalCode: z.string().optional(),
streetAddress: z.string().optional(),
});

// Schema: https://schema.org/Person
export const personSchema = thingSchema.extend({
additionalName: z.string().optional(),
Expand All @@ -95,6 +105,15 @@ export const personSchema = thingSchema.extend({
telephone: z.string().optional(),
});

// Schema: https://schema.org/Place
export const placeSchema = thingSchema.extend({
address: postalAddressSchema.optional(),
latitude: z.string().or(z.number()).optional(),
longitude: z.string().or(z.number()).optional(),
keywords: z.array(z.string()).optional(),
telephone: z.string().optional(),
});

// Schema: https://schema.org/CreativeWork
const creativeWorkSchema = thingSchema.extend({
url: z.string(),
Expand Down Expand Up @@ -189,6 +208,7 @@ export const pageSchema = galactiksSchema.merge(webPageSchema);
export type MetadataHeaders = z.infer<typeof metadataHeaders>;
export type ItemList = z.infer<typeof itemListSchema>;
export type Person = z.infer<typeof personSchema>;
export type Place = z.infer<typeof placeSchema>;
export type Organization = z.infer<typeof organizationSchema>;
export type Article = z.infer<typeof articlePageSchema>;
export type Page = z.infer<typeof pageSchema>;
3 changes: 3 additions & 0 deletions packages/explorer/src/core/content/types/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Article as ContentlayerArticle,
Page as ContentlayerPage,
Person as ContentlayerPerson,
Place as ContentlayerPlace,
} from '@galactiks/contentlayer';

import type { MetadataHeaders, Page } from './_schemas.mjs';
Expand All @@ -16,6 +17,7 @@ export type {
DocumentTypes as ContentlayerDocumentTypes,
DataExports as ContentlayerDataExports,
Person as ContentlayerPerson,
Place as ContentlayerPlace,
Website as ContentlayerWebsite,
WebPageElement as ContentlayerWebPageElement,
} from '@galactiks/contentlayer';
Expand All @@ -25,4 +27,5 @@ export type ContentlayerWebPageDocument =
| ContentlayerArticle
| ContentlayerPage
| ContentlayerPerson
| ContentlayerPlace
| ContentlayerTagPage;

0 comments on commit 4ee160c

Please sign in to comment.