Skip to content

Commit

Permalink
docs: external sidebar links, filled navbar button, tab slug overrides (
Browse files Browse the repository at this point in the history
#3034)

* external link

* fix bugs

* fix fdr upgrade renames
  • Loading branch information
abvthecity authored Feb 22, 2024
1 parent 3d91632 commit a4e45c5
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 87 deletions.
36 changes: 18 additions & 18 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
16 changes: 9 additions & 7 deletions fern/apis/docs-config/definition/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ types:
properties:
display-name: string
icon: string
slug: optional<string>

DocsInstances:
properties:
Expand Down Expand Up @@ -135,6 +136,7 @@ types:
- PageConfiguration
- SectionConfiguration
- ApiSectionConfiguration
- LinkConfiguration

LogoConfiguration:
properties:
Expand Down Expand Up @@ -328,15 +330,15 @@ types:

NavbarLink:
union:
primary: NavbarPrimaryLink
secondary: NavbarSecondaryLink
filled: LinkConfiguration
outlined: LinkConfiguration
minimal: LinkConfiguration

NavbarPrimaryLink:
properties:
url: string
text: string
# deprecated
primary: LinkConfiguration # use `outlined` instead
secondary: LinkConfiguration # use `minimal` instead

NavbarSecondaryLink:
LinkConfiguration:
properties:
url: string
text: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"dependencies": {
"@fern-api/config-management-commons": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/fdr-sdk": "0.50.1-1-g1f0f637",
"@fern-api/fdr-sdk": "0.50.8-1-gace1ff5",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-fern/docs-config": "0.0.75",
"@fern-fern/docs-config": "0.0.76",
"js-yaml": "^4.1.0",
"tinycolor2": "^1.6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export interface TabbedNavigation {
layout: DocsNavigationItem[];
}

export type DocsNavigationItem = DocsNavigationItem.Page | DocsNavigationItem.Section | DocsNavigationItem.ApiSection;
export type DocsNavigationItem =
| DocsNavigationItem.Page
| DocsNavigationItem.Section
| DocsNavigationItem.ApiSection
| DocsNavigationItem.Link;

export declare namespace DocsNavigationItem {
export interface Page {
Expand All @@ -152,6 +156,12 @@ export declare namespace DocsNavigationItem {
snippetsConfiguration: SnippetsConfiguration | undefined;
}

export interface Link {
type: "link";
text: string;
url: string;
}

export interface SnippetsConfiguration {
python: string | undefined;
typescript: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function getAllPagesFromNavigationItem({
}): Promise<Record<RelativeFilePath, string>> {
switch (item.type) {
case "apiSection":
case "link":
return {};
case "page":
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ export function visitDocsNavigationItem({
case "apiSection":
collector.collect(item);
return;
case "page":
case "section":
item.contents.forEach((subItem) => {
visitDocsNavigationItem({ item: subItem, collector });
});
return;
case "page":
case "link":
return;
default:
assertNever(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function parseDocsConfiguration({
favicon,
backgroundImage,
colors: convertColorsConfiguration(colors ?? {}, context),
navbarLinks: navbarLinks != null ? convertNavbarLinks(navbarLinks) : undefined,
navbarLinks,
typography,
layout: convertLayoutConfig(layout),
css,
Expand Down Expand Up @@ -503,6 +503,13 @@ async function convertNavigationItem({
rawConfig.snippets != null ? convertSnippetsConfiguration({ rawConfig: rawConfig.snippets }) : undefined
};
}
if (isRawLinkConfig(rawConfig)) {
return {
type: "link",
text: rawConfig.text,
url: rawConfig.url
};
}
assertNever(rawConfig);
}

Expand Down Expand Up @@ -534,6 +541,11 @@ function isRawApiSectionConfig(item: RawDocs.NavigationItem): item is RawDocs.Ap
return (item as RawDocs.ApiSectionConfiguration).api != null;
}

function isRawLinkConfig(item: RawDocs.NavigationItem): item is RawDocs.LinkConfiguration {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return (item as RawDocs.LinkConfiguration).url != null;
}

async function convertImageReference({
rawImageReference,
absoluteFilepathToDocsConfig
Expand All @@ -549,27 +561,6 @@ async function convertImageReference({
};
}

function convertNavbarLinks(rawConfig: RawDocs.NavbarLink[]): DocsV1Write.NavbarLink[] {
return rawConfig.map((rawNavbarLink) => {
switch (rawNavbarLink.type) {
case "primary":
return {
type: "primary",
text: rawNavbarLink.text,
url: rawNavbarLink.url
};
case "secondary":
return {
type: "secondary",
text: rawNavbarLink.text,
url: rawNavbarLink.url
};
default:
assertNever(rawNavbarLink);
}
});
}

async function resolveFilepath({
rawUnresolvedFilepath,
absolutePath
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/docs-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/docs-configuration": "workspace:*",
"@fern-api/fdr-sdk": "0.50.1-1-g1f0f637",
"@fern-api/fdr-sdk": "0.50.8-1-gace1ff5",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/ir-generator": "workspace:*",
"@fern-api/register": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-fern/docs-config": "0.0.75",
"@fern-fern/docs-config": "0.0.76",
"cors": "^2.8.5",
"express": "^4.18.2",
"uuid": "^9.0.1"
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/docs-preview/src/previewDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ async function convertNavigationConfig({
apiCollector
})
)
)
),
urlSlugOverride: tabConfig.slug
};
})
)
Expand Down Expand Up @@ -370,6 +371,12 @@ async function convertNavigationItem({
showErrors: item.showErrors
};
}
case "link":
return {
type: "link",
title: item.text,
url: item.url
};
default:
assertNever(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@fern-api/core": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/docs-configuration": "workspace:*",
"@fern-api/fdr-sdk": "0.50.1-1-g1f0f637",
"@fern-api/fdr-sdk": "0.50.8-1-gace1ff5",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generators-configuration": "workspace:*",
"@fern-api/ir-generator": "workspace:*",
Expand All @@ -42,7 +42,7 @@
"@fern-api/register": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-fern/docs-config": "0.0.75",
"@fern-fern/docs-config": "0.0.76",
"@fern-fern/fiddle-sdk": "^0.0.411",
"axios": "^0.28.0",
"chalk": "^5.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ async function convertUnversionedNavigationConfig({
version
})
)
)
),
urlSlugOverride: tabConfig.slug
};
})
)
Expand Down Expand Up @@ -702,6 +703,12 @@ async function convertNavigationItem({
showErrors: item.showErrors
};
}
case "link":
return {
type: "link",
title: item.text,
url: item.url
};
default:
assertNever(item);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@fern-api/task-context": "workspace:*",
"@fern-api/yaml-formatter": "workspace:*",
"@fern-api/yaml-schema": "workspace:*",
"@fern-fern/docs-config": "0.0.75",
"@fern-fern/docs-config": "0.0.76",
"axios": "^0.28.0",
"chalk": "^5.0.1",
"fs-extra": "^11.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fern-api/config-management-commons": "workspace:*",
"@fern-api/core": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/fdr-sdk": "0.50.1-1-g1f0f637",
"@fern-api/fdr-sdk": "0.50.8-1-gace1ff5",
"@fern-api/ir-generator": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/task-context": "workspace:*",
Expand Down
Loading

0 comments on commit a4e45c5

Please sign in to comment.