-
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
Showing
2 changed files
with
8 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,8 @@ | ||
import type { FetchWebsite, LoaderUrls } from '@starnexus/core' | ||
import { getDomain } from '@starnexus/core' | ||
import { getWebsiteInfo as getInfo } from '../../core/src/website' | ||
import { routes } from '../src/routes-auto-generate' | ||
|
||
export async function getWebsiteInfo(urls: LoaderUrls, header?: Record<string, string>): Promise<FetchWebsite> { | ||
let info: FetchWebsite = { error: 'StarNexus error: Not supported website.' } | ||
const domain = getDomain(urls.webUrl) | ||
|
||
if (routes[domain]) { | ||
const router = routes[domain] | ||
if (router.paths) { | ||
for (let i = 0; i < router.paths.length; i++) { | ||
const pathInfo = router.paths[i] | ||
const loaderUrls = pathInfo.filter(urls) | ||
if (loaderUrls) { | ||
info = await pathInfo.loader(loaderUrls, header) | ||
if (info.data) { | ||
info.data.meta.domain = domain | ||
info.data.meta.website = router.name | ||
} | ||
|
||
return info | ||
} | ||
} | ||
} | ||
return { error: `${router.name} error: Not supported website.` } | ||
} | ||
export async function getWebsiteInfo(url: string) { | ||
const info = await getInfo({ webUrl: url }, routes) | ||
|
||
return info | ||
} |