@sitespirit/pagespirit
TypeScript icon, indicating that this package has built-in type declarations

0.0.90 • Public • Published

PageSpirit CMS package for Angular 5+

Contact: david@sitespirit.nl

Installation

npm i --save @sitespirit/pagespirit

Implementation

Minimum setup

The most basic implementation only gives you dynamic routes by providing a states object and api endpoint to the module:

import { PageSpiritModule, RouteLoader } from '@sitespirit/pagespirit';

Then put the PageSpiritModule inside your NgModule imports and provide the configuration object inside the forRoot method.

imports: [
  PageSpiritModule.forRoot({
    states: {
      content_page: { // State as named inside PageSpirit CMS
        component: ContentComponent, // The Component to be loaded for the found route
        items: { // The CMS data to be resolved before allowing the client access to the route
          content: {
            itemid: 1,
            seo_main: true
          }
        }
      }
    },
    apiEndpoint: 'https://client.telespirit.com' // TeleSpirit or Cloudant(WIP) Api Endpoint
  })
]

And add the RouteLoader to the end of your RouterModule.

imports: [
  RouterModule.forRoot([
    { // Make sure this is the last index of the routes array
      path: '**',
      canActivate: [RouteLoader],
      component: ErrorComponent
    }    
  ])
]

Static routes with dynamic data

import { RouteDataResolver } from '@sitespirit/pagespirit';

imports: [
  RouterModule.forRoot([
    {
      path: '',
      component: HomeComponent,
      pathMatch: 'full',
      data: {
        items: { // The CMS data to be resolved before allowing the client access to the route
          content: {
            itemid: 1
          }
        },
        language: 'nl', // Used for multi lingual websites
        uniqueKey: 'home', // Used for multi lingual webistes
        seo: { // SEO settings can be provided, but functionality is not working yet
          nl: {
            title: 'Title for this route' // WIP,
            description: 'Description for this route' // WIP
          }
        }
      },
      resolve: { // When the RouteDataResolver is done fetching the data, the data will be available via ActivatedRoute in the component
        stateData: RouteDataResolver
      }
    }
  ])
]

Get data without routing

Import the DataService in both the app.module as the component or service where you want to use it.

import { DataService } from '@sitespirit/pagespirit';

Provide the DataService in app.module.

providers: [DataService]

Example usage inside component or service:

constructor(private dataService: DataService);

this.dataService.getItemsData(
  {
    content: { // you can add multiple properties to fetch more items
      itemid: 1
    }
  }
).then(x => {
  console.log(x); // here the data is available
});

Rehydration

app.component.ts (your root component)

Rehydration is a little weird at this stage, for some reason rehydrating a child module isnt working yet in Angular 5, so for now we have to subscribe to some observables from the PageSpiritModule to get this working:

The following code is to be placed in your root component:

import { DataService, RouteLoader } from '@sitespirit/pagespirit';

constructor(private transferState: TransferState, private dataService: DataService, private routeLoader: RouteLoader)

To be placed inside your constructor:

const PAGESPIRIT_ITEMS_STATE = makeStateKey('pagespirit_items');
const PAGESPIRIT_URLS_STATE = makeStateKey('pagespirit_urls');
let pagespiritItemsState = this.transferState.get(PAGESPIRIT_ITEMS_STATE, null as any);
if(pagespiritItemsState){
  this.dataService.rehydrate(pagespiritItemsState);
}
this.dataService.items$.subscribe(x => {
  this.transferState.set(PAGESPIRIT_ITEMS_STATE, x as any);
});
let pagespiritUrlsState = this.transferState.get(PAGESPIRIT_URLS_STATE, null as any);
if(pagespiritUrlsState){
  this.routeLoader.rehydrate(pagespiritUrlsState);
}
this.routeLoader.transferObjSubject.asObservable().subscribe(x => {
  this.transferState.set(PAGESPIRIT_URLS_STATE, x as any);
});

app.module

import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser'; import { DataService } from '@sitespirit/pagespirit';

imports: [
  BrowserModule.withServerTransition({ appId: 'pagespirit' }),
  BrowserTransferStateModule,
},
providers: [DataService]

app.server.module

import { ServerModule, ServerTransferStateModule } from '@angular/platform-server';

imports: [
  ServerModule,
  ServerTransferStateModule
]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.901latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.901
0.0.890
0.0.880
0.0.871
0.0.860
0.0.850
0.0.840
0.0.820
0.0.811
0.0.800
0.0.790
0.0.780
0.0.770
0.0.760
0.0.750
0.0.740
0.0.730
0.0.720
0.0.700
0.0.690
0.0.680
0.0.670
0.0.660
0.0.650
0.0.640
0.0.631
0.0.620
0.0.610
0.0.600
0.0.590
0.0.580
0.0.570
0.0.560
0.0.550
0.0.540
0.0.530
0.0.520
0.0.510
0.0.501
0.0.490
0.0.480
0.0.470
0.0.460
0.0.450
0.0.440
0.0.430
0.0.420
0.0.410
0.0.400
0.0.390
0.0.380
0.0.370
0.0.360
0.0.350
0.0.340
0.0.330
0.0.320
0.0.310
0.0.300
0.0.290
0.0.280
0.0.270
0.0.260
0.0.250
0.0.240
0.0.230
0.0.220
0.0.210
0.0.200
0.0.190
0.0.180
0.0.170
0.0.160
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i @sitespirit/pagespirit

Weekly Downloads

5

Version

0.0.90

License

MIT

Unpacked Size

1.03 MB

Total Files

72

Last publish

Collaborators

  • sitespirit