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

SEO #6

Merged
merged 18 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
File renamed without changes
Binary file removed src/images/icons/[email protected]
Binary file not shown.
Binary file removed src/images/icons/icon-76.png
Binary file not shown.
Binary file removed src/images/icons/[email protected]
Binary file not shown.
Binary file removed src/images/icons/[email protected]
Binary file not shown.
Binary file removed src/images/tumblr/pointless-stamp.png
Binary file not shown.
57 changes: 55 additions & 2 deletions src/layouts/Application.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
const { title, themeColors } = Astro.props;
const { title, themeColors, description, metaImage, slug } = Astro.props;

// Get the current path
const currentPath = Astro.url.pathname;
const isHomePage = currentPath === "/";

let rootUrl = '';
let metaImageUrl = '';
let contentUrl = '';
// Default colors
const defaultColors = {
backgroundColor: '#fff',
Expand Down Expand Up @@ -41,6 +43,21 @@ import logoLargeWhite from '../images/svgs/pointless-logo-large--white.svg';
import iconX from '../images/svgs/x.svg?raw';
import '../styles/global.css';
---
{(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was really weird and it even led me to a recent bug report by Henry! Moving this code outside the frontmatter fixed it not wanting to access the env variables.

// meta imports don't work in Astro frontmatter, so we set the root URL and meta image URL here
// Set the root URL based on the environment
rootUrl = import.meta.env.NETLIFY
? import.meta.env.CONTEXT === 'production'
? 'https://pointlesscorp.com/'
: `${import.meta.env.DEPLOY_PRIME_URL}/`
: new URL(Astro.url.origin).toString();

// Set the meta image URL based on the environment
metaImageUrl = metaImage ? `${metaImage}` : `${rootUrl}og.png`;
contentUrl = slug === '/' ? `${rootUrl}` : `${rootUrl}${slug}`;

return null;
})()}

<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
Expand All @@ -49,7 +66,35 @@ import '../styles/global.css';
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="/favicon.png">

<link rel="preconnect" href="//a-us.storyblok.com/">
<link rel="dns-prefetch" href="//a-us.storyblok.com/">
<link rel="preload" as="font" href={`${rootUrl}fonts/FunctionPro-Bold-webfont.woff`} type="font/woff" crossorigin="anonymous">

<!-- HTML Meta Tags -->
<title>{title}</title>
<meta name="description" content={description} />
<link rel="canonical" href={contentUrl} />

<!-- Google / Search Engine Tags -->
<meta itemprop="name" content={title} />
<meta itemprop="description" content={description} />
<meta itemprop="image" content={metaImageUrl} />

<!-- Facebook Meta Tags -->
<meta property="og:url" content={contentUrl} />
<meta property="og:type" content="website" />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={metaImageUrl} />

<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:image" content={metaImageUrl} />
<meta name="twitter:url" content={contentUrl} />
<meta name="twitter:site" content="@pointlesscorp" />
<meta name="twitter:creator" content="@pointlesscorp" />

<style define:vars={finalColors}>
:root {
Expand All @@ -66,6 +111,14 @@ import '../styles/global.css';
</style>
</head>
<body class="antialiased font-base">
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-N3P6MM"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s) as HTMLScriptElement,dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-N3P6MM');</script>

<header class="absolute top-9 left-0 z-20 w-full px-3">
<div class="mx-auto flex max-w-7xl items-center justify-center sm:justify-between">
{currentPath === "/" ? (
Expand Down
4 changes: 3 additions & 1 deletion src/pages/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const themeColors = {
textColor: story.content.textColor?.color,
linkColor: story.content.linkColor?.color,
};

const description = story.content.description.content[0].content[0].text;
---

<Application title={`${story.name} - Pointlesscorp`} themeColors={themeColors}>
<Application title={`${story.name} - Pointlesscorp`} themeColors={themeColors} description={description} metaImage={story.content.logo.filename} slug={slug}>
<StoryblokComponent blok={story.content} name={story.name} projects={projectData.stories} />
</Application>
8 changes: 7 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ const { data: projectData } = await storyblokApi.get('cdn/stories', {

const projects = projectData.stories;
const story = homeData.story;

// Extract text from the aboutText content
const aboutTextString = story.content.aboutText.content
.map(paragraph => paragraph.content
.map(item => item.text)
.join(''));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use flat map here so that there is less nesting.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap

It's a subtle change, but more "flat"

const aboutTextString = story.content.aboutText.content
  .flatMap(paragraph => paragraph.content)
  .map(item => item.text)
  .join('');

---

<Application title="Pointless Corp - The Innovation Lab at Viget">
<Application title="Pointless Corp - The Innovation Lab at Viget" description={aboutTextString} slug="/">
<StoryblokComponent blok={story.content} projects={projects} />
</Application>
4 changes: 2 additions & 2 deletions src/storyblok/Project.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function renderContent(content: any) {
}
---

<article class="px-5 pt-20 project">
<article class="px-5 pt-20 pb-10 project">
<h1 class="sr-only">{name}</h1>

<!-- Project Logo -->
Expand Down Expand Up @@ -186,7 +186,7 @@ function renderContent(content: any) {
)}

<!-- More Projects -->
<section class="mx-auto mt-14 mb-10 max-w-7xl">
<section class="mx-auto mt-14 max-w-7xl">
<h2 class="mb-3 text-center text-4xl uppercase font-functionpro">More Pointless Projects</h2>

<ul class="text-center text-lg uppercase font-functionpro xs:columns-2 md:columns-3">
Expand Down