Skip to content

Commit

Permalink
feat(templates): add new favicons and og images to website template (#…
Browse files Browse the repository at this point in the history
…9716)

Add new favicons to match payload's new logo and new OG images and OG
image sizes to the website template.
  • Loading branch information
paulpopus authored Dec 3, 2024
1 parent fd9a007 commit 1bd689b
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 32 deletions.
Binary file modified templates/website/public/favicon.ico
Binary file not shown.
28 changes: 18 additions & 10 deletions templates/website/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified templates/website/public/website-template-OG.webp
Binary file not shown.
7 changes: 7 additions & 0 deletions templates/website/src/collections/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const Media: CollectionConfig = {
// Upload to the public/media directory in Next.js making them publicly accessible even outside of Payload
staticDir: path.resolve(dirname, '../../public/media'),
adminThumbnail: 'thumbnail',
focalPoint: true,
imageSizes: [
{
name: 'thumbnail',
Expand All @@ -68,6 +69,12 @@ export const Media: CollectionConfig = {
name: 'xlarge',
width: 1920,
},
{
name: 'og',
width: 1200,
height: 630,
crop: 'center',
},
],
},
}
18 changes: 18 additions & 0 deletions templates/website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ export interface Media {
filesize?: number | null;
filename?: string | null;
};
og?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
};
}
/**
Expand Down Expand Up @@ -996,6 +1004,16 @@ export interface MediaSelect<T extends boolean = true> {
filesize?: T;
filename?: T;
};
og?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
};
}
/**
Expand Down
22 changes: 16 additions & 6 deletions templates/website/src/utilities/generateMeta.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import type { Metadata } from 'next'

import type { Page, Post } from '../payload-types'
import type { Media, Page, Post, Config } from '../payload-types'

import { mergeOpenGraph } from './mergeOpenGraph'
import { getServerSideURL } from './getURL'

const getImageURL = (image?: Media | Config['db']['defaultIDType'] | null) => {
const serverUrl = getServerSideURL()

let url = serverUrl + '/website-template-OG.webp'

if (image && typeof image === 'object' && 'url' in image) {
const ogUrl = image.sizes?.og?.url

url = ogUrl ? serverUrl + ogUrl : serverUrl + image.url
}

return url
}

export const generateMeta = async (args: {
doc: Partial<Page> | Partial<Post>
}): Promise<Metadata> => {
const { doc } = args || {}

const ogImage =
typeof doc?.meta?.image === 'object' &&
doc.meta.image !== null &&
'url' in doc.meta.image &&
`${getServerSideURL()}`
const ogImage = getImageURL(doc?.meta?.image)

const title = doc?.meta?.title
? doc?.meta?.title + ' | Payload Website Template'
Expand Down
Binary file modified templates/with-vercel-website/public/favicon.ico
Binary file not shown.
28 changes: 18 additions & 10 deletions templates/with-vercel-website/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified templates/with-vercel-website/public/website-template-OG.webp
Binary file not shown.
7 changes: 7 additions & 0 deletions templates/with-vercel-website/src/collections/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const Media: CollectionConfig = {
// Upload to the public/media directory in Next.js making them publicly accessible even outside of Payload
staticDir: path.resolve(dirname, '../../public/media'),
adminThumbnail: 'thumbnail',
focalPoint: true,
imageSizes: [
{
name: 'thumbnail',
Expand All @@ -68,6 +69,12 @@ export const Media: CollectionConfig = {
name: 'xlarge',
width: 1920,
},
{
name: 'og',
width: 1200,
height: 630,
crop: 'center',
},
],
},
}
18 changes: 18 additions & 0 deletions templates/with-vercel-website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ export interface Media {
filesize?: number | null;
filename?: string | null;
};
og?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
};
}
/**
Expand Down Expand Up @@ -996,6 +1004,16 @@ export interface MediaSelect<T extends boolean = true> {
filesize?: T;
filename?: T;
};
og?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
};
}
/**
Expand Down
22 changes: 16 additions & 6 deletions templates/with-vercel-website/src/utilities/generateMeta.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import type { Metadata } from 'next'

import type { Page, Post } from '../payload-types'
import type { Media, Page, Post, Config } from '../payload-types'

import { mergeOpenGraph } from './mergeOpenGraph'
import { getServerSideURL } from './getURL'

const getImageURL = (image?: Media | Config['db']['defaultIDType'] | null) => {
const serverUrl = getServerSideURL()

let url = serverUrl + '/website-template-OG.webp'

if (image && typeof image === 'object' && 'url' in image) {
const ogUrl = image.sizes?.og?.url

url = ogUrl ? serverUrl + ogUrl : serverUrl + image.url
}

return url
}

export const generateMeta = async (args: {
doc: Partial<Page> | Partial<Post>
}): Promise<Metadata> => {
const { doc } = args || {}

const ogImage =
typeof doc?.meta?.image === 'object' &&
doc.meta.image !== null &&
'url' in doc.meta.image &&
`${getServerSideURL()}`
const ogImage = getImageURL(doc?.meta?.image)

const title = doc?.meta?.title
? doc?.meta?.title + ' | Payload Website Template'
Expand Down

0 comments on commit 1bd689b

Please sign in to comment.