Constructor
new PageData(url)
This constructor throws a ValidationError unless a valid URL is passed.
| Name | Type | Description |
|---|---|---|
url | URL | The page's full URL. |
- Source
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.
- Source
h1s
An alias for .topLevelHeadings.
- Source
- See
- PageData#topLevelHeadings
h2s
An alias for .secondaryHeadings.
- Source
- See
- PageData#secondaryHeadings
headings
Get the page's section headings.
- Source
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.
- Source
path
- Source
secondaryHeadings
The page's secondary headings (h2 tags).
- Source
title
- Source
title
- Source
topLevelHeadings
The page's top-level headings (h1 tags).
- Source
uri
- Source
url
- Source
url
- Source
Methods
addSecondaryHeading(h2Text) → {PageData}
Add a seconary heading.
| Name | Type | Description |
|---|---|---|
h2Text | string |
- Source
A reference to self to facilitate function chaning.
- Type:
- PageData
addTopLevelHeading(h1Text) → {PageData}
Add a top-level heading.
| Name | Type | Description |
|---|---|---|
h1Text | string |
- Source
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.
- Source
A plain object containing the page data.
- Type:
- Object
h1()
A shortcut for .addTopLevelHeading().
- Source
- See
- PageData#addTopLevelHeading
h2()
A shortcut for .addSecondaryHeading().
- Source
- See
- PageData#addSecondaryHeading