-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#16 Упрощение contentlayer.config.ts
- Loading branch information
Showing
1 changed file
with
60 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
import {MDXOptions} from '@contentlayer/core' | ||
import {defineDocumentType, makeSource} from 'contentlayer/source-files' | ||
import rehypePrettyCode from 'rehype-pretty-code' | ||
import remarkMdxImages from 'remark-mdx-images' | ||
|
||
export const SiteConfig = defineDocumentType( | ||
() => ( | ||
{ | ||
name: 'SiteConfig', | ||
filePathPattern: `site.yaml`, | ||
isSingleton: true, | ||
fields: { | ||
title: { | ||
type: 'string', | ||
required: true | ||
}, | ||
description: { | ||
type: 'string', | ||
required: true | ||
} | ||
} | ||
} | ||
) | ||
) | ||
|
||
export const Post = defineDocumentType( | ||
() => ( | ||
{ | ||
|
@@ -24,69 +45,52 @@ export const Post = defineDocumentType( | |
) | ||
) | ||
|
||
export const SiteConfig = defineDocumentType( | ||
() => ( | ||
{ | ||
name: 'SiteConfig', | ||
filePathPattern: `site.yaml`, | ||
isSingleton: true, | ||
fields: { | ||
title: { | ||
type: 'string', | ||
required: true | ||
}, | ||
description: { | ||
type: 'string', | ||
required: true | ||
/** | ||
* @link https://www.contentlayer.dev/docs/sources/files/mdx | ||
*/ | ||
const mdx: MDXOptions = { | ||
rehypePlugins: [ | ||
[ | ||
// https://rehype-pretty-code.netlify.app/ | ||
// https://github.com/atomiks/rehype-pretty-code | ||
rehypePrettyCode, | ||
{ | ||
keepBackground: false, | ||
theme: { | ||
// https://unpkg.com/browse/[email protected]/themes/ | ||
dark: 'github-dark', | ||
light: 'github-light' | ||
} | ||
} | ||
] | ||
], | ||
remarkPlugins: [ | ||
remarkMdxImages | ||
], | ||
|
||
/** | ||
* Встраивание изображений в contentlayer не реализовано. Обсуждение см. на странице https://github.com/contentlayerdev/contentlayer/issues/11 | ||
* Сейчас изображения встраиваются в страницу (опция dataurl). Но можно сохранять и в файл (опция file). | ||
* @link https://github.com/kentcdodds/mdx-bundler#image-bundling | ||
* @param options | ||
* @returns {any} | ||
*/ | ||
esbuildOptions: options => { | ||
// Set the `outdir` to a public location for this bundle. | ||
// options.outdir = '/users/you/site/public/img/about' // Не ясно относительно чего указывать путь. | ||
options.loader = { | ||
...options.loader, | ||
'.jpg': 'dataurl' | ||
} | ||
) | ||
) | ||
return options | ||
} | ||
} | ||
|
||
// https://www.contentlayer.dev/docs/reference/source-files/make-source | ||
export default makeSource( | ||
{ | ||
mdx, | ||
contentDirPath: 'data2', | ||
documentTypes: [Post, SiteConfig], | ||
|
||
// https://www.contentlayer.dev/docs/sources/files/mdx | ||
mdx: { | ||
rehypePlugins: [ | ||
[ | ||
// https://rehype-pretty-code.netlify.app/ | ||
// https://github.com/atomiks/rehype-pretty-code | ||
rehypePrettyCode, | ||
{ | ||
keepBackground: false, | ||
theme: { | ||
// https://unpkg.com/browse/[email protected]/themes/ | ||
dark: 'github-dark', | ||
light: 'github-light' | ||
} | ||
} | ||
] | ||
], | ||
remarkPlugins: [ | ||
remarkMdxImages | ||
], | ||
|
||
/** | ||
* Встраивание изображений в contentlayer не реализовано. Обсуждение см. на странице https://github.com/contentlayerdev/contentlayer/issues/11 | ||
* Сейчас изображения встраиваются в страницу (опция dataurl). Но можно сохранять и в файл (опция file). | ||
* @link https://github.com/kentcdodds/mdx-bundler#image-bundling | ||
* @param options | ||
* @returns {any} | ||
*/ | ||
esbuildOptions: options => { | ||
// Set the `outdir` to a public location for this bundle. | ||
// options.outdir = '/users/you/site/public/img/about' // Не ясно относительно чего указывать путь. | ||
options.loader = { | ||
...options.loader, | ||
'.jpg': 'dataurl' | ||
} | ||
return options | ||
} | ||
} | ||
documentTypes: [Post, SiteConfig] | ||
} | ||
) |