-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6456802
commit 70bb537
Showing
14 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { z } from 'zod'; | ||
|
||
export const openGraphConfigSchema = z.object({ | ||
siteName: z.string().optional(), | ||
}); | ||
|
||
export const facebookConfigSchema = z.object({ | ||
appId: z.string().optional(), | ||
}); | ||
|
||
export const twitterConfigSchema = z.object({ | ||
creator: z.string().optional(), | ||
site: z.string().optional(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getFacebookObjects } from './facebook'; | ||
import { getConfig } from '@galactiks/config'; | ||
|
||
jest.mock('@galactiks/config'); | ||
|
||
describe('getFacebookObjects', () => { | ||
it('should return an empty array if facebook config is not present', () => { | ||
(getConfig as jest.Mock).mockReturnValue({}); | ||
|
||
const result = getFacebookObjects(); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should return an array with fb:app_id if facebook appId is present', () => { | ||
const mockAppId = '1234567890'; | ||
(getConfig as jest.Mock).mockReturnValue({ facebook: { appId: mockAppId } }); | ||
|
||
const result = getFacebookObjects(); | ||
|
||
expect(result).toEqual([{ property: 'fb:app_id', content: mockAppId }]); | ||
}); | ||
|
||
it('should return an empty array if facebook config is present but appId is not', () => { | ||
(getConfig as jest.Mock).mockReturnValue({ facebook: {} }); | ||
|
||
const result = getFacebookObjects(); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getConfig } from '@galactiks/config'; | ||
import type { MetadataHeaders } from '../../types/index.js'; | ||
|
||
export const getFacebookObjects = (): MetadataHeaders['facebook'] => { | ||
const { facebook } = getConfig(); | ||
const headers = []; | ||
if (facebook?.appId) { | ||
headers.push({ property: 'fb:app_id', content: facebook.appId }); | ||
} | ||
|
||
return headers; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import { getConfig } from '@galactiks/config'; | ||
import type { Content, MetadataHeaders } from '../../../types/index.js'; | ||
|
||
import { getArticle } from './article.js'; | ||
import { getWebsite } from './website.js'; | ||
|
||
export const getOpenGraphObjects = ( | ||
document: Content | ||
): MetadataHeaders['openGraph'] => { | ||
const getOpenGraphByType = (document: Content): MetadataHeaders['openGraph'] => { | ||
if (document.type === 'Article') { | ||
return getArticle(document); | ||
} | ||
|
||
return getWebsite(document); | ||
} | ||
|
||
export const getOpenGraphObjects = ( | ||
document: Content | ||
): MetadataHeaders['openGraph'] => { | ||
const headers = getOpenGraphByType(document) || []; | ||
|
||
const { webManifest, openGraph } = getConfig(); | ||
const siteName = openGraph?.siteName || webManifest?.name; | ||
if (siteName) { | ||
headers.push({ property: 'og:siteName', content: siteName }); | ||
} | ||
|
||
return headers; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
"cache": false | ||
}, | ||
"test": { | ||
"dependsOn": ["^build"], | ||
"outputLogs": "new-only" | ||
} | ||
} | ||
|