Skip to content

Commit

Permalink
Merge pull request #59 from thegalactiks/create-contentlayer-package
Browse files Browse the repository at this point in the history
feat: create contentlayer package
  • Loading branch information
emmanuelgautier authored Sep 17, 2023
2 parents f356289 + 5a58dfd commit 9252a65
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 97 deletions.
4 changes: 2 additions & 2 deletions packages/adapters/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"galactiks"
],
"dependencies": {
"@galactiks/config": "*",
"@galactiks/explorer": "*"
"@galactiks/config": "workspace:^",
"@galactiks/explorer": "workspace:^"
},
"peerDependencies": {
"@astrojs/partytown": "2.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"galactiks"
],
"dependencies": {
"@galactiks/contentlayer": "workspace:^",
"deepmerge": "4.3.1",
"lodash.set": "4.3.2",
"zod": "3.22.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/config.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pageDocumentTypes } from '@galactiks/contentlayer';
import deepmerge from 'deepmerge';
import { existsSync, readFileSync } from 'fs';
import set from 'lodash.set';
Expand All @@ -8,7 +9,6 @@ import {
type WebManifest,
} from './webmanifest.config.mjs';
import { join } from 'path';
import { pageDocumentTypes } from './consts.mjs';

const localesSchema = z.object({
default: z.string(),
Expand Down
16 changes: 0 additions & 16 deletions packages/config/src/consts.mts

This file was deleted.

1 change: 0 additions & 1 deletion packages/config/src/index.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './config.mjs';
export * from './consts.mjs';
export * from './webmanifest.config.mjs';
Empty file added packages/contentlayer/README.md
Empty file.
40 changes: 40 additions & 0 deletions packages/contentlayer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@galactiks/contentlayer",
"version": "0.0.1",
"description": "Galactiks contentlayer configurations",
"author": "galactiks",
"types": "./dist/index.d.mts",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
},
"bugs": "https://github.com/thegalactiks/explorer/issues",
"repository": {
"type": "git",
"url": "https://github.com/thegalactiks/explorer.git",
"directory": "packages/contentlayer"
},
"main": "dist/index.mjs",
"scripts": {
"build": "tsc -p ./tsconfig.json",
"build:ci": "tsc -p ./tsconfig.json"
},
"exports": {
"./package.json": "./package.json",
".": "./dist/index.mjs",
"./configs": "./dist/configs/index.mjs"
},
"files": [
"dist"
],
"keywords": [
"galactiks",
"contentlayer"
],
"devDependencies": {
"contentlayer": "0.3.4"
},
"peerDependencies": {
"contentlayer": "0.3.4"
}
}
1 change: 1 addition & 0 deletions packages/contentlayer/src/configs/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './source-files.config.mjs';
45 changes: 45 additions & 0 deletions packages/contentlayer/src/configs/source-files.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { defineDocumentType } from 'contentlayer/source-files';
import {
ContentLayerArticleFields,
ContentLayerWebsiteFields,
ContentLayerWebPageElementFields,
ContentLayerOrganizationFields,
ContentLayerPageFields,
ContentLayerPersonFields,
} from '../fields.mjs';

export const ArticleDocumentType = defineDocumentType(() => ({
...ContentLayerArticleFields,
filePathPattern: 'articles/**/*.mdx',
contentType: 'mdx',
}));

export const PageDocumentType = defineDocumentType(() => ({
...ContentLayerPageFields,
filePathPattern: 'pages/**/*.mdx',
contentType: 'mdx',
}));

export const PersonDocumentType = defineDocumentType(() => ({
...ContentLayerPersonFields,
filePathPattern: 'persons/**/*.mdx',
contentType: 'mdx',
}));

export const OrganizationDocumentType = defineDocumentType(() => ({
...ContentLayerOrganizationFields,
filePathPattern: 'organizations/**/*.mdx',
contentType: 'mdx',
}));

export const WebsiteDocumentType = defineDocumentType(() => ({
...ContentLayerWebsiteFields,
filePathPattern: 'websites/*.mdx',
contentType: 'mdx',
}));

export const WebpageElementDocumentType = defineDocumentType(() => ({
...ContentLayerWebPageElementFields,
filePathPattern: 'elements/*.mdx',
contentType: 'mdx',
}));
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ import {
type FieldDefs,
type NestedType,
} from 'contentlayer/source-files';
import { documentTypes } from '@galactiks/config';

export enum pageDocumentTypes {
Article = 'articles',
Organization = 'organizations',
Page = 'pages',
Person = 'people',
Tag = 'tags',
}

export enum documentTypes {
Article = pageDocumentTypes.Article,
Organization = pageDocumentTypes.Organization,
Page = pageDocumentTypes.Page,
Person = pageDocumentTypes.Person,
Tag = pageDocumentTypes.Tag,
WebPageElement = 'webPageElements',
Website = 'websites',
}

type DocumentTypeDef = ContentlayerDocumentTypeDef & {
name: keyof typeof documentTypes;
Expand Down
4 changes: 4 additions & 0 deletions packages/contentlayer/src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './fields.mjs';
export * from './types.mjs';

export type { MDX } from 'contentlayer/core';
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import type {
} from 'contentlayer/core';
import * as Local from 'contentlayer/source-files';

export { isType } from 'contentlayer/client';

export type { Markdown, MDX, ImageFieldData, IsoDateTimeString };

/** Document types */
Expand Down
10 changes: 10 additions & 0 deletions packages/contentlayer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"allowJs": true,
"target": "ES2021",
"module": "ES2022",
"outDir": "./dist"
}
}
11 changes: 3 additions & 8 deletions packages/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"scripts": {
"build": "tsc -p ./tsconfig.json",
"build:ci": "tsc -p ./tsconfig.json",
"contentlayer:build": "contentlayer build"
"build:ci": "tsc -p ./tsconfig.json"
},
"types": "./dist/index.d.mts",
"exports": {
Expand All @@ -28,12 +27,12 @@
"dist"
],
"keywords": [
"contentlayer",
"galactiks"
],
"dependencies": {
"@galactiks/config": "workspace:^",
"@galactiks/contentlayer": "workspace:^",
"@std-uritemplate/std-uritemplate": "0.0.40",
"@galactiks/config": "*",
"esbuild": "0.19.3",
"mdx-bundler": "9.2.1",
"react": "18.2.0",
Expand All @@ -42,10 +41,6 @@
},
"devDependencies": {
"@types/react": "18.2.21",
"contentlayer": "0.3.4",
"schema-dts": "1.1.2"
},
"peerDependencies": {
"contentlayer": "0.3.4"
}
}
2 changes: 1 addition & 1 deletion packages/explorer/src/core/content/render.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MDX } from 'contentlayer/core';
import type { MDX } from '@galactiks/contentlayer';
import { getMDXComponent } from 'mdx-bundler/client/index.js';
import * as React from 'react';
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/explorer/src/core/content/types/_schemas.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { documentTypes } from '@galactiks/config';
import { documentTypes } from '@galactiks/contentlayer';
import { z } from 'zod';

const metadataHeaders = z
Expand Down
8 changes: 4 additions & 4 deletions packages/explorer/src/core/content/types/index.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { MDX } from 'contentlayer/core';

import type {
MDX,
Article as ContentlayerArticle,
Page as ContentlayerPage,
Person as ContentlayerPerson,
} from './contentlayer.mjs';
} from '@galactiks/contentlayer';

import type { MetadataHeaders, Page } from './_schemas.mjs';
import type { Render } from '../render.mjs';

Expand All @@ -18,7 +18,7 @@ export type {
Person as ContentlayerPerson,
Website as ContentlayerWebsite,
WebPageElement as ContentlayerWebPageElement,
} from './contentlayer.mjs';
} from '@galactiks/contentlayer';
export type * from './_schemas.mjs';
type ContentlayerTagPage = Omit<ContentlayerPage, 'type'> & { type: 'Tag' };
export type ContentlayerWebPageDocument =
Expand Down
3 changes: 2 additions & 1 deletion packages/explorer/src/core/content/urls.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StdUriTemplate } from '@std-uritemplate/std-uritemplate';
import { documentTypes, getConfig } from '@galactiks/config';
import { getConfig } from '@galactiks/config';
import { documentTypes } from '@galactiks/contentlayer';
import { join } from 'path';

import type {
Expand Down
1 change: 0 additions & 1 deletion packages/explorer/src/core/index.mts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './content/index.mjs';
export * from './contentlayer.mjs';
Loading

0 comments on commit 9252a65

Please sign in to comment.