Skip to content

Commit

Permalink
feat: hidden, skipurlslug, and icon (#3352)
Browse files Browse the repository at this point in the history
impl: hidden, skipurlslug, and icon
  • Loading branch information
abvthecity authored Apr 10, 2024
1 parent a1fb67b commit 32ae9ed
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 12 deletions.
8 changes: 8 additions & 0 deletions packages/cli/configuration/fern/definition/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,18 @@ types:
page: string
path: string
slug: optional<string>
icon: optional<string>
hidden: optional<boolean>

SectionConfiguration:
properties:
section: string
contents: list<NavigationItem>
collapsed: optional<boolean>
slug: optional<string>
icon: optional<string>
hidden: optional<boolean>
skip-slug: optional<boolean>

ApiSectionConfiguration:
properties:
Expand All @@ -377,6 +382,9 @@ types:
type: optional<ApiNavigationItems>
docs: |
Advanced usage: when specified, this object will be used to customize the order that your API endpoints are displayed in the docs site, including subpackages, and additional markdown pages (to be rendered in between API endpoints). If not specified, the order will be inferred from the OpenAPI Spec or Fern Definition.
icon: optional<string>
hidden: optional<boolean>
skip-slug: optional<boolean>

ApiNavigationItem:
docs: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,35 @@ export declare namespace DocsNavigationItem {
export interface Page {
type: "page";
title: string;
icon: string | undefined;
absolutePath: AbsoluteFilePath;
slug: string | undefined;
hidden: boolean | undefined;
}

export interface Section {
type: "section";
title: string;
icon: string | undefined;
contents: DocsNavigationItem[];
collapsed: boolean | undefined;
slug: string | undefined;
hidden: boolean | undefined;
skipUrlSlug: boolean | undefined;
}

export interface ApiSection {
type: "apiSection";
title: string;
icon: string | undefined;
apiName: string | undefined;
audiences: Audiences;
showErrors: boolean;
snippetsConfiguration: SnippetsConfiguration | undefined;
summaryAbsolutePath: AbsoluteFilePath | undefined;
navigation: ParsedApiNavigationItem[];
hidden: boolean | undefined;
skipUrlSlug: boolean | undefined;
}

export interface Link {
Expand Down
25 changes: 15 additions & 10 deletions packages/cli/configuration/src/docs-yml/parseDocsConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,26 +522,32 @@ async function convertNavigationItem({
absolutePath: absolutePathToConfig,
rawUnresolvedFilepath: rawConfig.path
}),
slug: rawConfig.slug ?? undefined
slug: rawConfig.slug,
icon: rawConfig.icon,
hidden: rawConfig.hidden
};
}
if (isRawSectionConfig(rawConfig)) {
return {
type: "section",
title: rawConfig.section,
icon: rawConfig.icon,
contents: await Promise.all(
rawConfig.contents.map((item) =>
convertNavigationItem({ rawConfig: item, absolutePathToFernFolder, absolutePathToConfig, context })
)
),
slug: rawConfig.slug ?? undefined,
collapsed: rawConfig.collapsed ?? undefined
collapsed: rawConfig.collapsed ?? undefined,
hidden: rawConfig.hidden ?? undefined,
skipUrlSlug: rawConfig.skipSlug ?? false
};
}
if (isRawApiSectionConfig(rawConfig)) {
return {
type: "apiSection",
title: rawConfig.api,
icon: rawConfig.icon,
apiName: rawConfig.apiName ?? undefined,
audiences:
rawConfig.audiences != null ? { type: "select", audiences: rawConfig.audiences } : { type: "all" },
Expand All @@ -557,7 +563,9 @@ async function convertNavigationItem({
absolutePath: absolutePathToConfig,
rawUnresolvedFilepath: rawConfig.summary
})
: undefined
: undefined,
hidden: rawConfig.hidden ?? undefined,
skipUrlSlug: rawConfig.skipSlug ?? false
};
}
if (isRawLinkConfig(rawConfig)) {
Expand All @@ -575,12 +583,7 @@ function parseApiNavigationItem(
absolutePathToConfig: AbsoluteFilePath
): ParsedApiNavigationItem[] {
if (typeof item === "string") {
return [
{
type: "item",
value: item
}
];
return [{ type: "item", value: item }];
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -593,7 +596,9 @@ function parseApiNavigationItem(
absolutePath: absolutePathToConfig,
rawUnresolvedFilepath: item.path
}),
slug: item.slug ?? undefined
slug: item.slug,
icon: item.icon,
hidden: item.hidden
}
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export interface ApiSectionConfiguration {
summary?: string;
/** Advanced usage: when specified, this object will be used to customize the order that your API endpoints are displayed in the docs site, including subpackages, and additional markdown pages (to be rendered in between API endpoints). If not specified, the order will be inferred from the OpenAPI Spec or Fern Definition. */
layout?: FernDocsConfig.ApiNavigationItems;
icon?: string;
hidden?: boolean;
skipSlug?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export interface PageConfiguration {
page: string;
path: string;
slug?: string;
icon?: string;
hidden?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export interface SectionConfiguration {
contents: FernDocsConfig.NavigationItem[];
collapsed?: boolean;
slug?: string;
icon?: string;
hidden?: boolean;
skipSlug?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const ApiSectionConfiguration: core.serialization.ObjectSchema<
snippets: core.serialization.lazyObject(async () => (await import("../../..")).SnippetsConfiguration).optional(),
summary: core.serialization.string().optional(),
layout: core.serialization.lazy(async () => (await import("../../..")).ApiNavigationItems).optional(),
icon: core.serialization.string().optional(),
hidden: core.serialization.boolean().optional(),
skipSlug: core.serialization.property("skip-slug", core.serialization.boolean().optional()),
});

export declare namespace ApiSectionConfiguration {
Expand All @@ -28,5 +31,8 @@ export declare namespace ApiSectionConfiguration {
snippets?: serializers.SnippetsConfiguration.Raw | null;
summary?: string | null;
layout?: serializers.ApiNavigationItems.Raw | null;
icon?: string | null;
hidden?: boolean | null;
"skip-slug"?: boolean | null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ export const PageConfiguration: core.serialization.ObjectSchema<
page: core.serialization.string(),
path: core.serialization.string(),
slug: core.serialization.string().optional(),
icon: core.serialization.string().optional(),
hidden: core.serialization.boolean().optional(),
});

export declare namespace PageConfiguration {
interface Raw {
page: string;
path: string;
slug?: string | null;
icon?: string | null;
hidden?: boolean | null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const SectionConfiguration: core.serialization.ObjectSchema<
contents: core.serialization.list(core.serialization.lazy(async () => (await import("../../..")).NavigationItem)),
collapsed: core.serialization.boolean().optional(),
slug: core.serialization.string().optional(),
icon: core.serialization.string().optional(),
hidden: core.serialization.boolean().optional(),
skipSlug: core.serialization.property("skip-slug", core.serialization.boolean().optional()),
});

export declare namespace SectionConfiguration {
Expand All @@ -22,5 +25,8 @@ export declare namespace SectionConfiguration {
contents: serializers.NavigationItem.Raw[];
collapsed?: boolean | null;
slug?: string | null;
icon?: string | null;
hidden?: boolean | null;
"skip-slug"?: boolean | null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,11 @@ async function convertNavigationItem({
convertedItem = {
type: "page",
title: item.title,
icon: item.icon,
id: relative(dirname(parsedDocsConfig.absoluteFilepath), item.absolutePath),
urlSlugOverride: item.slug,
fullSlug: fullSlugs[item.absolutePath]?.fullSlug?.split("/")
fullSlug: fullSlugs[item.absolutePath]?.fullSlug?.split("/"),
hidden: item.hidden
};
break;
}
Expand All @@ -882,7 +884,10 @@ async function convertNavigationItem({
title: item.title,
items: sectionItems.map((sectionItem) => sectionItem.item),
urlSlugOverride: item.slug,
collapsed: item.collapsed
collapsed: item.collapsed,
icon: item.icon,
hidden: item.hidden,
skipUrlSlug: item.skipUrlSlug
};
for (const sectionItem of sectionItems) {
pages = {
Expand Down

0 comments on commit 32ae9ed

Please sign in to comment.