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

Improve the Open Graph tags for Twitter/X #17

Merged
merged 18 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5498cc9
Try to improve the Open Graph tags specificaly for twitter (use `name…
conradolandia Sep 20, 2024
e257abe
Change metadata setting process a little bit, and add some more metad…
conradolandia Sep 20, 2024
fd25e41
Replace big pngs with small size webps to see if this improves the si…
conradolandia Sep 20, 2024
4f53b53
Try again with jpg files
conradolandia Sep 20, 2024
76b8ff1
Try again with png files
conradolandia Sep 20, 2024
3984929
Try a different method to get the URL for OG assets, since a cross-do…
conradolandia Sep 20, 2024
ed755f9
Try another solution to check out in netlify's preview
conradolandia Sep 23, 2024
1ec5af0
Try another variation
conradolandia Sep 23, 2024
f797c1d
Restore indentation to 2 spaces in files affected by editor change
conradolandia Sep 23, 2024
2c89bd3
Move metadata logic from the main layout to each page and implement a…
conradolandia Sep 25, 2024
04b5435
Add metadata to blog pages (blog/1, blog/2, etc)
conradolandia Sep 25, 2024
0a64c78
Add preliminar support for OG metadata to individual blog posts
conradolandia Sep 25, 2024
99d5e70
Try a different method to set metadata in blog posts
conradolandia Sep 25, 2024
b9a8079
Try to use the first post image as OG for now as a test
conradolandia Sep 25, 2024
dbdbd31
Try a different method to set the metadata
conradolandia Sep 25, 2024
f0523ea
Revert to the old method
conradolandia Sep 25, 2024
0b18327
Improve a bit the component's readability
conradolandia Sep 25, 2024
24c9bfd
Updated some packages in package-lock.json
conradolandia Sep 25, 2024
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
134 changes: 67 additions & 67 deletions package-lock.json

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

69 changes: 44 additions & 25 deletions src/lib/blocks/Blog.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<script>
import { base } from "$app/paths";
import { page } from "$app/stores";
import { browser } from "$app/environment";
import { metadata } from "$lib/store";
import { formattedPubDate, fetchAuthorMetadata } from "$lib/utils";

import Loader from "$lib/components/Loader.svelte";
import Pagination from "$lib/components/Pagination.svelte";

import {
socials,
siteUrl,
title as siteTitle,
author as siteAuthor,
Expand All @@ -13,46 +17,55 @@
keywords as blogKeywords,
} from "$lib/config";

import Loader from "$lib/components/Loader.svelte";
import Pagination from "$lib/components/Pagination.svelte";

export let data, pageNum, totalPages;

$: ({ posts, pageNum, totalPages } = data.props);
$: route = "blog";
const route = "blog";
const url = `${siteUrl}${route}`;
const site = `@${socials.twitter.split("/").pop()}`;

let postsWithAuthor = [];

$: if (posts) {
postsWithAuthor = Promise.all(posts.map(async (post) => {
if (typeof window !== "undefined") {
const authorMetadata = await fetchAuthorMetadata(post.meta.author);
return { ...post, authorMetadata };
}
return post;
}));
}

$: url = $page.url.href;
$: fullImageUrl = `${siteUrl}/assets/media/blog_screenshot.png`;
$: image = data.image || "assets/media/blog_screenshot.png";
$: fullImageUrl = image.startsWith("http") ? image : `${siteUrl}${image}`;

$: metadata.setMetadata({
title: `${siteTitle} | ${blogTitle}`,
description: blogDescription,
keywords: blogKeywords.join(", "),
author: siteAuthor,
image: fullImageUrl,
site,
url,
image: fullImageUrl
});

$: ({ posts, pageNum, totalPages } = data.props);
$: if (posts) {
postsWithAuthor = Promise.all(
posts.map(async (post) => {
if (browser) {
const authorMetadata = await fetchAuthorMetadata(post.meta.author);
return { ...post, authorMetadata };
}
return post;
}),
);
}
</script>

<svelte:head>
<link rel="canonical" href={url} />
<link rel="alternate" type="application/rss+xml" title="Spyder's Blog" href="{url}/feed.xml">
<link rel="canonical" href={siteUrl} />
<link
rel="alternate"
type="application/rss+xml"
title="Spyder's Blog"
href="{siteUrl}feed.xml"
/>
</svelte:head>

<div class="container">
<h1 class="text-4xl xl:tracking-tight xl:text-6xl text-center tracking-tight font-extralight text-mine-shaft-600 dark:text-mine-shaft-200 my-16 md:my-32">
<h1
class="text-4xl xl:tracking-tight xl:text-6xl text-center tracking-tight font-extralight text-mine-shaft-600 dark:text-mine-shaft-200 my-16 md:my-32"
>
{blogTitle}
</h1>

Expand All @@ -64,7 +77,11 @@
{#each loadedPosts as post}
<article>
<h2 class="text-xl md:text-2xl xl:text-3xl font-light">
<a class="post-link" href="{base}/{route}/{post.path}" title={post.meta.title}>
<a
class="post-link"
href="{base}/{route}/{post.path}"
title={post.meta.title}
>
{post.meta.title}
</a>
</h2>
Expand All @@ -83,7 +100,9 @@
</div>
</div>
{/if}
<p class="text-gray-700 dark:text-gray-300 font-light">{post.meta.summary}</p>
<p class="text-gray-700 dark:text-gray-300 font-light">
{post.meta.summary}
</p>
<a
class="block text-right mt-4"
href="{base}/{route}/{post.path}"
Expand All @@ -99,4 +118,4 @@
<p>Error loading posts: {error.message}</p>
{/await}
</section>
</div>
</div>
Loading