Skip to content

Commit

Permalink
encapsulate hacky isDocsPluginEnabled in docsUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 12, 2020
1 parent 80d1fba commit 15424bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 0 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/hooks/useDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924
try {
module.exports = require('@theme-init/hooks/useDocs');
exports.docsPluginEnabled = true;
} catch (e) {
module.exports = {};
exports.docsPluginEnabled = false;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import React, {
useState,
} from 'react';
import useThemeConfig, {DocsVersionPersistence} from '../useThemeConfig';
import {isDocsPluginEnabled} from '../docsUtils';

import {useAllDocsData} from '@theme/hooks/useDocs';

import {docsPluginEnabled, useAllDocsData} from '@theme/hooks/useDocs';
import DocsPreferredVersionStorage from './DocsPreferredVersionStorage';

type DocsPreferredVersionName = string | null;
Expand Down Expand Up @@ -132,7 +134,7 @@ export default function DocsPreferredVersionContextProvider({
}: {
children: ReactNode;
}) {
if (docsPluginEnabled) {
if (isDocsPluginEnabled) {
return (
<DocsPreferredVersionContextProviderUnsafe>
{children}
Expand Down
11 changes: 11 additions & 0 deletions packages/docusaurus-theme-classic/src/utils/docsUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* 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 {useAllDocsData} from '@theme/hooks/useDocs';

// TODO not ideal, see also "useDocs"
export const isDocsPluginEnabled: boolean = !!useAllDocsData;

0 comments on commit 15424bb

Please sign in to comment.