Skip to content
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

exports convertToPageMap, mergeMetaWithPageMap, normalizePageMap, evaluate from nextra #1906

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/fast-drinks-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theguild/components': patch
---

exports `convertToPageMap`, `mergeMetaWithPageMap`, `normalizePageMap`, `evaluate` from nextra
9 changes: 8 additions & 1 deletion packages/components/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ export { MDXRemote } from 'nextra/mdx-remote';

export { fetchFilePathsFromGitHub } from 'nextra/fetch-filepaths-from-github';
export { compileMdx } from 'nextra/compile';
export { getPageMap, createIndexPage } from 'nextra/page-map';
export {
getPageMap,
createIndexPage,
convertToPageMap,
mergeMetaWithPageMap,
normalizePageMap,
} from 'nextra/page-map';
export { evaluate } from 'nextra/evaluate';
export { fetchPackageInfo } from './npm.js';
export { sharedMetaItems } from './shared-meta-items';

Expand Down
3 changes: 0 additions & 3 deletions packages/components/src/server/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@

const require = createRequire(import.meta.url);

function getFrontMatterASTObject(node: any) {

Check warning on line 19 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
const [n] = node.data!.estree!.body;
return (n as any).declaration.declarations[0].init.properties;

Check warning on line 21 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
}

function isExportNode(node: any, varName: string) {

Check warning on line 24 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
if (node.type !== 'mdxjsEsm') return false;
const [n] = node.data!.estree!.body;

if (n.type !== 'ExportNamedDeclaration') return false;

const name = (n as any).declaration?.declarations?.[0].id.name;

Check warning on line 30 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
if (!name) return false;

return name === varName;
}

const rehypeCheckFrontMatter: Plugin<[], any> = () => (ast, file) => {

Check warning on line 36 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
const [filePath] = file.history;
// Skip if no file path (e.g. dynamic mdx without filePath provided)
if (!filePath) return;
Expand All @@ -54,9 +54,9 @@
}
}

const frontMatterNode = ast.children.find((node: any) => isExportNode(node, 'metadata'))!;

Check warning on line 57 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
const frontMatter = getFrontMatterASTObject(frontMatterNode);
const description = frontMatter.find((o: any) => o.key.value === 'description')?.value

Check warning on line 59 in packages/components/src/server/next.config.ts

View workflow job for this annotation

GitHub Actions / Build

Unexpected any. Specify a different type
.value as string;

if (!description) {
Expand All @@ -75,9 +75,6 @@
export const defaultNextraOptions: NextraConfig = {
defaultShowCopyCode: true,
whiteListTagsStyling: ['iframe', 'video', 'source'],
search: {
codeblocks: true,
},
mdxOptions: {
// Check front matter only in production (when Webpack is used)
// Should be rehype since frontMatter is attached in remark plugins
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/server/theme-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentProps, FC, ReactNode } from 'react';
import { Metadata } from 'next';
import { PageMapItem } from 'nextra';
import { Layout, Navbar } from 'nextra-theme-docs';
import { Head } from 'nextra/components';
import { getPageMap } from 'nextra/page-map';
Expand Down Expand Up @@ -72,6 +73,7 @@ export const GuildLayout: FC<{
* Nextra's Docs Theme `<Navbar>` component props
*/
navbarProps: NavbarProps;
pageMap?: PageMapItem[];
}> = async ({
children,
websiteName,
Expand All @@ -81,8 +83,9 @@ export const GuildLayout: FC<{
logo,
layoutProps,
navbarProps,
...props
}) => {
const [meta, ...pageMap] = await getPageMap();
const [meta, ...pageMap] = props.pageMap || (await getPageMap());

const pageMapWithCompanyMenu = [
{
Expand Down
Loading