Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add absolute path to frontmatter meta og:image (cohere) #1223

Merged
merged 10 commits into from
Jul 31, 2024
Merged
1 change: 1 addition & 0 deletions clis/docs-migrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@fern-fern/docs-config": "^0.22.0",
"@fern-ui/core-utils": "workspace:*",
"@fern-api/fdr-sdk": "workspace:*",
"execa": "^5.1.1",
"gray-matter": "^4.0.3",
"lodash-es": "^4.17.21",
Expand Down
4 changes: 3 additions & 1 deletion clis/docs-migrator/src/fern.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DocsV1Read } from "@fern-api/fdr-sdk";

/**
* The layout used for guides. This is the default layout.
* Guides are typically long-form content that is meant to be read from start to finish.
Expand Down Expand Up @@ -47,7 +49,7 @@ export interface FernDocsFrontmatter {
/**
* The URL to the page's image. This is used for the <meta property="og:image"> tag in the HTML.
*/
image?: string;
image?: string | DocsV1Read.FileIdOrUrl;

/**
* Full slug of the page.
Expand Down
2 changes: 2 additions & 0 deletions clis/docs-migrator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ export class MigrateFromMintlify {
content,
};
}

return {
path: mintlify.path,
data: {
title: data.title,
subtitle: data.description,
layout: data.mode != null ? "reference" : undefined,
// TODO: (rohin) investigate this more; it seems like mintlify isn't reliant on fdr, so not sure if there's a transformation here.
image: data["og:image"],
slug,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/mdx/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface FernDocsFrontmatter extends DocsV1Read.MetadataConfig {
/**
* The URL to the page's image. This is used for the <meta property="og:image"> tag in the HTML.
*/
image?: string;
image?: string | DocsV1Read.FileIdOrUrl;

/**
* Renders an "Edit this page" link at the bottom of the page.
Expand Down
29 changes: 26 additions & 3 deletions packages/ui/app/src/next-app/utils/getSeoProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,32 @@ export function getSeoProps(
const { data: frontmatter } = getFrontmatter(page.markdown);
ogMetadata = { ...ogMetadata, ...frontmatter };

// retrofit og:image
if (frontmatter.image != null) {
ogMetadata["og:image"] ??= { type: "url", value: frontmatter.image };
// retrofit og:image, preferring og:image
// TODO: (rohin) Come back here and support more image transformations (twitter, logo, etc)
for (const frontmatterImageVar of [frontmatter.image, frontmatter["og:image"]]) {
if (frontmatterImageVar != null) {
// TODO: (rohin) remove string check when fully migrated, but keeping for back compat
if (typeof frontmatterImageVar === "string") {
ogMetadata["og:image"] ??= {
type: "url",
value: frontmatterImageVar,
};
} else {
visitDiscriminatedUnion(frontmatterImageVar, "type")._visit({
fileId: (fileId) => {
const realId = fileId.value.split(":")[1];
if (realId != null) {
fileId.value = realId;
ogMetadata["og:image"] = fileId;
}
},
url: (url) => {
ogMetadata["og:image"] = url;
},
_other: undefined,
});
}
}
}

seo.title ??= frontmatter.title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ function toFeedItem(
try {
let image: string | undefined;

if (frontmatter.image != null) {
// TODO: (rohin) Clean up after safe deploy, but include for back compat
if (frontmatter.image != null && typeof frontmatter.image === "string") {
image = frontmatter.image;
} else if (frontmatter["og:image"] != null) {
image = toUrl(frontmatter["og:image"], files);
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

Loading