Skip to content

Commit

Permalink
Merge pull request #47 from supproduction/bugix/cc-34208-cms-pages
Browse files Browse the repository at this point in the history
feat: cms content
  • Loading branch information
tolerants authored Sep 9, 2024
2 parents 70366d8 + 18556df commit fc94309
Show file tree
Hide file tree
Showing 27 changed files with 171 additions and 397 deletions.
3 changes: 2 additions & 1 deletion libs/domain/content/link/link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export class ContentLinkComponent extends ContentMixin<

protected $link = computed(() => {
const { url, type, id, qualifier, params } = this.$options();

if (url) return of(url);
if (type)
return this.semanticLinkService.get({
type: type,
type,
id,
qualifier,
params,
Expand Down
1 change: 1 addition & 0 deletions libs/domain/content/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './feature';
export * from './models';
export * from './resolvers';
export * from './services';
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// TODO: create dynamic types and dependable dynamic pages.
export const cmsTypes = ['article', 'faq', 'about'];

declare global {
interface ContentFields {
article: undefined;
about: undefined;
faq: undefined;
about: undefined;
}
}

export interface ArticleContent {
export interface CmsContent {
heading: string;
description: string;
content: string;
type: string;
[key: string]: unknown;
}
3 changes: 3 additions & 0 deletions libs/domain/content/src/models/content.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
declare global {
interface ContentFields {
/**
* Page or component config. // ExperienceComponent
*/
component: undefined;
}
}
Expand Down
1 change: 1 addition & 0 deletions libs/domain/content/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './cms.model';
export * from './content.model';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
ContentContext,
ContentQualifier,
ContentService,
} from '@oryx-frontend/content';
import {
ContextService,
ElementResolver,
Expand All @@ -11,9 +6,10 @@ import {
import { inject } from '@oryx-frontend/di';
import { RouterService } from '@oryx-frontend/router';
import { Observable, combineLatest, map, of, switchMap } from 'rxjs';
import { ArticleContent } from '../article.model';
import { CmsContent, ContentQualifier } from '../models';
import { ContentContext, ContentService } from '../services';

export class ArticlePageDescriptionMetaResolver implements PageMetaResolver {
export class CmsPageDescriptionMetaResolver implements PageMetaResolver {
constructor(
protected context = inject(ContextService),
protected content = inject(ContentService),
Expand All @@ -26,7 +22,11 @@ export class ArticlePageDescriptionMetaResolver implements PageMetaResolver {
combineLatest([
this.context.get(null, ContentContext.Content),
this.router.currentRoute(),
]).pipe(map(([type, route]) => route.includes(`/${type}/`))),
]).pipe(
map(([qualifier, route]) =>
route.includes(`/${qualifier?.type}/${qualifier?.id}`)
)
),
]);
}

Expand All @@ -41,7 +41,7 @@ export class ArticlePageDescriptionMetaResolver implements PageMetaResolver {
if (!id || !type) return of({});

return this.content
.get<ArticleContent>({
.get<CmsContent>({
id,
type,
entities: [type],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
ContentContext,
ContentQualifier,
ContentService,
} from '@oryx-frontend/content';
import {
ContextService,
ElementResolver,
Expand All @@ -11,9 +6,10 @@ import {
import { inject } from '@oryx-frontend/di';
import { RouterService } from '@oryx-frontend/router';
import { Observable, combineLatest, map, of, switchMap } from 'rxjs';
import { ArticleContent } from '../article.model';
import { CmsContent, ContentQualifier } from '../models';
import { ContentContext, ContentService } from '../services';

export class ArticlePageTitleMetaResolver implements PageMetaResolver {
export class CmsPageTitleMetaResolver implements PageMetaResolver {
constructor(
protected context = inject(ContextService),
protected router = inject(RouterService),
Expand All @@ -26,7 +22,11 @@ export class ArticlePageTitleMetaResolver implements PageMetaResolver {
combineLatest([
this.context.get(null, ContentContext.Content),
this.router.currentRoute(),
]).pipe(map(([type, route]) => route.includes(`/${type}/`))),
]).pipe(
map(([qualifier, route]) =>
route.includes(`/${qualifier?.type}/${qualifier?.id}`)
)
),
]);
}

Expand All @@ -41,7 +41,7 @@ export class ArticlePageTitleMetaResolver implements PageMetaResolver {
if (!id || !type) return of({});

return this.content
.get<ArticleContent>({
.get<CmsContent>({
id,
type,
entities: [type],
Expand Down
2 changes: 2 additions & 0 deletions libs/domain/content/src/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './cms-page-description-meta.resolver';
export * from './cms-page-title-meta.resolver';
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ContentContext } from '@oryx-frontend/content';
import { ContextFallback } from '@oryx-frontend/core';
import { inject, Provider } from '@oryx-frontend/di';
import { RouterService } from '@oryx-frontend/router';
import { combineLatest, map } from 'rxjs';
import { ContentContext } from '../content-context';

export const ArticleQualifierContextFallback: Provider = {
export const CmsQualifierContextFallback: Provider = {
provide: `${ContextFallback}${ContentContext.Content}`,
useFactory: () =>
combineLatest([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import {
Content,
ContentConfig,
ContentQualifier,
ContentService,
} from '@oryx-frontend/content';
import { PageMetaResolver, provideEntity } from '@oryx-frontend/core';
import { Provider } from '@oryx-frontend/di';
import { provideExperienceData } from '@oryx-frontend/experience';
import { ArticleQualifierContextFallback } from './article-context';
import { experienceArticlePages } from './article-page';
import { articleTypes } from './article-types';
import { Content, ContentQualifier, cmsTypes } from '../../models';
import {
ArticlePageDescriptionMetaResolver,
ArticlePageTitleMetaResolver,
} from './resolvers';
CmsPageDescriptionMetaResolver,
CmsPageTitleMetaResolver,
} from '../../resolvers';
import { ContentConfig } from '../adapter';
import { ContentService } from '../content.service';
import { CmsQualifierContextFallback } from './cms-context';
import { contentfulProviders } from './contentful';
import { storyblokProviders } from './storyblok';
import { strapiProviders } from './strapi';

export const articleProviders: Provider[] = [
ArticleQualifierContextFallback,
provideExperienceData(experienceArticlePages),
export const cmsProviders: Provider[] = [
...contentfulProviders,
...storyblokProviders,
...strapiProviders,
CmsQualifierContextFallback,
{
provide: PageMetaResolver,
useClass: ArticlePageTitleMetaResolver,
useClass: CmsPageTitleMetaResolver,
},
{
provide: PageMetaResolver,
useClass: ArticlePageDescriptionMetaResolver,
useClass: CmsPageDescriptionMetaResolver,
},
{
provide: ContentConfig,
Expand All @@ -41,10 +40,10 @@ export const articleProviders: Provider[] = [
},
},
},
...articleTypes.map((type) =>
...cmsTypes.map((type) =>
provideEntity<Content | null | undefined, ContentQualifier>(type, {
service: ContentService,
context: type,
context: 'content',
get: (service, qualifier) =>
(service as ContentService).get({ ...qualifier, type }),
})
Expand Down
2 changes: 2 additions & 0 deletions libs/domain/content/src/services/cms/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './cms-context';
export * from './cms-providers';
export * from './contentful';
export * from './storyblok';
export * from './strapi';
10 changes: 2 additions & 8 deletions libs/domain/content/src/services/content.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { provideEntity } from '@oryx-frontend/core';
import { Provider } from '@oryx-frontend/di';
import { ExperienceAdapter } from '@oryx-frontend/experience';
import { ContentExperienceAdapter } from './adapter';
import {
contentfulProviders,
storyblokProviders,
strapiProviders,
} from './cms';
import { cmsProviders } from './cms';
import { ContentContext } from './content-context';
import { ContentService } from './content.service';
import { DefaultContentService } from './default-content.service';
Expand All @@ -25,11 +21,9 @@ export const contentProviders: Provider[] = [
provide: FontService,
useClass: DefaultFontService,
},
...contentfulProviders,
...storyblokProviders,
...strapiProviders,
provideEntity('content', {
service: ContentService,
context: ContentContext.Content,
}),
...cmsProviders,
];
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export class DefaultPageMetaResolverService implements PageMetaResolverService {
).pipe(
map((data) =>
data
.filter(([score]) => score !== ResolverScore.NotUsed)
.filter(
([score, data]) =>
score !== ResolverScore.NotUsed && Object.keys(data).length
)
.sort(([aScore], [bScore]) => aScore - bScore)
.reduce((acc, [_, elements]) => ({ ...acc, ...elements }), {})
)
Expand Down
1 change: 1 addition & 0 deletions libs/platform/experience/data-text/data-text.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class DataTextComponent extends TextMixin(

protected $data = computed<string | undefined>(() => {
const { entity: type, field } = this.$options();

return this.entityService
.getField<string>({ element: this, type, field })
.pipe(catchError(() => of()));
Expand Down
115 changes: 0 additions & 115 deletions libs/template/labs/src/articles/article-page.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/template/labs/src/articles/article-types.ts

This file was deleted.

5 changes: 0 additions & 5 deletions libs/template/labs/src/articles/index.ts

This file was deleted.

Loading

0 comments on commit fc94309

Please sign in to comment.