Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: test parallelism changes with gatsby docs
  • Loading branch information
tstelzer committed Jul 7, 2022
commit 71f286c7448f6433eee37e798c934bc5e6e9e045
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"node": true,
"es6": true
},
"ignorePatterns": ["packages/_archive/*", "examples/*", "**/.contentlayer/*", "**/dist/*", "**/.nyc_output/*"],
"ignorePatterns": ["packages/_archive/*", "**/.contentlayer/*", "**/dist/*", "**/.nyc_output/*"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "simple-import-sort", "import"],
"extends": ["plugin:react-hooks/recommended", "plugin:@typescript-eslint/recommended", "prettier"],
Expand Down
4 changes: 4 additions & 0 deletions examples/gatsbydocs/.gitignore
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
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
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
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
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"
}
}
28 changes: 28 additions & 0 deletions examples/gatsbydocs/pages/[...id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Head from 'next/head'
import type { FC } from 'react'

import { allDocuments } from 'contentlayer/generated'
import type { DocumentTypes } from 'contentlayer/generated'

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
22 changes: 22 additions & 0 deletions examples/gatsbydocs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { InferGetStaticPropsType } from 'next'
import type { FC } from 'react'

import { allDocuments } from 'contentlayer/generated'

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
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"
]
}