Skip to content
Merged
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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"lint:prettier:fix": "prettier --write \"./{src,app,scripts}/**/*.{md,mdx,ts,tsx,js,jsx,mjs}\"",
"lint:fix": "yarn run lint:prettier:fix && yarn run lint:eslint:fix",
"sidecar": "yarn spotlight-sidecar",
"test": "jest"
"test": "jest",
"build-trace": "npx next@canary internal turbo-trace-server .next/trace"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep that?

},
"prisma": {
"seed": "node prisma/seed/seed.mjs"
Expand All @@ -36,9 +37,9 @@
"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.0.0",
"@google-cloud/storage": "^7.7.0",
"@mdx-js/loader": "^3.0.0",
"@mdx-js/react": "^3.0.0",
"@next/mdx": "^14.0.1",
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@next/mdx": "^14.2.4",
"@popperjs/core": "^2.11.8",
"@prettier/plugin-xml": "^3.3.1",
"@prisma/client": "^5.8.1",
Expand All @@ -51,7 +52,7 @@
"@radix-ui/themes": "^2.0.3",
"@sentry-internal/global-search": "^1.0.0",
"@sentry/nextjs": "^8.8.0",
"@types/mdx": "^2.0.9",
"@types/mdx": "^2.0.13",
"algoliasearch": "^4.23.3",
"esbuild": "^0.19.8",
"framer-motion": "^10.12.16",
Expand All @@ -61,9 +62,9 @@
"js-cookie": "^3.0.5",
"js-yaml": "^4.1.0",
"match-sorter": "^6.3.4",
"mdx-bundler": "^10.0.1",
"mdx-bundler": "^10.0.2",
"micromark": "^4.0.0",
"next": "14.0.2",
"next": "14.2.4",
"next-auth": "^4.24.5",
"next-mdx-remote": "^4.4.1",
"nextjs-toploader": "^1.6.6",
Expand Down
46 changes: 24 additions & 22 deletions src/mdx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';

import matter from 'gray-matter';
import {s} from 'hastscript';
Expand Down Expand Up @@ -28,7 +29,8 @@ import remarkTocHeadings, {TocNode} from './remark-toc-headings';
import remarkVariables from './remark-variables';
import {FrontMatter, Platform, PlatformConfig} from './types';

const root = process.cwd();
// @ts-ignore
const directoryName = path.dirname(fileURLToPath(import.meta.url));

function formatSlug(slug: string) {
return slug.replace(/\.(mdx|md)/, '');
Expand Down Expand Up @@ -96,8 +98,8 @@ async function getDocsFrontMatterUncached(): Promise<FrontMatter[]> {
return frontMatter;
}

export function getAllFilesFrontMatter(folder: string = 'docs') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this folder shouldn't be hardcoded as we need to pass it as a parameter for developer docs for example later on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it doesn't need to be. We can add it back if needed. We shouldn't add code for the mere possibility of needing it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just mentioned it since this is deleting something that was already there, but I see what you mean

const docsPath = path.join(root, folder);
function getAllFilesFrontMatter() {
const docsPath = path.join(directoryName, '..', 'docs');
const files = getAllFilesRecursively(docsPath);
const allFrontMatter: FrontMatter[] = [];
files.forEach(file => {
Expand All @@ -115,15 +117,10 @@ export function getAllFilesFrontMatter(folder: string = 'docs') {
allFrontMatter.push({
...(frontmatter as FrontMatter),
slug: formatSlug(fileName),
sourcePath: path.join(folder, fileName),
sourcePath: path.join('docs', fileName),
});
});

if (folder !== 'docs') {
// We exit early if we're not in the docs folder. We use this for the changelog.
return allFrontMatter;
}

// Add all `common` files in the right place.
const platformsPath = path.join(docsPath, 'platforms');
const platformNames = fs
Expand Down Expand Up @@ -218,17 +215,17 @@ export function getAllFilesFrontMatter(folder: string = 'docs') {
}

export async function getFileBySlug(slug: string) {
const configPath = path.join(root, slug, 'config.yml');
const configPath = path.join(directoryName, '..', slug, 'config.yml');

let configFrontmatter: PlatformConfig | undefined;
if (fs.existsSync(configPath)) {
configFrontmatter = yaml.load(fs.readFileSync(configPath, 'utf8')) as PlatformConfig;
}

let mdxPath = path.join(root, `${slug}.mdx`);
let mdxIndexPath = path.join(root, slug, 'index.mdx');
let mdPath = path.join(root, `${slug}.md`);
let mdIndexPath = path.join(root, slug, 'index.md');
let mdxPath = path.join(directoryName, '..', `${slug}.mdx`);
let mdxIndexPath = path.join(directoryName, '..', slug, 'index.mdx');
let mdPath = path.join(directoryName, '..', `${slug}.md`);
let mdIndexPath = path.join(directoryName, '..', slug, 'index.md');

if (
slug.indexOf('docs/platforms/') === 0 &&
Expand All @@ -249,18 +246,20 @@ export async function getFileBySlug(slug: string) {
commonFilePath = path.join(commonPath, slugParts.slice(3).join('/'));
}
if (commonFilePath && fs.existsSync(commonPath)) {
mdxPath = path.join(root, `${commonFilePath}.mdx`);
mdxIndexPath = path.join(root, commonFilePath, 'index.mdx');
mdPath = path.join(root, `${commonFilePath}.md`);
mdIndexPath = path.join(root, commonFilePath, 'index.md');
mdxPath = path.join(directoryName, '..', `${commonFilePath}.mdx`);
mdxIndexPath = path.join(directoryName, '..', commonFilePath, 'index.mdx');
mdPath = path.join(directoryName, '..', `${commonFilePath}.md`);
mdIndexPath = path.join(directoryName, '..', commonFilePath, 'index.md');
}
}

const sourcePath = [mdxPath, mdxIndexPath, mdPath].find(fs.existsSync) ?? mdIndexPath;
const sourcePath =
[mdxPath, mdxIndexPath, mdPath].find(p => fs.existsSync(p)) ?? mdIndexPath;
const source = fs.readFileSync(sourcePath, 'utf8');

process.env.ESBUILD_BINARY_PATH = path.join(
root,
directoryName,
'..',
'node_modules',
'esbuild',
'bin',
Expand All @@ -285,7 +284,10 @@ export async function getFileBySlug(slug: string) {
[remarkTocHeadings, {exportRef: toc}],
remarkGfm,
remarkFormatCodeBlocks,
[remarkImageSize, {sourceFolder: cwd, publicFolder: path.join(root, 'public')}],
[
remarkImageSize,
{sourceFolder: cwd, publicFolder: path.join(directoryName, '..', 'public')},
],
remarkMdxImages,
remarkCodeTitles,
remarkCodeTabs,
Expand Down Expand Up @@ -353,7 +355,7 @@ export async function getFileBySlug(slug: string) {
};
// Set the `outdir` to a public location for this bundle.
// this where this images will be copied
options.outdir = path.join(root, 'public', 'mdx-images');
options.outdir = path.join(directoryName, '..', 'public', 'mdx-images');

// Set write to true so that esbuild will output the files.
options.write = true;
Expand Down
1 change: 1 addition & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"headers": [
{
"source": "/(.*)",
Expand Down
Loading