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: og images #540

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 42 additions & 30 deletions src/theme/BlogPostItem/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import TagsListInline from '@theme/TagsListInline';
import ReadMoreLink from '@theme/BlogPostItem/Footer/ReadMoreLink';
import styles from './styles.module.css';
import { AuthorSummary } from '../../../component/AuthorSummary';
import Head from '@docusaurus/Head';
export default function BlogPostItemFooter() {
const { metadata, isBlogPostPage } = useBlogPost();
const { tags, title, editUrl, hasTruncateMarker, authors } = metadata;
const { tags, title, editUrl, hasTruncateMarker, authors, frontMatter } =
metadata;
const { image } = frontMatter;
// A post is truncated if it's in the "list view" and it has a truncate marker
const truncatedPost = !isBlogPostPage && hasTruncateMarker;
const tagsExists = tags.length > 0;
Expand All @@ -18,38 +21,47 @@ export default function BlogPostItemFooter() {
return null;
}
return (
<footer
className={clsx(
'row docusaurus-mt-lg',
isBlogPostPage && styles.blogPostFooterDetailsFull
<>
{image && (
<Head>
<meta property="og:image" content={image} />
</Head>
)}
>
{!truncatedPost &&
authors.map((author, i) => {
return <AuthorSummary key={i} author={author} />;
})}
{renderFooter ? (
<footer
className={clsx(
'row docusaurus-mt-lg',
isBlogPostPage && styles.blogPostFooterDetailsFull
)}
>
{!truncatedPost &&
authors.map((author, i) => {
return <AuthorSummary key={i} author={author} />;
})}

{tagsExists && (
<div className={clsx('col', { 'col--9': truncatedPost })}>
<TagsListInline tags={tags} />
</div>
)}
{tagsExists && (
<div className={clsx('col', { 'col--9': truncatedPost })}>
<TagsListInline tags={tags} />
</div>
)}

{isBlogPostPage && editUrl && (
<div className="col margin-top--sm">
<EditThisPage editUrl={editUrl} />
</div>
)}
{isBlogPostPage && editUrl && (
<div className="col margin-top--sm">
<EditThisPage editUrl={editUrl} />
</div>
)}

{truncatedPost && (
<div
className={clsx('col text--right', {
'col--3': tagsExists,
})}
>
<ReadMoreLink blogPostTitle={title} to={metadata.permalink} />
</div>
)}
</footer>
{truncatedPost && (
<div
className={clsx('col text--right', {
'col--3': tagsExists,
})}
>
<ReadMoreLink blogPostTitle={title} to={metadata.permalink} />
</div>
)}
</footer>
) : null}
</>
);
}
2 changes: 2 additions & 0 deletions src/theme/LayoutContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export const LayoutContent = ({ children }) => {
content="boppg6u2f0982xhjbg7jtr9odtchvk"
/>
</Head>
{/** default og image can be overriten in the Head */}
<meta property="og:image" content="/img/og-default.svg" />
{trackingId && (
<div
dangerouslySetInnerHTML={{
Expand Down
Loading
Loading