forked from jaredpalmer/tsdx
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b148ce
commit b09e195
Showing
47 changed files
with
10,116 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/ https://tsdx.io 301! | ||
/* https://tsdx.io 301! |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["next/babel"], | ||
"plugins": ["babel-plugin-macros", "./.nextra/babel-plugin-nextjs-mdx-patch"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.next | ||
.DS_Store | ||
yarn-error.log |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default ({ width = 24, height = 24, ...props }) => { | ||
return ( | ||
<svg | ||
width={width} | ||
height={height} | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
{...props} | ||
> | ||
<path | ||
d="M3 12h18m0 0l-6.146-6M21 12l-6.146 6" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Currently it's not possible to export data fetching functions from MDX pages | ||
* because MDX includes them in `layoutProps`, and Next.js removes them at some | ||
* point, causing a `ReferenceError`. | ||
* | ||
* https://github.com/mdx-js/mdx/issues/742#issuecomment-612652071 | ||
* | ||
* This plugin can be removed once MDX removes `layoutProps`, at least that | ||
* seems to be the current plan. | ||
*/ | ||
|
||
// https://nextjs.org/docs/basic-features/data-fetching | ||
const DATA_FETCH_FNS = ['getStaticPaths', 'getStaticProps', 'getServerProps'] | ||
|
||
module.exports = () => { | ||
return { | ||
visitor: { | ||
ObjectProperty(path) { | ||
if ( | ||
DATA_FETCH_FNS.includes(path.node.value.name) && | ||
path.findParent( | ||
(path) => | ||
path.isVariableDeclarator() && | ||
path.node.id.name === 'layoutProps', | ||
) | ||
) { | ||
path.remove() | ||
} | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// https://github.com/vercel/next.js/issues/12053#issuecomment-622939046 |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import userConfig from '../nextra.config'; | ||
|
||
const defaultConfig = { | ||
nextLinks: true, | ||
prevLinks: true, | ||
search: true, | ||
}; | ||
|
||
export default () => { | ||
return { ...defaultConfig, ...userConfig }; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import preval from 'preval.macro' | ||
import title from 'title' | ||
|
||
const excludes = ['/_app.js', '/_document.js', '/_error.js'] | ||
|
||
// watch all meta files | ||
const meta = {} | ||
function importAll(r) { | ||
return r.keys().forEach(key => { | ||
meta[key.slice(1)] = r(key) | ||
}) | ||
} | ||
importAll(require.context('../pages/', true, /meta\.json$/)) | ||
|
||
// use macro to load the file list | ||
const items = preval` | ||
const { readdirSync, readFileSync } = require('fs') | ||
const { resolve, join } = require('path') | ||
const extension = /\.(mdx?|jsx?)$/ | ||
function getFiles(dir, route) { | ||
const files = readdirSync(dir, { withFileTypes: true }) | ||
// go through the directory | ||
const items = files | ||
.map(f => { | ||
const filePath = resolve(dir, f.name) | ||
const fileRoute = join(route, f.name.replace(extension, '').replace(/^index$/, '')) | ||
if (f.isDirectory()) { | ||
const children = getFiles(filePath, fileRoute) | ||
if (!children.length) return null | ||
return { name: f.name, children, route: fileRoute } | ||
} else if (f.name === 'meta.json') { | ||
return null | ||
} else if (extension.test(f.name)) { | ||
return { name: f.name.replace(extension, ''), route: fileRoute } | ||
} | ||
}) | ||
.map(item => { | ||
if (!item) return | ||
return { ...item, metaPath: join(route, 'meta.json') } | ||
}) | ||
.filter(Boolean) | ||
return items | ||
} | ||
module.exports = getFiles(join(process.cwd(), 'pages'), '/') | ||
` | ||
|
||
const attachPageConfig = function (items) { | ||
let folderMeta = null | ||
let fnames = null | ||
|
||
return items | ||
.filter(item => !excludes.includes(item.name)) | ||
.map(item => { | ||
const { metaPath, ...rest } = item | ||
folderMeta = meta[metaPath] | ||
if (folderMeta) { | ||
fnames = Object.keys(folderMeta) | ||
} | ||
|
||
const pageConfig = folderMeta?.[item.name] | ||
|
||
if (rest.children) rest.children = attachPageConfig(rest.children) | ||
|
||
if (pageConfig) { | ||
if (typeof pageConfig === 'string') { | ||
return { ...rest, title: pageConfig } | ||
} | ||
return { ...rest, ...pageConfig } | ||
} else { | ||
if (folderMeta) { | ||
return null | ||
} | ||
return { ...rest, title: title(item.name) } | ||
} | ||
}) | ||
.filter(Boolean) | ||
.sort((a, b) => { | ||
if (folderMeta) { | ||
return fnames.indexOf(a.name) - fnames.indexOf(b.name) | ||
} | ||
// by default, we put directories first | ||
if (!!a.children !== !!b.children) { | ||
return !!a.children ? -1 : 1 | ||
} | ||
// sort by file name | ||
return a.name < b.name ? -1 : 1 | ||
}) | ||
} | ||
|
||
export default () => { | ||
return attachPageConfig(items) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useRef, useEffect } from 'react' | ||
|
||
export default function () { | ||
const input = useRef(null) | ||
|
||
useEffect(() => { | ||
const inputs = ['input', 'select', 'button', 'textarea'] | ||
|
||
const down = (e) => { | ||
if ( | ||
document.activeElement && | ||
inputs.indexOf(document.activeElement.tagName.toLowerCase() !== -1) | ||
) { | ||
if (e.key === '/') { | ||
e.preventDefault() | ||
input.current?.focus() | ||
} | ||
} | ||
} | ||
|
||
window.addEventListener('keydown', down) | ||
return () => window.removeEventListener('keydown', down) | ||
}, []) | ||
|
||
useEffect(() => { | ||
if (window.docsearch) { | ||
window.docsearch({ | ||
apiKey: '247dd86c8ddbbbe6d7a2d4adf4f3a68a', | ||
indexName: 'vercel_swr', | ||
inputSelector: 'input#algolia-doc-search' | ||
}) | ||
} | ||
}, []) | ||
|
||
return <div className="relative w-full md:w-64 mr-2"> | ||
<input | ||
id="algolia-doc-search" | ||
className="appearance-none border rounded py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline w-full" | ||
type="search" | ||
placeholder='Search ("/" to focus)' | ||
ref={input} | ||
/> | ||
</div> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.