npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@connectholland/ngx-prismic

v1.3.0

Published

## Installation ```npm i @connectholland/ngx-prismic```

Downloads

29

Readme

NgxPrismic

Installation

npm i @connectholland/ngx-prismic

Implementation

Make sure to add "preserveSymlinks": true to the angular.json otherwise this library doesn't work with ng serve.

angular.json

     "projects": {
       "my-project-name": {
         "architect": {
           "build": {
             "options": {
               "preserveSymlinks": true

app.module.ts

Add required imports

import { NgxPrismicModule, NgxPrismicConfiguration, NgxPrismicConfigurationParameters } from '@connectholland/ngx-prismic';
import { prismicConfig } from './prismic.conf';

Note: prismicConfig is defined in the next step, for now just create an empty prismic.conf file in your application.

Add the prismicConfigFactory

export function prismicConfigFactory(): NgxPrismicConfiguration {
  const params: NgxPrismicConfigurationParameters = {
    apiUrl: 'https://my-repo.prismic.io/api/v2',
    prismicConfig: prismicConfig,
    languagePrefixes: {
      'nl-nl': '',
      'en-gb': '/en'
    },
    unknownPageType: 'page-not-found'
  };

  return new NgxPrismicConfiguration(params);
}

| parameter | type | description | |:---------------- |:------------------------|:-------------| | apiUrl | string | The url to the prismic API v2. | prismicConfig | PrismicConfig[] | Imported entity configuration. | languagePrefixes | {[key: string]: string} | object with the prefix of the pages in a selected language. | unknownPageType | string | Single type item to be loaded from prismic if the requested page can not be found (404).

Note: languagePrefixes and unknownPageType will be moved to the prismic config in a future release.

and use it while importing the Module

imports: [
    NgxPrismicModule.forRoot(prismicConfigFactory)
]

Configuration

Module

The prismic.conf contains the configuration for entities in prismic

import { PrismicConfig } from '@connectholland/ngx-prismic';
import { ExampleComponent } from './pages/news/example.component';

export const prismicConfig: PrismicConfig[] = [
  {
    type: 'example',
    urlPrefix: {
      'nl-nl': 'voorbeeld'
      'en-gb': 'example'
    },
    component: ExampleComponent
  }
];

| parameter | type | description | |:-------------- |:------------------------|:-------------| | type | string | name of the type in the api of prismic. | urlPrefix | {[key: string]: string} | urlPrefix of the type where the object key is the required language. | fixedUrl | {[key: string]: string} | should only be used for single types like the homepage so you can redirect them to / or /en. | searchable | boolean | true if this entity should be included while using the search function. | filterable | boolean | if true returns this entity as one of the options to filter on in the search. | parentage | function | anonymous function that can be used to define parentage, this will be explained in more detail later. | component | Type<any> | The component to call if the page is found in prismic (this component must have an input variable called data to push in the content | requestOptions | {[key: string]: string} | Used for making additinal requests like extra fields for linked items if this item is requested by the module.

Router

Example how the router component can be added to sites navigation module, this is still up for improvement but seems to work for now.

import { PrismicRouterComponent } from '@connectholland/ngx-prismic';

const routes: Routes = [
  { path: 'en/:uid', component: PrismicRouterComponent, data: { lang: 'en-gb' }},
  { path: ':uid', component: PrismicRouterComponent, data: { lang: 'nl-nl' }},
  { path: 'en/:urlPrefix/:uid', component: PrismicRouterComponent, data: { lang: 'en-gb' }},
  { path: ':urlPrefix/:uid', component: PrismicRouterComponent, data: { lang: 'nl-nl' }}
]

Usage

The following is an example on how the service can be used to fetch multiple projects (there is a limit of 100 on the api)

  public projects: any;

  constructor(
    public prismicService: PrismicApiClientService,
  ) {}

  private fetchProjects(page: number = 1) {
    this.prismicService.getMultipleByType('project'}, this.filter).then(projects => {
      this.projects = result;
    });
  }

Methods

These still have to be ezplained

public getConfig(): PrismicConfig[]

public getDocument(type: string, uid: string, options?: any): Promise<any>

public getSingleByType(type: string): Promise<any>

public getMultipleByType(type: string | string[], options: any = {}, atFilters: {[key: string]: any} = {}, anyFilters: {[key: string]: any} = {}): Promise<any>

public getById(id: string, type?: any): Promise<any>

public findByUID(uid: string, page: number = 1): Promise<any>

public getDocumentByUid(uid: string): Promise<any>

public search(text: string, page: number = 1, filterType?: string): Promise<any>

public getSearchableTypes(): string[]

public getFilterableSearchTypes(): string[]

public getRequestOptions(type)

public toHtml(data): string

public toRaw(data): string

public getimage(image: any, size?: string)

public getTagsByType(type: string): string[]

public formatDate(date, options?: any): string

public getLanguage(): string

public setLanguage(lang: string)

public getLanguagePrefix(): string

public getParent(type: string)

public objectLinkResolver(doc: any): any

public linkResolver(doc): string

public setActiveType(type: string)

public getActiveType(): string

public getLanguageObserver(): Subject<string>