Giter VIP home page Giter VIP logo

angular-update-meta's Introduction

Update meta tags in AngularJS

Dynamically update meta tags and document title for SEO purposes in your AngularJS application.

Build Status

  • lightweight (< 1KB)
  • uses original meta syntax
  • supports prerender.io for SEO purposes
  • supports Open Graph protocol meta elements
  • supports schema.org protocol meta elements
  • supports link elements
  • update your document title dynamically
  • update your meta tags depending on the state your application is in
  • no additional scripting required, works out-of-the-box!

View example plunk right here.

Usage

First install the module using bower:

$ bower install angular-update-meta

then add the updateMeta module to the dependencies of your AngularJS application module:

angular.module('yourApp', ['updateMeta']);

Suppose you have the following markup in your template:

<html>
  <head>
    <title>Website title</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Language" content="en" />
    <meta name="description" content="Application wide description" />
    <meta property="og:title" content="The Rock" />
    <meta itemprop="description" content="Application wide description for Schema.org (Google+ uses this)">
    <script type="application/ld+json"></script>
  </head>
  <body ng-app="yourApp">
    ...
  </body>
</html>

Now you can use the following markup in your view(s):

<update-title title="A new title"></update-title>
<update-meta charset="ISO-8859-1"></update-meta>
<update-meta http-equiv="Content-Language" content="es"></update-meta>
<update-meta name="description" content="A page specific description"></update-meta>
<update-meta property="og:title" content="Minions"></update-meta>
<update-meta itemprop="description" content="A page specific itemprop description"></update-meta>
<update-script content="structuredData" type="application/ld+json"></update-script>

And if you want to use Google Structured Data, create an object like this in $scope:

$scope.structuredData = {
  "@context": "http://schema.org",
  "@type": "Organization",
  "url": "http://www.example.com",
  "name": "Unlimited Ball Bearings Corp.",
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "+1-401-555-1212",
    "contactType": "Customer service"
  }
};

So the head is updated to:

<html>
  <head>
    <title>A new title</title>
    <meta charset="ISO-8859-1" />
    <meta http-equiv="Content-Language" content="es" />
    <meta name="description" content="A page specific description" />
    <meta property="og:title" content="Minions" />
    <meta itemprop="description" content="A page specific itemprop description">
    <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "Organization",
      "url": "http://www.example.com",
      "name": "Unlimited Ball Bearings Corp.",
      "contactPoint": {
        "@type": "ContactPoint",
        "telephone": "+1-401-555-1212",
        "contactType": "Customer service"
      }
    }
    </script>
  </head>
  <body ng-app="yourApp">
    ...
  </body>
</html>

Only existing meta elements are updated.

If the meta element does not exist yet, it is NOT added, so make sure they exist in your original head element.

Whenever an update-meta element is processed, the original meta in the head is updated with the new value.

This allows you to dynamically set the meta element values with values from within your markup and child states.

You can also update link tags. If you have the following markup in your layout:

<html>
  <head>
    <link rel="stylesheet" href="http://example.com" />
    <link rel="alternate" href="http://example.com/another" hreflang="" />
    <link rel="alternate" href="http://example.com/another" id="test" />
  </head>
</html>

and you have the following markup in your view:

<update-link rel="stylesheet" href="http://example.com/updated"></update-link>
<update-link rel="alternate" href="http://example.com/another" hreflang="es"></update-link>
<update-link rel="alternate" href="http://example.com/another-updated" id="test"></update-link>

then the head will be updated to:

<html>
  <head>
    <link rel="stylesheet" href="http://example.com/updated" />
    <link rel="alternate" href="http://example.com/another" hreflang="es" />
    <link rel="alternate" href="http://example.com/another-updated" id="test" />
  </head>
</html>

A rel and a href attribute must be supplied to the directive. The directive will try querying the DOM using the rel and href attributes, and optionally an id. Any of the supported attributes (id, charset, crossorigin, hreflang, integrity, media, methods, referrerpolicy, sizes, target, title, type) will be updated.

Expressions

Dynamic AngularJS expressions are supported too:

<update-meta property="og:title" content="{{ title }}"></update-meta>

In the example above, the og:title is automatically updated whenever title changes.

Prerender.io

Prerender.io will grab the updated values and store them in your page snapshots so they are optimized for SEO purposes.

This allows you to conveniently update the meta elements for each individual page in your AngularJS single page application and store them correctly in your Prerender page snapshots.

You can preview the prerender output by using the _escaped_fragment_= parameter as described in the prerender.io documentation.

Contribute

To update the build in the dist directory:

$ gulp

To run the unit tests (for both concatenated and minified version):

$ gulp test

Change log

2.1.0

2.0.1

2.0.0

  • added support for link elements #18

1.9.0

  • added support for itemprop (thank you @urbgimtam)
  • added examples for itemprop

1.8.0

  • added examples for use with ngRoute and ui-router

v1.7.1

  • fixed bower dependencies

v1.7.0

  • added update-title directive
  • updated documentation
  • updated example

v1.6.0

  • added dynamic tag support
  • updated documentation
  • updated example

v1.5.1

  • fixed issue with http-equiv
  • updated documentation
  • updated example

v1.5.0

v1.4.0

  • switch to native element.querySelector() method to fix #4

v1.3.0

  • added double quotes to support #2

v1.2.1

  • fix bower ignore files

v1.2.0

  • update bower ignore files

v1.1.0

  • add travis support
  • update documentation

v1.0.0

  • refactor to support original markup
  • add unit tests
  • update documentation

v0.1.0

  • Initial version

angular-update-meta's People

Contributors

jvandemo avatar pymossy avatar zupper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-update-meta's Issues

Open Graph support?

Does the Open Graph support imply that social media networks such as Facebook will scrape the correct information if the properties are set?

Update Metat Tag not working - Angular

Working with Angular 9

Added meta tag in index.html , now from other pages i am trying to update metatag from component to share it on LinkedIn.

They are updated when i check using inspect element. but on linked in it is not show updated one.

Default tags not supported

Can there be a functionality where we set default tags which are adopted by all pages?
Right now, meta information has to be provided for all pages.

update meta not working

Hi, I have implemented this into my angularjs app however, the update-meta tag is not working, it does not update my meta tags.

It is weird because update-title works, only the update-meta dosent work.

Help would be much appreciated.

Thanks

support for property attribute

Hi @jvandemo, since the open graph uses property as the meta key, is there any concern for not supporting it? I've seen you rejected the PR due to the meta element standard though. However, it would be great if this plugin is a complete solution for all those SEO things within head tag.

Title is changing after reload

views title and meta tags updated perfectly using updateMeta. But after reload the website then everything is updated in views but title only changes i mean template title updated to view title after particular seconds. Initially it is showing the correct view page title but after 2 seconds it is showing template title but other meta tags are not changing only title is having this problem. Other than this issue everything is working fine . Please help me to fix the issue.

Navigating away from a view with update-meta overwrites doesn't return to default values

If you overwrite default meta values from within a view; navigating off of that view to one without any update-meta does not return the page meta values to their original values.

For example, if the default title tag in my template is set to:

<title>My Lovely Company</title>

... and I overwrite that title from within the /contact view:

<update-title title="My Lovely Company | Contact us"></update-title>

When I navigate away from the /contact view to a view without any overwrites, the DOM title remains:

<title>My Lovely Company | Contact us</title>

Is this intended behaviour? In which case, it requires that all views that can make do with the default meta data have their own update-meta overwrites. Subsequent app wide changes to the default meta data will then need to be updated in all the 'vanilla' views also.

Update meta not working

Hello, I have used angular meta tag into my angularjs app, but when I check on card validator for Facebook or Twitter, it's not working. The page keep the content of default meta tag.

I have questions on how to use update-meta tag :

  • Can we have the meta tag and the update-meta tag in the same page ? In the docs, it's written :

Now you can use the following markup in your view(s):

  • Shloud I used prerender.io to operate update-meta tag ?

Here is an example of my meta tag :

	<meta property="fb:app_id"             content="MY_APP_ID" />
	<meta property="og:url"                content="MY_URL_BASE" />
	<meta property="og:type"               content="MY_TYPE" />
	<meta property="og:title"              content="My_DEFAULT_TITLE" />
	<meta property="og:description"        content="MY_DEFAULT_DESCRIPTION" />
	<meta property="og:image"              content="MY_DEFAULT_IMAGE" />
	<meta property="music:duration"        content="" />
	<meta property="music:album"           content="" />
	<meta property="music:album:track"     content="" />
	<meta property="music:musician"        content="" />

	<update-meta property="og:description"     content="{{ description }}"></update-meta>
	<update-meta property="og:image"	   content="{{ image }}"></update-meta>
	<update-meta property="music:duration"     content="{{ duration }}"></update-meta>
	<update-meta property="music:album"        content="{{ album }}"></update-meta>
	<update-meta property="music:album:track"  content="{{ title }}"></update-meta>
	<update-meta property="music:musician"     content="{{ artist }}"></update-meta>

Thanks.

Image does not appear when sharing

@jvandemo
I have added image tag to have a certain image appear when sharing to Facebook
<meta name="og:image" content="assets/images/background.jpg" />. This works well when I share the homepage but whenever I share any other page, no image appears. The title and the description appear correctly but no image appears. Not the even the home page one.
Here's what I am doing when trying to update the image:
<update-meta name="og:image" content="{{property.property.images[0].image_path}}"></update-meta>
Any idea how can I debug this issue further?

Missing "main" key in package.json breaks ES6 simple module import

Unlike other npm packages, this package does not yet support the ES6 simple import, as in:

import 'angular-update-meta';

note that it's possible to work around it with:

import 'angular-update-meta/dist/update-meta'

Anyway, adding a 'main' key to package.json should solve it:

"main": "dist/update-meta.js"

"Looking up elements via selectors" error

Hi @jvandemo, thanks for creating this plugin. As soon as I add the line <update-meta name="apple-mobile-web-app-status-bar-style" content="black"> in my view template, I get the following error:

Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element

In your directive, the line angular.element('meta[name=' + scope.name + ']') triggers the error in my debug mode. I also try to include jQuery but does not resolve the issue. Would you advise what goes wrong here? My AngularJS is at version 1.4.3.

Update an array of values - prevent overwrite of content for same property

Does this plugin support updating multiple values for the same property? For example,

<update-meta property="article:tag" content="one" />
<update-meta property="article:tag" content="two" />
<update-meta property="article:tag" content="three" />
<update-meta property="article:tag" content="four" />

Right now it seems like if there's an array, each update overwrites the last, so that what shows up is just

<meta property="article:tag" content="four">
<meta property="article:tag" content="">
<meta property="article:tag" content="">
<meta property="article:tag" content="">

even if I've defined

<meta property="article:tag" content="">
<meta property="article:tag" content="">
<meta property="article:tag" content="">
<meta property="article:tag" content="">

Facebook share not receiving og:meta tags

The angular site: http://ec2-52-77-225-241.ap-southeast-1.compute.amazonaws.com/article/poor-left-behind-at-climate-talks is using (successfully) this directive and the tags are being updated. However when I try sharing it (the post share is currently using the feed method) I get the default meta tags.

Even facebook debugger is not showing the current tags..

Also, the facebook sharing on Disqus is not working as it is using Facebook share dialogue.

Could someone shed some light on what's happening?

Update the html tag?

Can (or Will) this module update an attribute of the html tag like the lang for example: ?

2.0.0 update-link directive not working while update-meta is working...

Is it only me? Ive spent a good 2 hours trying to get update-link directive to work.

I checked the documentation and examples and have rechecked my code at least 10 times, even had a peek into the release to check the directive was there! (Sadly the plunker hasnt been updated to include any working update-link examples - although i have COPIED the documentation examples into my page and they dont work.)

  1. In my index.php I have the default tags in my head which includes the meta properties as well as the link rels.

  2. In my gallery subpage/subdirectory I have included the update-meta and update-link directives as given in the example.

  3. this results in the meta tags being updated, while the link tags remain as in the 'default' values in the head of the document.

....?!?....

Could somebody please create a working update-link plunker?

Empty tags content if not used

I would take benefits of an option that would reset the tags content, before any state change.

For example, I use open-graph meta in few states on my application. I expect them to be empty in other states ; by now to make it work I must add

in any state.

update meta tags issue

I have following code in my index.html

<meta property="og:title" content="Lorem ipsum dolor sit amet" /> <meta property="og:type" content="website" /> <meta property="og:url" content="http://www.example.com/home.html" /> <meta property="og:image" content="https://faisal080.files.wordpress.com/2012/11/marcus_2545603.jpg?w=640&h=480" /> <meta property="fb:app_id" content="1673863836197303" />

I have following code in my view:
<update-meta property="og:title" content="{{vm.title}}"></update-meta> <update-meta property="og:type" content="website"></update-meta> <update-meta property="og:url" content="{{vm.location}}"></update-meta> <update-meta property="og:image" content="{{vm.image}}"></update-meta>

When I open my view in browser, meta tags are updated correctly in DOM but when I copy view URL here https://developers.facebook.com/tools/debug/
it always fetch content from index.html. In other words it always take og:url from index.html.

Can you please guide me what I am doing wrong ?

bower.json should be updated

The file bower.json should be update to use the lastest version of AngularJS 1.4.*.

"dependencies": {
    "angular": "~1.2.21"
  },
  "devDependencies": {
    "angular-mocks": "~1.2.21",
    "angular-scenario": "~1.2.21"
  }

I tested without the dependencies with the lastest version of AngularJS, works like a charm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.