Skip to content

Commit

Permalink
Seo (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholeuf authored Feb 18, 2024
1 parent 4fcdf9d commit fe8cb52
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 5 deletions.
1 change: 0 additions & 1 deletion .env.test

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "18.x"
cache: "yarn"
node-version: '18.x'
cache: 'yarn'
- run: yarn install --immutable
- run: yarn test
- name: Run Tests
env:
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME: ${{ secrets.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME }}
NEXT_PUBLIC_SITE_URL: ${{ secrets.NEXT_PUBLIC_SITE_URL }}
run: yarn test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ yarn-error.log*

# local env files
.env*.local
.env*.test

# vercel
.vercel
Expand Down
18 changes: 17 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import { Metadata } from 'next';
import { AppRouterCacheProvider } from '@mui/material-nextjs/v14-appRouter';
import { getCldOgImageUrl } from 'next-cloudinary';

import AppLayout from '@/components/AppLayout';
import getBaseUrl from '@/app/lib/getBaseUrl';

export const metadata: Metadata = {
title: {
template: '%s | Nichole Frey',
// a default is required when creating a template
default: 'Nichole Frey',
},
description: 'Full-Stack Web Developer located in Central Florida',
description:
'Portfolio website for Nichole Frey, a Full-Stack Developer based in Orlando, FL',

generator: 'Next.js',
applicationName: 'Nichole Frey | Full-Stack Developer',
Expand All @@ -28,6 +31,19 @@ export const metadata: Metadata = {
authors: [{ name: 'Nichole Frey' }],
creator: 'Nichole Frey',
publisher: 'Nichole Frey',
openGraph: {
url: getBaseUrl(),
images: [
{
width: 1200,
height: 627,
url: getCldOgImageUrl({
src: 'zensite/og-image',
crop: 'scale',
}),
},
],
},
};

interface RootLayoutProps {
Expand Down
7 changes: 7 additions & 0 deletions src/app/lib/getBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getBaseUrl = () => {
// TODO: Determine why VERCEL_URL is not working in vercel deployment
// https://github.com/nicholeuf/zen-site-next/issues/18
return process.env.NEXT_PUBLIC_SITE_URL;
};

export default getBaseUrl;
4 changes: 4 additions & 0 deletions src/app/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ const routes = {
home: {
href: '/',
name: 'Home',
priority: 1,
},
about: {
href: '/about',
name: 'About',
priority: 0.8,
},
work: {
href: '/work',
name: 'Work',
priority: 0.8,
},
contact: {
href: '/contact',
name: 'Contact',
priority: 0.5,
},
};

Expand Down
14 changes: 14 additions & 0 deletions src/app/robots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import robots from './robots';

describe('The robots file', () => {
test('generates as expected', () => {
const output = robots();
expect(output).toEqual({
rules: {
userAgent: '*',
allow: '/',
},
sitemap: `${process.env.NEXT_PUBLIC_SITE_URL}/sitemap.xml`,
});
});
});
15 changes: 15 additions & 0 deletions src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MetadataRoute } from 'next';

import getBaseUrl from '@/app/lib/getBaseUrl';

const robots = (): MetadataRoute.Robots => {
return {
rules: {
userAgent: '*',
allow: '/',
},
sitemap: new URL('sitemap.xml', getBaseUrl()).toString(),
};
};

export default robots;
34 changes: 34 additions & 0 deletions src/app/sitemap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sitemap from './sitemap';

describe('The sitemap file', () => {
test('generates as expected', () => {
const output = sitemap();
expect(output).toMatchObject([
{
url: `${process.env.NEXT_PUBLIC_SITE_URL}/`,
lastModified: expect.any(Date),
changeFrequency: 'always',
priority: expect.any(Number),
},
{
url: `${process.env.NEXT_PUBLIC_SITE_URL}/about`,
lastModified: expect.any(Date),
changeFrequency: 'always',
priority: expect.any(Number),
},

{
url: `${process.env.NEXT_PUBLIC_SITE_URL}/work`,
lastModified: expect.any(Date),
changeFrequency: 'always',
priority: expect.any(Number),
},
{
url: `${process.env.NEXT_PUBLIC_SITE_URL}/contact`,
lastModified: expect.any(Date),
changeFrequency: 'always',
priority: expect.any(Number),
},
]);
});
});
16 changes: 16 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MetadataRoute } from 'next';
import routes from '@/app/lib/routes';
import getBaseUrl from '@/app/lib/getBaseUrl';

const sitemap = (): MetadataRoute.Sitemap => {
return Object.values(routes).map((route) => {
return {
url: new URL(route.href, getBaseUrl()).toString(),
lastModified: new Date(),
changeFrequency: 'always',
priority: route.priority,
};
});
};

export default sitemap;
4 changes: 4 additions & 0 deletions versel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cleanUrls": true,
"trailingSlash": true
}

1 comment on commit fe8cb52

@vercel
Copy link

@vercel vercel bot commented on fe8cb52 Feb 18, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.