From 7b41e4a69ec400628ddff12fb0dc65b2be70df82 Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Tue, 26 Sep 2023 21:44:49 +0200 Subject: [PATCH 1/2] feat(@galactiks/contentlayer): add place content type --- .../src/configs/source-files.config.mts | 7 ++ packages/contentlayer/src/fields.mts | 28 ++++++- packages/contentlayer/src/types.mts | 83 ++++++++++++++++++- 3 files changed, 115 insertions(+), 3 deletions(-) diff --git a/packages/contentlayer/src/configs/source-files.config.mts b/packages/contentlayer/src/configs/source-files.config.mts index b2afe85f..80019ffc 100644 --- a/packages/contentlayer/src/configs/source-files.config.mts +++ b/packages/contentlayer/src/configs/source-files.config.mts @@ -6,6 +6,7 @@ import { ContentLayerOrganizationFields, ContentLayerPageFields, ContentLayerPersonFields, + ContentLayerPlaceFields, } from '../fields.mjs'; export const ArticleDocumentType = defineDocumentType(() => ({ @@ -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', diff --git a/packages/contentlayer/src/fields.mts b/packages/contentlayer/src/fields.mts index 5420453f..52069ac6 100644 --- a/packages/contentlayer/src/fields.mts +++ b/packages/contentlayer/src/fields.mts @@ -10,6 +10,7 @@ export enum pageDocumentTypes { Organization = 'organizations', Page = 'pages', Person = 'people', + Place = 'place', Tag = 'tags', } @@ -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', @@ -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 }, @@ -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: { diff --git a/packages/contentlayer/src/types.mts b/packages/contentlayer/src/types.mts index 69b45d9f..9a6895f6 100644 --- a/packages/contentlayer/src/types.mts +++ b/packages/contentlayer/src/types.mts @@ -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; @@ -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; @@ -196,6 +241,7 @@ export type DocumentTypes = | Organization | Page | Person + | Place | WebPageElement | Website; export type DocumentTypeNames = @@ -203,11 +249,12 @@ export type DocumentTypeNames = | '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[]; @@ -215,6 +262,38 @@ export type DataExports = { 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; +}; From eaadfa246f2ea98934cb80a98d1298b462ad7d44 Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Tue, 26 Sep 2023 21:45:10 +0200 Subject: [PATCH 2/2] feat(@galactiks/explorer): explore places new content type --- .../core/content/repositories/generated.mts | 3 ++- .../src/core/content/types/_schemas.mts | 20 +++++++++++++++++++ .../explorer/src/core/content/types/index.mts | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/explorer/src/core/content/repositories/generated.mts b/packages/explorer/src/core/content/repositories/generated.mts index 99e54b29..1e6b2f6c 100644 --- a/packages/explorer/src/core/content/repositories/generated.mts +++ b/packages/explorer/src/core/content/repositories/generated.mts @@ -56,7 +56,8 @@ const getWebPageDocuments = async (): Promise => { documents: new Array() .concat(generated.allPages) .concat(generated.allArticles) - .concat(generated.allPeople), + .concat(generated.allPeople) + .concat(generated.allPlaces), people: generated.allPeople, }); diff --git a/packages/explorer/src/core/content/types/_schemas.mts b/packages/explorer/src/core/content/types/_schemas.mts index 5f23729e..3b7b7671 100644 --- a/packages/explorer/src/core/content/types/_schemas.mts +++ b/packages/explorer/src/core/content/types/_schemas.mts @@ -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(), @@ -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(), @@ -189,6 +208,7 @@ export const pageSchema = galactiksSchema.merge(webPageSchema); export type MetadataHeaders = z.infer; export type ItemList = z.infer; export type Person = z.infer; +export type Place = z.infer; export type Organization = z.infer; export type Article = z.infer; export type Page = z.infer; diff --git a/packages/explorer/src/core/content/types/index.mts b/packages/explorer/src/core/content/types/index.mts index 69c77bbf..cae8089f 100644 --- a/packages/explorer/src/core/content/types/index.mts +++ b/packages/explorer/src/core/content/types/index.mts @@ -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'; @@ -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'; @@ -25,4 +27,5 @@ export type ContentlayerWebPageDocument = | ContentlayerArticle | ContentlayerPage | ContentlayerPerson + | ContentlayerPlace | ContentlayerTagPage;