0

I have the following snippet running the latest version of x-ray npm module.

I expect to the Meta and Metatags elements to be populated but they are not when i print out obj. What am i doing wrong?

var Xray = require('x-ray');
var x = Xray();

x('http://www.rte.ie', {
    title: 'title',
    metatags: x('meta', [{
        name: 'meta@name',
        description: 'meta@content'
  }]),
    meta: 'meta'
})(function (err, obj) {
    console.log(obj);
})
TommyK
  • 416
  • 2
  • 6
  • 24

1 Answers1

0

The way you set up your selectors for meta, essentially leaves xray looking for:

<meta>
    <meta name="@val" />
    <meta description="@val" />
    <meta name="@val" />
    <meta description="@val" />
</meta>

So an alternative for the same would have been:

x('http://www.rte.ie', {
    title: 'title',
    metaname: 'meta@name',
    metadescription: 'meta@content'
  }]),
    meta: 'meta'
})(function (err, obj) {
    console.log(obj);
})

If you were looking for multiple names / descriptions, simply putting the entire thing in square brackets suits.

That, or search the use the head tag as a selector:

x('http://www.rte.ie', 'html'{
    title: 'title',
    meta: x('head', [{
        name: 'meta@name',
        description: 'meta@content'
    }])
  }]),
    meta: 'meta'
})(function (err, obj) {
    console.log(obj);
})
Tainted
  • 237
  • 1
  • 5
  • 17