Skip to content

Commit

Permalink
chore: remark plugins from source
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 28, 2023
1 parent c147109 commit 815ac43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 506 deletions.
19 changes: 18 additions & 1 deletion src/lib/md-doc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { compile } from '@mdx-js/mdx';
import { addRawDocumentToVFile } from 'contentlayer/core';
import type { MdDoc } from 'contentlayer/generated';
import { readFileSync } from 'fs';
import { join } from 'path';
import { codeExamples } from '~/docs/fuel-graphql-docs/src/lib/code-examples';
import { codeImport as walletCodeImport } from '~/docs/fuels-wallet/packages/docs/src/lib/code-import';

import { DOCS_DIRECTORY } from '../config/constants';
import type { Config, DocType, SidebarLinkItem } from '../types';
Expand Down Expand Up @@ -79,7 +82,7 @@ export class Doc {
outputFormat: 'function-body',
format: doc._raw.contentType === 'markdown' ? 'md' : 'mdx',
providerImportSource: '@mdx-js/react',
remarkPlugins: [addRawDocumentToVFile(this.md._raw), ...remarkPlugins],
remarkPlugins: this.#remarkPlugins(),
rehypePlugins: [
...rehypePlugins,
rehypeExtractHeadings({
Expand Down Expand Up @@ -151,4 +154,18 @@ export class Doc {
#createUrl(slug: string) {
return `${BASE_URL}${slug.replace('../', '').replace('./', '')}`;
}

#remarkPlugins() {
const filepath = this.md._raw.sourceFilePath;
let plugins = [addRawDocumentToVFile(this.md._raw), ...remarkPlugins];

if (this.md.slug.startsWith('docs/wallet/')) {
plugins = plugins.concat([[walletCodeImport, { filepath }] as any]);
}
if (this.md.slug.startsWith('docs/graphql/')) {
plugins = plugins.concat([[codeExamples, { filepath }] as any]);
}

return plugins;
}
}
4 changes: 0 additions & 4 deletions src/lib/md-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ import remarkSlug from 'remark-slug';

import { codeImport } from './plugins/code-import';
import { fixIndent } from './plugins/fix-indent';
import { gqlCodeExamples } from './plugins/gql-code-examples';
import { handlePlugins } from './plugins/plugins';
import { getMdxCode } from './plugins/rehype-code';
import { codeImport as walletCodeImport } from './plugins/wallet-code-import';

export const remarkPlugins = [
remarkSlug,
remarkGfm,
handlePlugins,
fixIndent,
codeImport,
walletCodeImport,
gqlCodeExamples,
];

export const rehypePlugins = getMdxCode();
263 changes: 0 additions & 263 deletions src/lib/plugins/gql-code-examples.ts

This file was deleted.

Loading

0 comments on commit 815ac43

Please sign in to comment.