-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
β»οΈ refactor: refactor the sitemap implement (#4012)
* β¨ feat: Add new sitemap * π fix: Fix url * β test: Add test * π fix: Fix host * β test: Fix test * β test: Fix test * π fix: Fix alternative * π fix: Try to fix * π fix: Fix build * π fix: Fix build * π§ chore: Update git ignore * π fix: Fix review problem
- Loading branch information
1 parent
5bd773e
commit d93a161
Showing
28 changed files
with
964 additions
and
81 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 was deleted.
Oops, something went wrong.
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,12 @@ | ||
import { writeFileSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import { sitemapModule } from '@/server/sitemap'; | ||
|
||
const genSitemap = () => { | ||
const sitemapIndexXML = sitemapModule.getIndex(); | ||
const filename = resolve(__dirname, '../../', 'public', 'sitemap-index.xml'); | ||
writeFileSync(filename, sitemapIndexXML); | ||
}; | ||
|
||
genSitemap(); |
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
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,16 @@ | ||
import { MetadataRoute } from 'next'; | ||
|
||
import { sitemapModule } from '@/server/sitemap'; | ||
import { getCanonicalUrl } from '@/server/utils/url'; | ||
|
||
export default function robots(): MetadataRoute.Robots { | ||
return { | ||
host: getCanonicalUrl(), | ||
rules: { | ||
allow: ['/'], | ||
disallow: ['/api/*'], | ||
userAgent: '*', | ||
}, | ||
sitemap: sitemapModule.getRobots(), | ||
}; | ||
} |
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,30 @@ | ||
import { MetadataRoute } from 'next'; | ||
|
||
import { SitemapType, sitemapModule } from '@/server/sitemap'; | ||
|
||
export const generateSitemaps = async () => { | ||
// Fetch the total number of products and calculate the number of sitemaps needed | ||
return sitemapModule.sitemapIndexs; | ||
}; | ||
|
||
const Sitemap = async ({ id }: { id: SitemapType }): Promise<MetadataRoute.Sitemap> => { | ||
switch (id) { | ||
case SitemapType.Pages: { | ||
return sitemapModule.getPage(); | ||
} | ||
case SitemapType.Assistants: { | ||
return sitemapModule.getAssistants(); | ||
} | ||
case SitemapType.Plugins: { | ||
return sitemapModule.getPlugins(); | ||
} | ||
case SitemapType.Models: { | ||
return sitemapModule.getModels(); | ||
} | ||
case SitemapType.Providers: { | ||
return sitemapModule.getProviders(); | ||
} | ||
} | ||
}; | ||
|
||
export default Sitemap; |
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,102 @@ | ||
// @vitest-environment node | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { DEFAULT_LANG } from '@/const/locale'; | ||
|
||
import { AUTHOR_LIST, Ld } from './ld'; | ||
|
||
describe('Ld', () => { | ||
const ld = new Ld(); | ||
|
||
describe('generate', () => { | ||
it('should generate correct LD+JSON structure', () => { | ||
const result = ld.generate({ | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
url: 'https://example.com/test', | ||
locale: DEFAULT_LANG, | ||
}); | ||
|
||
expect(result['@context']).toBe('https://schema.org'); | ||
expect(Array.isArray(result['@graph'])).toBe(true); | ||
expect(result['@graph'].length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
|
||
describe('genOrganization', () => { | ||
it('should generate correct organization structure', () => { | ||
const org = ld.genOrganization(); | ||
|
||
expect(org['@type']).toBe('Organization'); | ||
expect(org.name).toBe('LobeHub'); | ||
expect(org.url).toBe('https://lobehub.com/'); | ||
}); | ||
}); | ||
|
||
describe('getAuthors', () => { | ||
it('should return default author when no ids provided', () => { | ||
const author = ld.getAuthors(); | ||
expect(author['@type']).toBe('Organization'); | ||
}); | ||
|
||
it('should return person when valid id provided', () => { | ||
const author = ld.getAuthors(['arvinxx']); | ||
expect(author['@type']).toBe('Person'); | ||
// @ts-ignore | ||
expect(author.name).toBe(AUTHOR_LIST.arvinxx.name); | ||
}); | ||
}); | ||
|
||
describe('genWebPage', () => { | ||
it('should generate correct webpage structure', () => { | ||
const webpage = ld.genWebPage({ | ||
title: 'Test Page', | ||
description: 'Test Description', | ||
url: 'https://example.com/test', | ||
locale: DEFAULT_LANG, | ||
}); | ||
|
||
expect(webpage['@type']).toBe('WebPage'); | ||
expect(webpage.name).toBe('Test Page Β· LobeChat'); | ||
expect(webpage.description).toBe('Test Description'); | ||
}); | ||
}); | ||
|
||
describe('genImageObject', () => { | ||
it('should generate correct image object', () => { | ||
const image = ld.genImageObject({ | ||
image: 'https://example.com/image.jpg', | ||
url: 'https://example.com/test', | ||
}); | ||
|
||
expect(image['@type']).toBe('ImageObject'); | ||
expect(image.url).toBe('https://example.com/image.jpg'); | ||
}); | ||
}); | ||
|
||
describe('genWebSite', () => { | ||
it('should generate correct website structure', () => { | ||
const website = ld.genWebSite(); | ||
|
||
expect(website['@type']).toBe('WebSite'); | ||
expect(website.name).toBe('LobeChat'); | ||
}); | ||
}); | ||
|
||
describe('genArticle', () => { | ||
it('should generate correct article structure', () => { | ||
const article = ld.genArticle({ | ||
title: 'Test Article', | ||
description: 'Test Description', | ||
url: 'https://example.com/test', | ||
author: ['arvinxx'], | ||
identifier: 'test-id', | ||
locale: DEFAULT_LANG, | ||
}); | ||
|
||
expect(article['@type']).toBe('Article'); | ||
expect(article.headline).toBe('Test Article Β· LobeChat'); | ||
expect(article.author['@type']).toBe('Person'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.