Skip to content

Commit

Permalink
Add author and publication date to OpenGraph metadata
Browse files Browse the repository at this point in the history
Refers to #158
  • Loading branch information
michel-kraemer committed Apr 14, 2024
1 parent f4c2eb2 commit 84bfa7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
13 changes: 10 additions & 3 deletions components/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Head from "next/head"
import NavBar from "./NavBar"

const Header = ({ title, ogUrl, ogImage, ogDescription }) => {
const Header = ({ title, ogType = "website", ogUrl, ogImage, ogDescription,
ogAuthor, ogDate }) => {
let fullTitle = (title ? title + " | " : "") + "Eclipse Vert.x"
return (
<header>
Expand All @@ -17,11 +18,17 @@ const Header = ({ title, ogUrl, ogImage, ogDescription }) => {
<link rel="alternate" type="application/rss+xml" href="/feed/rss.xml" />
<link rel="alternate" type="application/atom+xml" href="/feed/atom.xml" />
<link rel="alternate" type="application/json" href="/feed/feed.json" />
<meta property="og:type" content="website"/>
<meta property="og:type" content={ogType}/>
<meta property="og:title" content={fullTitle}/>
{ogDescription !== undefined ? (
<meta property="og:description" content={ogDescription} />
): undefined}
) : undefined}
{ogAuthor !== undefined ? (
<meta property="article:author" content={ogAuthor} />
) : undefined}
{ogDate !== undefined ? (
<meta property="article:published_time" content={ogDate} />
) : undefined}
{ogUrl !== undefined ? (
<meta property="og:url" content={ogUrl} />
) : undefined}
Expand Down
2 changes: 1 addition & 1 deletion components/layouts/BlogPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BlogNavBar from "../blog/BlogNavBar"
import styles from "./BlogPost.scss?type=global"

const BlogPost = (props) => (
<Page hashSmoothScroll {...props}>
<Page hashSmoothScroll ogType="article" {...props}>
<div className="blog-post">
<BlogNavBar categories={props.categories} />
{props.children}
Expand Down
6 changes: 4 additions & 2 deletions components/layouts/Page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import Header from "../Header"
import Footer from "../Footer"
import styles from "./Page.scss"

const Layout = ({ title, ogUrl, ogImage, ogDescription, narrow, hashSmoothScroll = false, children }) => {
const Layout = ({ title, ogType, ogUrl, ogImage, ogDescription, ogAuthor, ogDate,
narrow, hashSmoothScroll = false, children }) => {
const navBarState = useContext(NavBarContext.State)
const containerRef = useRef()

Expand Down Expand Up @@ -64,7 +65,8 @@ const Layout = ({ title, ogUrl, ogImage, ogDescription, narrow, hashSmoothScroll

return (
<main className="page">
<Header title={title} ogUrl={ogUrl} ogImage={ogImage} ogDescription={ogDescription} />
<Header title={title} ogType={ogType} ogUrl={ogUrl} ogImage={ogImage}
ogDescription={ogDescription} ogAuthor={ogAuthor} ogDate={ogDate} />
<div className="page-content">
<div className={classNames("container", { "container-narrow": narrow })}
ref={containerRef}>
Expand Down
4 changes: 3 additions & 1 deletion pages/blog/[[...slug]].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,12 @@ const BlogPage = ({ post, prevPost, nextPost, relatedPosts, category, categories

let url = `${process.env.baseUrl}/blog/${post.slug}`
let ogImage = `${process.env.baseUrl}/images/previews/${post.slug}.jpg`
let ogAuthor = post.meta.authors !== undefined ?
post.meta.authors.map(a => a.name).join(", ") : undefined

return (
<BlogPost title={`${post.meta.title} | Blog`} categories={categories} ogUrl={url}
ogImage={ogImage} ogDescription={post.meta.summary}>
ogImage={ogImage} ogDescription={post.meta.summary} ogAuthor={ogAuthor} ogDate={post.date}>
<div className="blog-post-main">
<div className="blog-post-content">
<h1>{post.meta.title}</h1>
Expand Down

0 comments on commit 84bfa7b

Please sign in to comment.