Skip to main content

Context

The context object is the entrypoint for all data available to your templates. The TContext type describes this object and all its properties. See its pageData property for the result of scraping the current page and config for other information such as the page's current view. A number of assets are made available through its assets property.

Example

<img src="{{assets.images.hnLogo}}" />
<div>{{config.view}}</div>
{{#each pageData.items}}
<div>{{this.title}}</div>
{{/each}}

Table of contents

Type Aliases

Type Aliases

TAssets

Ƭ TAssets: Object

Assets available to templates.

Example

{{! in CSS using asset's full URL }}
{{#with assets.icons}}
.accordion {
--bs-accordion-btn-icon: url('{{expandDown}}');
--bs-accordion-btn-active-icon: url('{{expandDown}}');
}

[data-bs-theme=dark] .accordion-button:after {
--bs-accordion-btn-icon: url('{{expandDown_dark}}');
--bs-accordion-btn-active-icon: url('{{expandDown_dark}}');
}
{{/with}}

Example

{{! in HTML using baseURL }}
<img src="{{assets.baseURL}}/images/hn_logo.svg" />

Type declaration

NameTypeDescription
baseURLstringThe assets directory's base URL. Example chrome-extension://ihcblehlmbfeecfaiomaihjkeedjepoc/assets/img/content See packages/content/public/assets/img/content
icons{ chevronDown: string ; chevronDown_dark: string ; expandDown: string ; expandDown_dark: string }Icon URLs. Remarks While Material icons are available in Handlebars templates, sometimes it is necessary to use icons in CSS such as when overriding a Bootstrap component's iconography. We include light and dark versions of icons for this purpose.
icons.chevronDownstring-
icons.chevronDown_darkstring-
icons.expandDownstring-
icons.expandDown_darkstring-
images{ hnLogo: string ; hnLogo_256: string }Image URLs.
images.hnLogostring-
images.hnLogo_256string-

Defined in

types/src/content/views/context.ts:45


TConfig

Ƭ TConfig: Object

Context configuration for the current page.

Type declaration

NameTypeDescription
hostnamestringCurrent page's hostname. Example news.ycombinator.com
pathnamestringCurrent page's pathname. Example /newcomments
viewTViewCurrent page's view. Example storyList

Defined in

types/src/content/views/context.ts:83


TContext

Ƭ TContext<T>: Object

The main context object supplied to all views.

Type parameters

NameDescription
TThe result of parsing the current page. See the various views for return types: Lists, Items and Other.

Type declaration

NameTypeDescription
assetsTAssetsDescribes information about any available assets.
configTConfigConfiguration for the current page.
pageDataT & TPageDataExtensionData associated with the current page's view. Example { bodyHTML: "<p>Lorem ipsum</p>", comments: [], currentUser: { ... }, id: "37390184" }

Defined in

types/src/content/views/context.ts:108


TPageDataExtension

Ƭ TPageDataExtension: Object

Additional properties that are not specific to any one view.

Type declaration

NameTypeDescription
currentUser{ id?: string ; isLoggedIn?: boolean ; karma?: number ; links: { login?: string ; logout?: string ; profile?: string } }Information about the current user.
currentUser.id?stringUser's identifier. Example pg
currentUser.isLoggedIn?booleanWhether the user is logged in.
currentUser.karma?numberKarma amount.
currentUser.links{ login?: string ; logout?: string ; profile?: string }Links to other pages.
currentUser.links.login?stringUser's path to login. Example login?auth=abcd1234&goto=news
currentUser.links.logout?stringUser's path to logout. Example logout?auth=abcd1234&goto=news
currentUser.links.profile?stringUser's profile. Example user?id=pg

Defined in

types/src/content/views/context.ts:135