Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix open graph url verification + add more info #815

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

Draft
ianhi wants to merge 3 commits into xarray-contrib:main
base: main
Choose a base branch
Loading
from ianhi:ian/open-graph
Draft
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
8 changes: 2 additions & 6 deletions netlify.toml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
status = 404

# Environment variables for different deploy contexts
# Note: Netlify automatically provides URL and DEPLOY_PRIME_URL
# We don't need to set NEXT_PUBLIC_SITE_URL for previews since our code falls back to process.env.URL
[context.production.environment]
NEXT_PUBLIC_SITE_URL = "https://xarray.dev"

[context.deploy-preview.environment]
NEXT_PUBLIC_SITE_URL = "$DEPLOY_PRIME_URL"

[context.branch-deploy.environment]
NEXT_PUBLIC_SITE_URL = "$DEPLOY_PRIME_URL"

# Headers for security
[[headers]]
for = "/*"
Expand Down
33 changes: 32 additions & 1 deletion src/components/layout.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const Layout = ({
children,
url = 'https://xarray.dev',
enableBanner = false,
type = 'website',
imageWidth,
imageHeight,
publishedTime,
authors,
}) => {
const bannerTitle = 'Check out the latest blog post:'
// The first link will be the main description for the banner
Expand Down Expand Up @@ -39,8 +44,16 @@ export const Layout = ({
? process.env.NEXT_PUBLIC_SITE_URL
: process.env.URL || 'http://localhost:3000'

// Canonical URL always points to production for SEO
const canonicalBaseUrl = 'https://xarray.dev'
const canonicalUrl = url.startsWith('http')
? url
: `${canonicalBaseUrl}${url}`

// Construct the full card URL
const fullCardUrl = card.startsWith('http') ? card : `${baseUrl}${card}`
// Construct the full URL for og:url (can use preview URL)
const fullUrl = url.startsWith('http') ? url : `${baseUrl}${url}`

return (
<>
Expand All @@ -50,12 +63,30 @@ export const Layout = ({
<meta property='og:title' content={title} />
<meta property='og:description' content={description} />
<meta property='og:image' content={fullCardUrl} />
<meta property='og:url' content={url} />
{imageWidth && <meta property='og:image:width' content={imageWidth} />}
{imageHeight && (
<meta property='og:image:height' content={imageHeight} />
)}
<meta property='og:url' content={fullUrl} />
<meta property='og:type' content={type} />
{type === 'article' && publishedTime && (
<meta property='article:published_time' content={publishedTime} />
)}
{type === 'article' &&
authors &&
authors.map((author) => (
<meta
key={author.github}
property='article:author'
content={`https://github.com/${author.github}`}
/>
))}
<meta name='twitter:title' content={title} />
<meta name='twitter:description' content={description} />
<meta name='twitter:image' content={fullCardUrl} />
<meta name='twitter:card' content='summary_large_image' />
<meta name='twitter:site' content='@xarray_dev' />
<link rel='canonical' href={canonicalUrl} />
<link
rel='icon'
type='image/png'
Expand Down
5 changes: 5 additions & 0 deletions src/pages/blog/[id].js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default function Post({ source, frontmatter, postId }) {
card={`/cards/${postId}.png`}
description={frontmatter.summary}
url={`/blog/${postId}`}
type='article'
imageWidth='2560'
imageHeight='1440'
publishedTime={date.toISOString()}
authors={frontmatter.authors}
>
<Box as={'section'}>
<Container maxW='container.lg' py={10}>
Expand Down

AltStyle によって変換されたページ (->オリジナル) /