Skip to content

Commit 4d0d2e3

Browse files
committed
Preview - improve format detection
Format may be a string or a complex object. Look at both. fixes #8662
1 parent 078cac0 commit 4d0d2e3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/project/serve/serve.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,32 @@ export async function serveProject(
140140
throw new Error(`${target} is not a project`);
141141
}
142142

143+
const isDocusaurusMd = (
144+
format?: string | Record<string, unknown> | unknown,
145+
) => {
146+
if (!format) {
147+
return false;
148+
}
149+
150+
if (typeof format === "string") {
151+
return format === "docusaurus-md";
152+
} else if (typeof format === "object") {
153+
const formats = Object.keys(format);
154+
if (formats.length > 0) {
155+
const firstFormat = Object.keys(format)[0];
156+
return firstFormat === "docusaurus-md";
157+
} else {
158+
return false;
159+
}
160+
} else {
161+
return false;
162+
}
163+
};
164+
143165
// Default project types can't be served
144166
const projType = projectType(project?.config?.project?.[kProjectType]);
145167
if (
146-
projType.type === "default" && project?.config?.format !== "docusaurus-md"
168+
projType.type === "default" && !isDocusaurusMd(project?.config?.format)
147169
) {
148170
const hasIndex = project.files.input.some((file) => {
149171
let relPath = file;

0 commit comments

Comments
 (0)