Skip to content

Commit

Permalink
Migrate preset-classic
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Sep 17, 2021
1 parent b6d0378 commit 9b97744
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 57 deletions.
4 changes: 2 additions & 2 deletions packages/docusaurus-mdx-loader/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ declare module '@docusaurus/mdx-loader' {
type RemarkOrRehypePlugin =
// eslint-disable-next-line @typescript-eslint/ban-types
[Function, Record<string, unknown>] | Function;
export interface RemarkAndRehypePluginOptions {
export type RemarkAndRehypePluginOptions = {
remarkPlugins: RemarkOrRehypePlugin[];
rehypePlugins: string[];
beforeDefaultRemarkPlugins: RemarkOrRehypePlugin[];
beforeDefaultRehypePlugins: RemarkOrRehypePlugin[];
}
};
}

// TODO Types provided by MDX 2.0 https://github.com/mdx-js/mdx/blob/main/packages/mdx/types/index.d.ts
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type EditUrlFunction = (editUrlParams: {
locale: string;
}) => string | undefined;

export interface PluginOptions extends RemarkAndRehypePluginOptions {
export type PluginOptions = RemarkAndRehypePluginOptions & {
id?: string;
path: string;
routeBasePath: string;
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
editLocalizedFiles?: boolean;
admonitions: Record<string, unknown>;
authorsMapPath: string;
}
};

export interface BlogTags {
[key: string]: BlogTag;
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-pages/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';

export interface PluginOptions extends RemarkAndRehypePluginOptions {
export type PluginOptions = RemarkAndRehypePluginOptions & {
id?: string;
path: string;
routeBasePath: string;
include: string[];
exclude: string[];
mdxPageComponent: string;
admonitions: Record<string, unknown>;
}
};

export type JSXPageMetadata = {
type: 'jsx';
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-sitemap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import {EnumChangefreq} from 'sitemap';

export interface PluginOptions {
export type PluginOptions = {
changefreq?: EnumChangefreq;
priority?: number;
trailingSlash?: boolean;
}
};
6 changes: 5 additions & 1 deletion packages/docusaurus-preset-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"name": "@docusaurus/preset-classic",
"version": "2.0.0-beta.6",
"description": "Classic preset for Docusaurus.",
"main": "src/index.js",
"main": "lib/index.js",
"types": "src/preset-classic.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
},
"publishConfig": {
"access": "public"
},
Expand Down
48 changes: 0 additions & 48 deletions packages/docusaurus-preset-classic/src/index.js

This file was deleted.

71 changes: 71 additions & 0 deletions packages/docusaurus-preset-classic/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import type {
Preset,
LoadContext,
PluginConfig,
PluginOptions,
} from '@docusaurus/types';
import type {Options, ThemeConfig} from '@docusaurus/preset-classic';

function makePluginConfig(
source: string,
options?: PluginOptions,
): string | [string, PluginOptions] {
if (options) {
return [require.resolve(source), options];
}
return require.resolve(source);
}

export default function preset(
context: LoadContext,
opts: Options = {},
): Preset {
const {siteConfig} = context;
const {themeConfig} = siteConfig;
const {algolia, googleAnalytics, gtag} = themeConfig as ThemeConfig;
const isProd = process.env.NODE_ENV === 'production';

const themes: PluginConfig[] = [];
themes.push(makePluginConfig('@docusaurus/theme-classic', opts.theme));
if (algolia) {
themes.push(require.resolve('@docusaurus/theme-search-algolia'));
}

const plugins: PluginConfig[] = [];
if (opts.docs !== false) {
plugins.push(
makePluginConfig('@docusaurus/plugin-content-docs', opts.docs),
);
}
if (opts.blog !== false) {
plugins.push(
makePluginConfig('@docusaurus/plugin-content-blog', opts.blog),
);
}
if (opts.pages !== false) {
plugins.push(
makePluginConfig('@docusaurus/plugin-content-pages', opts.pages),
);
}
if (isProd && googleAnalytics) {
plugins.push(require.resolve('@docusaurus/plugin-google-analytics'));
}
if (opts.debug || (typeof opts.debug === 'undefined' && !isProd)) {
plugins.push(require.resolve('@docusaurus/plugin-debug'));
}
if (isProd && gtag) {
plugins.push(require.resolve('@docusaurus/plugin-google-gtag'));
}
if (isProd && opts.sitemap !== false) {
plugins.push(makePluginConfig('@docusaurus/plugin-sitemap', opts.sitemap));
}

return {themes, plugins};
}
9 changes: 9 additions & 0 deletions packages/docusaurus-preset-classic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"rootDir": "src",
"outDir": "lib"
}
}

0 comments on commit 9b97744

Please sign in to comment.