Skip to content

Commit 881017b

Browse files
committed
add file path logs, to find the culprit
1 parent c1b4076 commit 881017b

File tree

7 files changed

+36
-12
lines changed

7 files changed

+36
-12
lines changed

frontend/src/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ export const API_ADDRESS =
33

44
export const WEB_ADDRESS =
55
process.env.NEXT_PUBLIC_WEB_ADDRESS ?? "https://open.mp";
6-
7-
console.log(API_ADDRESS, WEB_ADDRESS);

frontend/src/mdx-helpers/babel-plugin-mdx-browser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ export default function BabelPluginMdxBrowser() {
22
return {
33
visitor: {
44
// remove all imports, we will add these to scope manually
5+
Program(path, state) {
6+
// Log the filename using state
7+
const filename = state.file.opts.filename || "Unknown file";
8+
console.log("Processing file:", filename);
9+
},
510
ImportDeclaration(path: any) {
611
path.remove();
712
},

frontend/src/mdx-helpers/csr.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import "./idle-callback-polyfill";
99

1010
// Renders markdown content on the client side using the props passed to the
1111
// page component from `markdownSSR`.
12-
export const markdownCSR = (content: MarkdownContent): JSX.Element =>
13-
hydrate(content, {
14-
components: MDX_COMPONENTS,
15-
});
12+
// export const markdownCSR = (content: MarkdownContent): JSX.Element =>
13+
// hydrate(content, {
14+
// components: MDX_COMPONENTS,
15+
// });
1616

1717
// Stolen from Hashicorp's next-mdx-remote!
1818
export const hydrate = (

frontend/src/mdx-helpers/ssr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ export const markdownSSR = async (
2121
const { source } = await readLocaleContent(file, locale);
2222
return await renderToString(source, {
2323
components: MDX_COMPONENTS,
24+
fileName: file
2425
});
2526
};
2627

2728
// Stolen from Hashicorp's next-mdx-remote!
2829
export const renderToString = async (
2930
source: Buffer | string,
30-
{ components, mdxOptions, scope = {} }: MarkdownRenderConfig
31+
{ components, mdxOptions, scope = {}, fileName }: MarkdownRenderConfig
3132
): Promise<MarkdownContent> => {
3233
// transform it into react
3334
const code = await mdx(source, { ...mdxOptions, skipExport: true });
@@ -47,6 +48,7 @@ export const renderToString = async (
4748
presets: [presetReact, presetEnv],
4849
plugins: [pluginBrowser],
4950
configFile: false,
51+
filename: fileName
5052
});
5153

5254
// evaluate the code

frontend/src/mdx-helpers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export type MarkdownRenderConfig = {
1010
components: Components;
1111
mdxOptions?: any;
1212
scope?: any;
13+
fileName: string;
1314
};

frontend/src/pages/[...slug].tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ type Props = {
2525
error?: string;
2626
data?: { [key: string]: any };
2727
fallback?: boolean;
28+
filePath?: string;
2829
};
2930

30-
const Page = ({ source, error, data, fallback }: Props) => {
31+
const Page = ({ source, error, data, fallback, filePath }: Props) => {
3132
if (error) {
3233
return (
3334
<section>
@@ -37,7 +38,11 @@ const Page = ({ source, error, data, fallback }: Props) => {
3738
}
3839

3940
const content =
40-
source && hydrate(source, { components: components as Components });
41+
source &&
42+
hydrate(source, {
43+
components: components as Components,
44+
fileName: filePath,
45+
});
4146

4247
const codeColor = useColorModeValue(
4348
"var(--chakra-colors-gray-200)",
@@ -87,7 +92,6 @@ import {
8792
import { renderToString } from "src/mdx-helpers/ssr";
8893
import { RawContent } from "src/types/content";
8994
import { Components } from "@mdx-js/react";
90-
import { concat, flatten, flow, map } from "lodash/fp";
9195
import rehypeStarryNight from "@microflash/rehype-starry-night";
9296

9397
export async function getStaticProps(
@@ -107,6 +111,7 @@ export async function getStaticProps(
107111

108112
const mdxSource = await renderToString(content, {
109113
components: components as Components,
114+
fileName: route.join("/"),
110115
mdxOptions: {
111116
components: components as Components,
112117
rehypePlugins: [
@@ -115,7 +120,14 @@ export async function getStaticProps(
115120
},
116121
});
117122

118-
return { props: { source: mdxSource, data, fallback: result.fallback } };
123+
return {
124+
props: {
125+
source: mdxSource,
126+
data,
127+
fallback: result.fallback,
128+
filePath: route.join("/"),
129+
},
130+
};
119131
}
120132

121133
export function getStaticPaths(): GetStaticPathsResult {

frontend/src/pages/docs/[[...path]].tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Props = {
1919
data?: { [key: string]: any };
2020
fallback?: boolean;
2121
ghUrl?: string;
22+
filePath?: string;
2223
};
2324

2425
const Page = (props: Props) => {
@@ -31,7 +32,10 @@ const Page = (props: Props) => {
3132
// not there was an error in the following if-statement.
3233
const content =
3334
props.source &&
34-
hydrate(props.source, { components: components as Components });
35+
hydrate(props.source, {
36+
components: components as Components,
37+
fileName: props.filePath,
38+
});
3539

3640
const codeColor = useColorModeValue(
3741
"var(--chakra-colors-gray-200)",
@@ -193,6 +197,7 @@ export async function getStaticProps(
193197
// TODO: plugin for frontmatter
194198
const mdxSource = await renderToString(content, {
195199
components,
200+
fileName: path,
196201
mdxOptions: {
197202
remarkPlugins: [
198203
admonitions,
@@ -210,6 +215,7 @@ export async function getStaticProps(
210215
data,
211216
fallback: result.fallback,
212217
ghUrl: getDocsGithubUrl(path, !result.fallback, locale),
218+
filePath: path,
213219
},
214220
};
215221
}

0 commit comments

Comments
 (0)