mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
refactor: fix a few places of path handling (#7023)
This commit is contained in:
parent
e6838dd7a6
commit
4957ec947b
7 changed files with 9 additions and 15 deletions
|
@ -9,7 +9,6 @@ import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
|
||||||
import type {BlogPost} from './types';
|
import type {BlogPost} from './types';
|
||||||
import {
|
import {
|
||||||
normalizeUrl,
|
normalizeUrl,
|
||||||
posixPath,
|
|
||||||
mapAsyncSequential,
|
mapAsyncSequential,
|
||||||
readOutputHTMLFile,
|
readOutputHTMLFile,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
|
@ -128,10 +127,7 @@ async function createBlogFeedFile({
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
try {
|
try {
|
||||||
await fs.outputFile(
|
await fs.outputFile(path.join(generatePath, feedPath), feedContent);
|
||||||
posixPath(path.join(generatePath, feedPath)),
|
|
||||||
feedContent,
|
|
||||||
);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Generating ${feedType} feed failed: ${err}.`);
|
throw new Error(`Generating ${feedType} feed failed: ${err}.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ describe('docsVersion', () => {
|
||||||
DEFAULT_OPTIONS,
|
DEFAULT_OPTIONS,
|
||||||
),
|
),
|
||||||
).rejects.toThrowErrorMatchingInlineSnapshot(
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||||
`"[docs]: there is no docs to version!"`,
|
`"[docs]: no docs found in <PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/empty-site/docs."`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ export async function cliDocsVersionCommand(
|
||||||
const {path: docsPath, sidebarPath} = options;
|
const {path: docsPath, sidebarPath} = options;
|
||||||
|
|
||||||
// Copy docs files.
|
// Copy docs files.
|
||||||
const docsDir = path.join(siteDir, docsPath);
|
const docsDir = path.resolve(siteDir, docsPath);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(await fs.pathExists(docsDir)) &&
|
(await fs.pathExists(docsDir)) &&
|
||||||
|
@ -127,7 +127,7 @@ export async function cliDocsVersionCommand(
|
||||||
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
const newVersionDir = path.join(versionedDir, `version-${version}`);
|
||||||
await fs.copy(docsDir, newVersionDir);
|
await fs.copy(docsDir, newVersionDir);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
|
throw new Error(`${pluginIdLogPrefix}: no docs found in ${docsDir}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await createVersionedSidebarFile({
|
await createVersionedSidebarFile({
|
||||||
|
|
|
@ -14,7 +14,7 @@ import type {
|
||||||
SidebarItemCategoryLinkConfig,
|
SidebarItemCategoryLinkConfig,
|
||||||
} from './types';
|
} from './types';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import {addTrailingSlash, posixPath} from '@docusaurus/utils';
|
import {addTrailingSlash} from '@docusaurus/utils';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
import {createDocsByIdIndex, toCategoryIndexMatcherParam} from '../docs';
|
||||||
|
@ -157,7 +157,7 @@ Available doc IDs:
|
||||||
folderName: string,
|
folderName: string,
|
||||||
): WithPosition<NormalizedSidebarItemCategory> {
|
): WithPosition<NormalizedSidebarItemCategory> {
|
||||||
const categoryMetadata =
|
const categoryMetadata =
|
||||||
categoriesMetadata[posixPath(path.join(autogenDir, fullPath))];
|
categoriesMetadata[path.posix.join(autogenDir, fullPath)];
|
||||||
const allItems = Object.entries(dir).map(([key, content]) =>
|
const allItems = Object.entries(dir).map(([key, content]) =>
|
||||||
dirToItem(content, key, `${fullPath}/${key}`),
|
dirToItem(content, key, `${fullPath}/${key}`),
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,7 +37,7 @@ export async function getDataFilePath({
|
||||||
filePath,
|
filePath,
|
||||||
);
|
);
|
||||||
if (contentPath) {
|
if (contentPath) {
|
||||||
return path.join(contentPath, filePath);
|
return path.resolve(contentPath, filePath);
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,7 @@ export default async function serve(
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
cliOptions: ServeCLIOptions,
|
cliOptions: ServeCLIOptions,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let dir = path.isAbsolute(cliOptions.dir)
|
let dir = path.resolve(siteDir, cliOptions.dir);
|
||||||
? cliOptions.dir
|
|
||||||
: path.join(siteDir, cliOptions.dir);
|
|
||||||
|
|
||||||
if (cliOptions.build) {
|
if (cliOptions.build) {
|
||||||
dir = await build(
|
dir = await build(
|
||||||
|
|
|
@ -145,7 +145,7 @@ Maybe you should remove them? ${unknownKeys}`;
|
||||||
|
|
||||||
// should we make this configurable?
|
// should we make this configurable?
|
||||||
function getTranslationsDirPath(context: TranslationContext): string {
|
function getTranslationsDirPath(context: TranslationContext): string {
|
||||||
return path.resolve(path.join(context.siteDir, I18N_DIR_NAME));
|
return path.join(context.siteDir, I18N_DIR_NAME);
|
||||||
}
|
}
|
||||||
export function getTranslationsLocaleDirPath(
|
export function getTranslationsLocaleDirPath(
|
||||||
context: TranslationContext,
|
context: TranslationContext,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue