-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #69: Rename url to path and do not prefix with baseUrl
Fix #72 Move sitemap field under portalSite Content ObjectType Fix #73: sitemap should return null in Guillotine when the app is not installed on the nearest site
- Loading branch information
1 parent
1104f6a
commit d3eb8b9
Showing
12 changed files
with
356 additions
and
243 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const DEBUG = false; | ||
export const TRACE = false; | ||
// const PROFILING = false; | ||
|
||
// In type names first letter should be uppercase | ||
export const enum GraphQLTypeName { | ||
SITEMAP = 'Sitemap', | ||
SITEMAP_URL = 'Sitemap_Url', | ||
} | ||
|
||
// In fields names first letter should be lowercase | ||
export const SITEMAP_FIELD_NAME = 'sitemap'; | ||
export const URLSET_FIELD_NAME = 'urlset'; |
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,9 @@ | ||
export declare interface SiteMapResolverData { | ||
baseUrl: string|null | ||
} | ||
|
||
export declare interface SiteMapResolverLocaleContext { | ||
siteJson: string | ||
siteConfigJson: string | ||
[x: string]: string | ||
} |
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,94 @@ | ||
import type {Site} from '@enonic-types/lib-content'; | ||
import type { | ||
DataFetcherResult, | ||
GraphQL, | ||
Resolver, | ||
} from '@enonic-types/guillotine'; | ||
import type { | ||
SiteMapResolverData, | ||
SiteMapResolverLocaleContext | ||
} from '/guillotine/guillotine.d'; | ||
import type { | ||
SitemapXmlSiteConfig, | ||
// tChangeFreq, | ||
// tPriority, | ||
} from '/types'; | ||
|
||
import {get as getContentByKey} from '/lib/xp/content'; | ||
import { | ||
get as getContext, | ||
run as runInContext | ||
} from '/lib/xp/context'; | ||
// import { | ||
// DEFAULT_PRIORITY, | ||
// DEFAULT_UPDATE_PERIOD | ||
// } from '/lib/app-sitemapxml/constants'; | ||
import { | ||
// DEBUG, | ||
SITEMAP_FIELD_NAME, | ||
TRACE, | ||
} from '/guillotine/constants'; | ||
import {getSiteConfigFromSite} from '/guillotine/getSiteConfigFromSite'; | ||
|
||
|
||
export const buildSitemapResolver = (graphQL: GraphQL): Resolver< | ||
{}, // args | ||
{}, // localContext | ||
Site<SitemapXmlSiteConfig>, | ||
DataFetcherResult<SiteMapResolverData,SiteMapResolverLocaleContext>|null | ||
> => (env) => { | ||
TRACE && log.debug(`resolvers ${SITEMAP_FIELD_NAME} env: ${JSON.stringify(env, null, 4)}`); | ||
const { | ||
// args, | ||
localContext, | ||
source: siteWithoutSiteConfig | ||
} = env; | ||
TRACE && log.debug(`resolvers ${SITEMAP_FIELD_NAME} siteWithoutSiteConfig: ${JSON.stringify(siteWithoutSiteConfig, null, 4)}`); | ||
|
||
const { | ||
branch, | ||
project, | ||
// siteKey // NOTE: Can be undefined when x-guillotine-sitekey is missing | ||
} = localContext; | ||
// TRACE && log.debug(`resolvers ${SITEMAP_FIELD_NAME} siteKey: ${siteKey}`); | ||
// if (!siteKey) { | ||
// return null; | ||
// } | ||
const context = getContext(); | ||
const { | ||
authInfo: { | ||
principals = [] // Handle undefined | ||
} = {} | ||
} = context; | ||
return runInContext({ | ||
branch, | ||
repository: `com.enonic.cms.${project}`, | ||
principals: principals || [] // Handle null | ||
}, () => { | ||
const site = getContentByKey<Site<SitemapXmlSiteConfig>>({key: siteWithoutSiteConfig._path}); | ||
TRACE && log.debug(`resolvers ${SITEMAP_FIELD_NAME} site: ${JSON.stringify(site, null, 4)}`); | ||
const siteConfig = getSiteConfigFromSite({ | ||
applicationKey: app.name, | ||
site: site as Site<SitemapXmlSiteConfig>, | ||
}); | ||
if (!siteConfig) { | ||
return null; | ||
} | ||
const { | ||
overrideDomain: baseUrl = null | ||
} = siteConfig || {}; | ||
return graphQL.createDataFetcherResult< | ||
SiteMapResolverData, | ||
SiteMapResolverLocaleContext | ||
>({ | ||
data: __.toScriptValue<SiteMapResolverData>({ | ||
baseUrl, | ||
}), | ||
localContext: { | ||
siteJson: JSON.stringify(site), | ||
siteConfigJson: JSON.stringify(siteConfig), | ||
}, | ||
parentLocalContext: localContext, | ||
}); | ||
}); // runInContext | ||
}; |
Oops, something went wrong.