-
Notifications
You must be signed in to change notification settings - Fork 194
Feature/parallel fetch data #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tstelzer
wants to merge
13
commits into
contentlayerdev:main
from
tstelzer:feature/parallel-fetch-data
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
494ffc1
feat(@contentlayer): begin threaded building of source files
tstelzer 71f286c
docs: test parallelism changes with gatsby docs
tstelzer aa764e9
docs: add TODO
tstelzer a0bff26
feat(@contentlayer): serialize DocumentTypeMapState
tstelzer 266d267
build: add eslint prettier plugin
tstelzer d814ae1
feat(@contentlayer): make documentTypeMap explicit in makeCacheItemFr...
tstelzer a53243e
feat: compute makeCacheItemFromFilePath via worker pool
tstelzer 6d8d3a2
feat: de-serializing errors
tstelzer d8784a6
fix: node worker (supposedly) OOM
tstelzer b4dcb70
style: improve
tstelzer fcb0103
feat: replace dummy with live tracing in worker
tstelzer fbd13b3
build: unserialized plugin throwing
tstelzer 5c827a3
docs: update
tstelzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
.editorconfig
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
|
|
||
| [*.{js,jsx,ts,tsx,json,mjs}] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| trim_trailing_whitespace = true | ||
| indent_size = 2 |
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
examples/gatsbydocs/.gitignore
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| content | ||
| .next | ||
| .contentlayer | ||
| node_modules |
80 changes: 80 additions & 0 deletions
examples/gatsbydocs/contentlayer.config.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import rehypeShiki from '@stefanprobst/rehype-shiki' | ||
| import type { FieldDef } from 'contentlayer/source-files' | ||
| import { defineDocumentType, defineNestedType, makeSource } from 'contentlayer/source-files' | ||
| import { createRequire } from 'module' | ||
| import * as path from 'path' | ||
| import * as shiki from 'shiki' | ||
|
|
||
| const Example = defineNestedType(() => ({ | ||
| name: 'Example', | ||
| fields: { | ||
| label: { type: 'string' }, | ||
| href: { type: 'string' }, | ||
| }, | ||
| })) | ||
|
|
||
| const fields: Record<string, FieldDef> = { | ||
| title: { | ||
| type: 'string', | ||
| required: true, | ||
| }, | ||
| jsdoc: { | ||
| type: 'list', | ||
| of: { type: 'string' }, | ||
| }, | ||
| tableOfContentsDepth: { type: 'number' }, | ||
| showTopLevelSignatures: { type: 'boolean' }, | ||
| date: { type: 'string' }, | ||
| version: { type: 'string' }, | ||
| canonicalLink: { type: 'string' }, | ||
| apiCalls: { type: 'string' }, | ||
| contentsHeading: { type: 'string' }, | ||
| description: { type: 'string' }, | ||
| examples: { | ||
| type: 'list', | ||
| of: Example, | ||
| }, | ||
| } | ||
|
|
||
| const Reference = defineDocumentType(() => ({ | ||
| name: 'Reference', | ||
| filePathPattern: 'docs/reference/**/*.md', | ||
| fields, | ||
| })) | ||
|
|
||
| const HowTo = defineDocumentType(() => ({ | ||
| name: 'HowTo', | ||
| filePathPattern: 'docs/how-to/**/*.md', | ||
| fields, | ||
| })) | ||
|
|
||
| const Conceptual = defineDocumentType(() => ({ | ||
| name: 'Conceptual', | ||
| filePathPattern: 'docs/conceptual/**/*.md', | ||
| fields, | ||
| })) | ||
|
|
||
| const Tutorial = defineDocumentType(() => ({ | ||
| name: 'Tutorial', | ||
| filePathPattern: 'tutorial/**/*.md', | ||
| fields, | ||
| })) | ||
|
|
||
| export default makeSource(async () => { | ||
| // const require = createRequire(import.meta.url) | ||
| // const shikiPkgPath = (dir: string) => path.join(require.resolve('shiki'), '..', '..', dir, path.sep) | ||
| // const highlighter = await shiki.getHighlighter({ | ||
| // paths: { languages: shikiPkgPath('languages'), themes: shikiPkgPath('themes') }, | ||
| // theme: 'github-light', | ||
| // }) | ||
|
|
||
| return { | ||
| contentDirPath: 'content', | ||
| documentTypes: [Reference, HowTo, Conceptual, Tutorial], | ||
| // onUnknownDocuments: 'skip-ignore', | ||
| // markdown: { | ||
| // // '@stefanprobst/rehype-shiki', {} | ||
| // rehypePlugins: [[rehypeShiki, { highlighter }]], | ||
| // }, | ||
| } | ||
| }) |
5 changes: 5 additions & 0 deletions
examples/gatsbydocs/next-env.d.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/basic-features/typescript for more information. |
4 changes: 4 additions & 0 deletions
examples/gatsbydocs/next.config.js
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| const { withContentlayer } = require('next-contentlayer') | ||
|
|
||
| // module.exports = {} | ||
| module.exports = withContentlayer({}) |
25 changes: 25 additions & 0 deletions
examples/gatsbydocs/package.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "examples-gatsby-docs", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start" | ||
| }, | ||
| "dependencies": { | ||
| "next": "12.1.6", | ||
| "react": "18.1.0", | ||
| "react-dom": "18.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@leafac/rehype-shiki": "^1.3.1", | ||
| "@stefanprobst/rehype-shiki": "^2.0.4", | ||
| "@types/react": "18.0.9", | ||
| "@types/react-dom": "^17.0.9", | ||
| "contentlayer": "workspace:*", | ||
| "eslint-config-next": "^11.0.1", | ||
| "next-contentlayer": "workspace:*", | ||
| "shiki": "^0.9.4", | ||
| "typescript": "4.6.4" | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
examples/gatsbydocs/pages/[...id].tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { DocumentTypes } from 'contentlayer/generated' | ||
| import { allDocuments } from 'contentlayer/generated' | ||
| import Head from 'next/head' | ||
| import type { FC } from 'react' | ||
|
|
||
| export const getStaticPaths = () => { | ||
| const paths = allDocuments.map((_) => `/${_._raw.flattenedPath}`) | ||
|
|
||
| return { paths, fallback: false } | ||
| } | ||
|
|
||
| export const getStaticProps = (context: any) => { | ||
| const doc = allDocuments.find((_) => _._raw.flattenedPath === context.params.id.join('/')) | ||
|
|
||
| return { props: { doc } } | ||
| } | ||
|
|
||
| const Page: FC<{ doc: DocumentTypes }> = ({ doc }) => ( | ||
| <> | ||
| <Head> | ||
| <title>{doc.title}</title> | ||
| </Head> | ||
| <div dangerouslySetInnerHTML={{ __html: doc.body.html }} /> | ||
| </> | ||
| ) | ||
|
|
||
| export default Page |
21 changes: 21 additions & 0 deletions
examples/gatsbydocs/pages/index.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { allDocuments } from 'contentlayer/generated' | ||
| import type { InferGetStaticPropsType } from 'next' | ||
| import type { FC } from 'react' | ||
|
|
||
| export const getStaticProps = () => { | ||
| const docs = allDocuments.map((_) => ({ path: _._raw.flattenedPath, title: _.title })) | ||
|
|
||
| return { props: { docs } } | ||
| } | ||
|
|
||
| const Page: FC<InferGetStaticPropsType<typeof getStaticProps>> = ({ docs }) => ( | ||
| <div> | ||
| {docs.map((doc) => ( | ||
| <a style={{ display: 'block' }} key={doc.path} href={`/${doc.path}`}> | ||
| {doc.title} | ||
| </a> | ||
| ))} | ||
| </div> | ||
| ) | ||
|
|
||
| export default Page |
41 changes: 41 additions & 0 deletions
examples/gatsbydocs/tsconfig.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "jsx": "preserve", | ||
| "allowSyntheticDefaultImports": true, | ||
| "rootDir": ".", | ||
| "allowJs": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "esModuleInterop": true, | ||
| "resolveJsonModule": true, | ||
| "incremental": false, | ||
| "composite": false, | ||
| "noEmit": true, | ||
| "target": "es5", | ||
| "lib": [ | ||
| "dom", | ||
| "dom.iterable", | ||
| "esnext" | ||
| ], | ||
| "strict": false, | ||
| "module": "esnext", | ||
| "moduleResolution": "node", | ||
| "isolatedModules": true, | ||
| "baseUrl": ".", | ||
| "paths": { | ||
| "contentlayer/generated": [ | ||
| "./.contentlayer/generated" | ||
| ] | ||
| } | ||
| }, | ||
| "include": [ | ||
| "next-env.d.ts", | ||
| "**/*.tsx", | ||
| "**/*.ts", | ||
| ".contentlayer/generated" | ||
| ], | ||
| "exclude": [ | ||
| "node_modules", | ||
| "gatsby" | ||
| ] | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.