Skip to content

Commit 3a8ca11

Browse files
authored
Merge pull request #354 from contentlayerdev/feat/v0.3.0
0.3.0
2 parents 899684e + 237b1a9 commit 3a8ca11

File tree

55 files changed

+1792
-7314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1792
-7314
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,27 @@ jobs:
5151
- run: yarn build
5252
- run: yarn start
5353
working-directory: examples/node-script
54+
55+
build-example-node-script-mdx:
56+
strategy:
57+
matrix:
58+
node-version: [14, 16, 17, 18]
59+
os: [ubuntu-latest, windows-latest]
60+
runs-on: ${{ matrix.os }}
61+
steps:
62+
- uses: schickling-actions/checkout-and-install@main
63+
- run: yarn build
64+
- run: yarn start
65+
working-directory: examples/node-script-mdx
66+
67+
build-example-node-script-remote-content:
68+
strategy:
69+
matrix:
70+
node-version: [14, 16, 17, 18]
71+
os: [ubuntu-latest, windows-latest]
72+
runs-on: ${{ matrix.os }}
73+
steps:
74+
- uses: schickling-actions/checkout-and-install@main
75+
- run: yarn build
76+
- run: yarn start
77+
working-directory: examples/node-script-remote-content

.vscode/operators.code-snippets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"body": ["function* ($) {}"],
1010
"description": "Generator FUnction with $ input"
1111
},
12+
"Gen Yield * tmp": {
13+
"prefix": "yy",
14+
"body": ["yield* $($0)"],
15+
"description": "Yield generator calling $()"
16+
},
1217
"Gen Yield *": {
1318
"prefix": "!",
1419
"body": ["yield* $($0)"],

.vscode/tasks.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
// for the documentation about the tasks.json format
44
"version": "2.0.0",
55
"tasks": [
6+
{
7+
"label": "yarn-install",
8+
"type": "shell",
9+
"command": "yarn install",
10+
"presentation": {
11+
"focus": true,
12+
"panel": "shared",
13+
"group": "yarn",
14+
"showReuseMessage": true,
15+
"clear": false,
16+
"close": true
17+
}
18+
},
619
{
720
"label": "build:clean",
821
"type": "shell",
@@ -13,7 +26,7 @@
1326
"group": "dev",
1427
"showReuseMessage": true,
1528
"clear": false,
16-
"close": true,
29+
"close": true
1730
}
1831
},
1932
{

examples/next-contentlayer-example

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
2+
import { bundleMDX } from 'mdx-bundler'
3+
import * as ReactDOMServer from 'react-dom/server'
4+
import { getMDXComponent } from 'mdx-bundler/client/index.js'
5+
6+
const mdxToHtml = async (mdxSource: string) => {
7+
const { code } = await bundleMDX({ source: mdxSource })
8+
const MDXLayout = getMDXComponent(code)
9+
// TODO add your own components here
10+
const element = MDXLayout({ components: {} })!
11+
const html = ReactDOMServer.renderToString(element)
12+
return html
13+
}
14+
15+
const Post = defineDocumentType(() => ({
16+
name: 'Post',
17+
filePathPattern: `**/*.mdx`,
18+
contentType: 'mdx',
19+
fields: {
20+
title: {
21+
type: 'string',
22+
description: 'The title of the post',
23+
required: true,
24+
},
25+
date: {
26+
type: 'date',
27+
description: 'The date of the post',
28+
required: true,
29+
},
30+
},
31+
computedFields: {
32+
url: {
33+
type: 'string',
34+
resolve: (doc) => `/posts/${doc._raw.flattenedPath}`,
35+
},
36+
mdxHtml: {
37+
type: 'string',
38+
resolve: async (doc) => mdxToHtml(doc.body.raw),
39+
},
40+
},
41+
}))
42+
43+
export default makeSource({
44+
contentDirPath: 'posts',
45+
documentTypes: [Post],
46+
disableImportAliasWarning: true,
47+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { allPosts } from './.contentlayer/generated/index.mjs'
2+
3+
console.log(allPosts)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "node-script-mdx-example",
3+
"private": true,
4+
"scripts": {
5+
"start": "contentlayer build && node --experimental-json-modules my-script.mjs"
6+
},
7+
"dependencies": {
8+
"contentlayer": "latest"
9+
}
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Change me!
3+
date: 2022-03-11
4+
---
5+
6+
When you change a source file, Contentlayer automatically updates the content cache, which prompts Next.js to reload the content on screen.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Click me!
3+
date: 2022-02-28
4+
---
5+
6+
Blog posts have their own pages. The content source is a markdown file, parsed to HTML by Contentlayer.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: What is Contentlayer?
3+
date: 2022-02-22
4+
---
5+
6+
**Contentlayer makes working with content easy.** It is a content preprocessor that validates and transforms your content into type-safe JSON you can easily import into your application.

0 commit comments

Comments
 (0)