All Projects → jenbuzz → ngx-metafrenzy

jenbuzz / ngx-metafrenzy

Licence: MIT License
🏷️ Angular module for setting meta/link tags such as open graph, canonical, robots, and title

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to ngx-metafrenzy

angular-prerender
A command line tool to prerender Angular Apps.
Stars: ✭ 123 (+547.37%)
Mutual labels:  server-side-rendering, ngx
fastify-angular-universal
Angular Universal integration to Fastify for rendering Angular apps on the server
Stars: ✭ 20 (+5.26%)
Mutual labels:  server-side-rendering, angular-universal
node-ng-ssr-example
Simple Angular Server Side Rendering example
Stars: ✭ 15 (-21.05%)
Mutual labels:  server-side-rendering, angular-universal
ng-mono-repo-starter
Angular Mono Repo Starter
Stars: ✭ 79 (+315.79%)
Mutual labels:  ngx, angular-library
mean-start-2
Full stack Angular + Nest + Universal.
Stars: ✭ 19 (+0%)
Mutual labels:  server-side-rendering, angular-universal
ngext
Better routing for Angular
Stars: ✭ 78 (+310.53%)
Mutual labels:  server-side-rendering, ngx
yii2-react
Yii2 widget for server-side rendering ReactJs
Stars: ✭ 38 (+100%)
Mutual labels:  server-side-rendering
egg-typescript-element-kit
基于 Egg + TypeScript + Element 博客系统,包括前台系统和后台管理系统
Stars: ✭ 19 (+0%)
Mutual labels:  server-side-rendering
ng-sq-ui
Flexible and easily customizable UI-kit for Angular 11+
Stars: ✭ 99 (+421.05%)
Mutual labels:  angular-library
SSR-React-Using-Serverless
SSR-React Using Serverless(aws)
Stars: ✭ 34 (+78.95%)
Mutual labels:  server-side-rendering
ngx-ui-tour
✈️ UI tour for Angular 9+ apps
Stars: ✭ 36 (+89.47%)
Mutual labels:  ngx
vue-js-laravel-ssr
Source code for the article "Server-Side Rendering With Laravel & Vue.js 2.5"
Stars: ✭ 69 (+263.16%)
Mutual labels:  server-side-rendering
ngx-animated-gradient
Angular Directive that animates the gradient background
Stars: ✭ 16 (-15.79%)
Mutual labels:  ngx
nx-ng-nest-universal
Nx Workspace with a seperated Nest App for Angular Universal SSR.
Stars: ✭ 32 (+68.42%)
Mutual labels:  server-side-rendering
frontity-twentynineteen
🎨 A Frontity Twentynineteen theme Project
Stars: ✭ 54 (+184.21%)
Mutual labels:  server-side-rendering
vue-ssr-starter
Starter kit for projects with Webpack 4, Vue 2 and SSR
Stars: ✭ 53 (+178.95%)
Mutual labels:  server-side-rendering
elekid
Resolver for React's Server Side Render on Module, ReactElement or Electron
Stars: ✭ 21 (+10.53%)
Mutual labels:  server-side-rendering
ng1-server
Node.js server side library for pre-rendering complex AngularJS app. Supports caching and URL rules.
Stars: ✭ 43 (+126.32%)
Mutual labels:  server-side-rendering
cloudflare-worker-app-kit
☁✨ A handy set of tools for creating a Cloudflare Worker app.
Stars: ✭ 75 (+294.74%)
Mutual labels:  server-side-rendering
next-saga-example
Example of using next.js with redux saga
Stars: ✭ 24 (+26.32%)
Mutual labels:  server-side-rendering

Coverage Status

ngx-metafrenzy

This angular module will provide help in dynamically setting the head-tags such as meta/link/title. It works with server-side rendering!

Requirements

  • Angular 13+

Older versions of Angular:

  • use v7.0.0 for Angular 12
  • use v6.0.0 for Angular 10
  • use v5.1.0 for Angular 9
  • use v4.1.0 for Angular 8
  • use v3.2.0 for Angular 7
  • use v2.4.1 for Angular 6

Installation

$ npm install ngx-metafrenzy

or

$ yarn add ngx-metafrenzy

Usage

Setup the NgModule first. Always import MetafrenzyModule. Import MetafrenzyGuard if you want to use the guard functionality. See the data section in the example below for more on the syntax.

import { MetafrenzyModule, MetafrenzyGuard } from 'ngx-metafrenzy';

@NgModule({
    declarations: [AppComponent],
    imports: [
        ...
        MetafrenzyModule.forRoot(),
        RouterModule.forRoot([
            {
                path: '',
                component: AppComponent,
                canActivate: [MetafrenzyGuard],
                data: { 
                    metafrenzy: {
                        title: 'My Title',
                        tags: [
                            {
                                name: 'og:title',
                                content: 'My title'
                            }, {
                                name: 'og:description',
                                content: 'My description'
                            }
                        ],
                        links: [
                            {
                                rel: 'canonical',
                                href: 'http://localhost/'
                            }
                        ]
                    }
                }
            }
        ])
        ...
    ],
    ...
})

When navigating between routes you can also add "canDeactivate" to the data object. This will try to reset the metatags, which were set in the previous route. Use this with caution as you might remove tags, which should be global or not removed. See remove-functions in the service class to remove single tags.

...
    canDeactivate: [MetafrenzyGuard],
...

You can use the service class MetafrenzyService in any component. See example below:

import { MetafrenzyService } from 'ngx-metafrenzy';

@Component({
    ...
})
export class AppComponent {

    constructor(private readonly metafrenzyService: MetafrenzyService) {
        this.metafrenzyService.setTitle('My title');

        this.metafrenzyService.setMetaTag('og:title', 'My title');

        this.metafrenzyService.setLinkTag({
            rel: 'canonical',
            href: 'http://localhost/'
        });
    }

}

As shown above the title can be set using setTitle and a meta tag using setMetaTag with the content as parameters. The link tag is a little different since you pass an object to match all possible variations of attributes on the link tag. Properties in this link object could be:

charset, crossorigin, href, hreflang, media, rel, rev, sizes, target, type

Service class functions

// Set title tag
setTitle('')

// Returns the current title as a string
getTitle()

// Set meta tag from specified name and content
setMetaTag('')

// Returns the content value of a metatag matching the selector
getMetaTag('')

// Remove a single meta tag (eg. removeMetaTag('name="test"'))
removeMetaTag('')

// Set the value of meta charset
setMetaCharsetTag('')

// Set link tag from specified object
setLinkTag({
    charset: '';
    crossorigin: '';
    href: '';
    hreflang: '';
    media: '';
    rel: '';
    rev: '';
    sizes: '';
    target: '';
    type: '';
})

// Remove link tags
removeLinkTags(() => true);

// Set title tag and og:title to the same value
setAllTitleTags('')

// Set meta description and og:description to the same value
setAllDescriptionTags('')

// Set canonical url
setCanonical('')

// Set robots tag
setRobots('')

// Set all open graph tags
setOpenGraph({
    title: '', 
    description: '',
    type: '',
    url: '',
    image: '',
    site_name: ''
});

// Set multiple tags with one call
setTags({
    title: '', // setting title and og:title
    description: '', // setting meta description and og:description
    url: '', // setting canonical and og:url
    robots: '', // setting robots
    image: '' // setting og:image:url
});

Docker

For development in a docker container run:

$ docker-compose up --build -d

And go to http://localhost:4200

License

This package is open-sourced software licensed under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].