Skip to content

Commit

Permalink
feat(v2): allow skipping build docs for next version (#2877)
Browse files Browse the repository at this point in the history
* feat(v2): allow skipping build docs for next version

* Refactor

* Refactor

Co-authored-by: Sébastien Lorber <[email protected]>
  • Loading branch information
lex111 and slorber authored Jun 25, 2020
1 parent 8304e82 commit bdffd28
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
55 changes: 31 additions & 24 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
showLastUpdateTime: false,
showLastUpdateAuthor: false,
admonitions: {},
excludeNextVersionDocs: false,
};

function getFirstDocLinkOfSidebar(
Expand Down Expand Up @@ -175,25 +176,30 @@ export default function pluginContentDocs(
// Prepare metadata container.
const docsMetadataRaw: DocsMetadataRaw = {};
const docsPromises = [];
const includeDefaultDocs = !(
options.excludeNextVersionDocs && process.argv[2] === 'build'
);

// Metadata for default/master docs files.
const docsFiles = await globby(include, {
cwd: docsDir,
});
docsPromises.push(
Promise.all(
docsFiles.map(async (source) => {
const metadata: MetadataRaw = await processMetadata({
source,
refDir: docsDir,
context,
options,
env,
});
docsMetadataRaw[metadata.id] = metadata;
}),
),
);
if (includeDefaultDocs) {
const docsFiles = await globby(include, {
cwd: docsDir,
});
docsPromises.push(
Promise.all(
docsFiles.map(async (source) => {
const metadata: MetadataRaw = await processMetadata({
source,
refDir: docsDir,
context,
options,
env,
});
docsMetadataRaw[metadata.id] = metadata;
}),
),
);
}

// Metadata for versioned docs.
if (versioning.enabled) {
Expand Down Expand Up @@ -222,13 +228,14 @@ export default function pluginContentDocs(
}

// Load the sidebars and create docs ordering.
const sidebarPaths = [
sidebarPath,
...versionsNames.map(
(versionName) =>
`${versionedSidebarsDir}/${versionName}-sidebars.json`,
),
];
const sidebarPaths = versionsNames.map(
(versionName) => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
);

if (includeDefaultDocs) {
sidebarPaths.unshift(sidebarPath);
}

const loadedSidebars: Sidebar = loadSidebars(sidebarPaths);
const order: Order = createOrder(loadedSidebars);

Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface PluginOptions extends MetadataOptions, PathOptions {
remarkPlugins: ([Function, object] | Function)[];
rehypePlugins: string[];
admonitions: any;
excludeNextVersionDocs: boolean;
}

export type SidebarItemDoc = {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/using-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ module.exports = {
* Whether to display the last date the doc was updated.
*/
showLastUpdateTime: false,
/**
* Skip the next release docs when versioning is enabled.
* This will not generate HTML files in the production build for documents
* in `/docs/next` directory, only versioned docs.
*/
excludeNextVersionDocs: false,
},
],
],
Expand Down

0 comments on commit bdffd28

Please sign in to comment.