PageData. PageData

A class representing the data extracted from web pages that can be transformed into link data for use when rendering links.

Constructor

new PageData(url)

This constructor throws a ValidationError unless a valid URL is passed.

Parameters:
NameTypeDescription
urlURL

The page's full URL.

Throws:

A validation error is thrown if an invalid URL is passed.

Type
ValidationError

Members

domain

Get the domain-part of the URL as a string.

h1s

An alias for .topLevelHeadings.

See
  • PageData#topLevelHeadings

h2s

An alias for .secondaryHeadings.

See
  • PageData#secondaryHeadings

headings

Get the page's section headings.

mainHeading

The text from the most important heading on the page. If the page has h1 tags, the first one will be used, if not, the first h2 tag will be used, and if there's none of those either, an empty string will be returned.

path

secondaryHeadings

The page's secondary headings (h2 tags).

title

title

topLevelHeadings

The page's top-level headings (h1 tags).

uri

url

url

Methods

addSecondaryHeading(h2Text) → {PageData}

Add a seconary heading.

Parameters:
NameTypeDescription
h2Textstring
Returns:

A reference to self to facilitate function chaning.

Type: 
PageData

addTopLevelHeading(h1Text) → {PageData}

Add a top-level heading.

Parameters:
NameTypeDescription
h1Textstring
Returns:

A reference to self to facilitate function chaning.

Type: 
PageData

asPlainObject() → {Object}

Get the page data as a plain object of the form:

{
    url: 'http://www.bartificer.net/',
    title: 'the page title',
    topLevelHeadings: [ 'first h1', 'second h1' ],
    secondaryHeadings: [ 'first h2', 'second h2' ],
    mainHeading: 'first h1',
    uri: {
        hostname: 'www.bartificer.net',
        path: '/',
        hasPath: false
    }
}

Note that the uri could contain more fields - it's initialised with output from the URI.parse() function from the URI module.

Returns:

A plain object containing the page data.

Type: 
Object

h1()

A shortcut for .addTopLevelHeading().

See
  • PageData#addTopLevelHeading

h2()

A shortcut for .addSecondaryHeading().

See
  • PageData#addSecondaryHeading