Skip to content

Commit

Permalink
(fix): markdown files are read with absolute path (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Mar 13, 2024
1 parent c0f39c8 commit a4e07b9
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createFdrService } from "@fern-api/core";
import { assertNever, entries, isNonNullish } from "@fern-api/core-utils";
import { getReferencedMarkdownFiles } from "@fern-api/docs-validator";
import { APIV1Write, DocsV1Write, DocsV2Write } from "@fern-api/fdr-sdk";
import { AbsoluteFilePath, dirname, relative } from "@fern-api/fs-utils";
import { AbsoluteFilePath, dirname, join, relative, RelativeFilePath } from "@fern-api/fs-utils";
import { registerApi } from "@fern-api/register";
import { TaskContext } from "@fern-api/task-context";
import { DocsWorkspace, FernWorkspace } from "@fern-api/workspace-loader";
Expand Down Expand Up @@ -235,10 +235,11 @@ async function constructRegisterDocsRequest({
};
pages = Object.fromEntries(
Object.entries(pages).map(([pageId, pageContent]) => {
const slug = fullSlugs[pageId]?.fullSlug;
const references = getReferencedMarkdownFiles({
content: pageContent.markdown,
absoluteFilepath: AbsoluteFilePath.of(pageId)
absoluteFilepath: pageId.startsWith("/")
? AbsoluteFilePath.of(pageId)
: convertFdrFilepathToAbsoluteFilepath(RelativeFilePath.of(pageId), parsedDocsConfig)
});
let markdown = pageContent.markdown;
for (const reference of references) {
Expand Down Expand Up @@ -1106,6 +1107,13 @@ function convertAbsoluteFilepathToFdrFilepath(
return relative(dirname(parsedDocsConfig.absoluteFilepath), filepath);
}

function convertFdrFilepathToAbsoluteFilepath(
filepath: RelativeFilePath,
parsedDocsConfig: docsYml.ParsedDocsConfiguration
) {
return join(dirname(parsedDocsConfig.absoluteFilepath), filepath);
}

function wrapWithHttps(url: string): string {
return url.startsWith("https://") || url.startsWith("http://") ? url : `https://${url}`;
}

0 comments on commit a4e07b9

Please sign in to comment.