Skip to main content

Shared

Types shared across the various page views.

Table of contents

Type Aliases

Variables

Type Aliases

TAge

Ƭ TAge: Object

Age information for a specific item.

Type declaration

NameTypeDescription
humanized?stringHuman-readable creation time. Example 2 hours ago
timestamp?stringTimestamp in UTC format. Example 2023-09-03T14:53:21Z Remarks There are Handlebars helpers to display formatted timestamps: timestampDate - Renders the date portion of the given timestamp. timestampTime - Renders the time portion. Example hbs <span>{{timestampDate age.timestamp}}</span>

Defined in

types/src/content/views/shared.ts:50


TComment

Ƭ TComment: Object

User comment and its replies.

Type declaration

NameTypeDescription
commentsTComment[]List of replies.
data{ age: TAge ; bodyHTML?: string ; collapsed: { count?: number ; value: boolean } ; id: string ; interactions: Pick<TInteractions, "next" | "parent" | "prev" | "root" | "toggle" | "voteDown" | "voteUp"> ; links: Pick<TLinks, "item" | "reply"> ; user?: TUser ; voted?: TVoteDirection }Comment information.
data.ageTAgeWhen the comment was created.
data.bodyHTML?stringHTML of the body. Remarks Should be used with Handlebar's triple-brace escape syntax: {{{bodyHTML}}}.
data.collapsed{ count?: number ; value: boolean }Information about the comment's collapsed status.
data.collapsed.count?numberNumber of collapsed items. Remarks When a comment is collapsed in Hacker News, the toggle element is replaced to show the number of collapsed children such as [17 more]. We capture the number of children as the count value only when a comment is collapsed. Its count will be undefined when expanded.
data.collapsed.valuebooleanWhether the comment is collapsed. Remarks A value of true indicates the comment is collapsed. When a comment is collapsed, access to its voting buttons is lost which must be taken into account when writing comment tree components.
data.idstringThe Hacker News identifier. Example 2921983
data.interactionsPick<TInteractions, "next" | "parent" | "prev" | "root" | "toggle" | "voteDown" | "voteUp">User interactions.
data.linksPick<TLinks, "item" | "reply">Links to other pages. Example item?id=37369826
data.user?TUserUser that created the comment.
data.voted?TVoteDirectionWhether the current user has voted on the comment and how.
depthnumberComment's depth in the tree.

Defined in

types/src/content/views/shared.ts:73


TCommentListItem

Ƭ TCommentListItem: Object

Single comment item.

Type declaration

NameTypeDescription
ageTAgeWhen the item was created.
bodyHTML?stringHTML of the body. Remarks Should be used with Handlebar's triple-brace escape syntax: {{{bodyHTML}}}.
id?stringThe Hacker News identifier. Example 2921983
interactionsPick<TInteractions, "voteDown" | "voteUp">User interactions.
linksPick<TLinks, "context" | "favorite" | "flag" | "next" | "parent" | "story" | "unflag">Links to other pages. Example item?id=37369826
story{ title: TStoryListItem["title"] }The associated story.
story.titleTStoryListItem["title"]Story's title.
user?TUserUser that created the comment.
voted?TVoteDirectionWhether the current user has voted on the comment and how.

Defined in

types/src/content/views/shared.ts:142


TForm

Ƭ TForm: Object

HTML form.

Type declaration

NameTypeDescription
action?stringThe endpoint of the submit action. Example comment
hiddenInputsHTML?stringHTML of hidden inputs. Remarks Should be used with Handlebar's triple-brace escape syntax: {{{hiddenInputsHTML}}}.
method?stringThe HTTP method associated with the form. Example post

Defined in

types/src/content/views/shared.ts:186


TForms

Ƭ TForms: Object

Type declaration

NameTypeDescription
comment?TFormComment or reply form.
submit?TFormSubmit form on the /submit page.

Defined in

types/src/content/views/shared.ts:208


TInteractions

Ƭ TInteractions: Object

User actions that may either redirect or perform an inline page update. These are HTML strings that must be used with a <hnp-interaction> web component.

Example

<hnp-interaction from="{{interactions.hide}}">hide</hnp-interaction>

Type declaration

NameTypeDescription
hide?stringHides the selected item from view.
next?stringNavigates to the next item.
parent?stringThe item's parent, typically a comment.
prev?stringPrevious instances of the linked item or the previous comment.
root?stringThe item's root, typically a comment.
toggle?stringCollapses the item, typically a comment.
voteDown?stringDownvotes an item.
voteUp?stringUpvotes an item.

Defined in

types/src/content/views/shared.ts:225


TJobListItem

Ƭ TJobListItem: Object

Single job item.

Type declaration

NameTypeDescription
ageTAgeWhen the job was created.
linksPick<TLinks, "from" | "hide" | "item">Links to other pages. Example item?id=37286598
site?TSiteInformation about the linked site.
title?stringThe job's title.

Defined in

types/src/content/views/shared.ts:252


Ƭ TLinks: Object

Elements that only perform a redirect when clicked.

Type declaration

NameTypeDescription
context?stringLocation of comment in a tree.
favorite?stringAdds the item to the user's list of favorites.
flag?stringFlags an item.
from?stringList of items from the same domain.
hide?stringRemoves an item from view. Remarks While this is named the same as hide on TInteraction, some items reload the page instead of performing an inline hide. Such examples may be seen on job item pages: https://news.ycombinator.com/item?id=37320729.
item?stringItem's pathname.
more?stringThe next page.
next?stringThe next item in a list.
parent?stringComment's parent.
past?stringItem's search results on hn.algolia.com.
reply?stringComment's reply page.
story?stringComment's story.
unflag?stringUnflags an item.

Defined in

types/src/content/views/shared.ts:270


TPollOptionItem

Ƭ TPollOptionItem: Object

Single option in a poll.

Type declaration

NameTypeDescription
id?stringThe Hacker News identifier. Example 126812
interactionsPick<TInteractions, "voteDown" | "voteUp">User interactions.
score?numberThe poll item's score.
title?stringTitle of the option.
voted?TVoteDirectionWhether the current user has voted on the option and how.

Defined in

types/src/content/views/shared.ts:318


TSite

Ƭ TSite: Object

Item's linked site or article.

Type declaration

NameTypeDescription
namestringShort version of the linked site. Example nature.com
urlstringFull URL of the linked article. Example https://www.nature.com/articles/s41612-023-00427-x

Defined in

types/src/content/views/shared.ts:339


TStoryListItem

Ƭ TStoryListItem: Object

Single story item.

Remarks

Sample page: https://news.ycombinator.com/item?id=37371084

Type declaration

NameTypeDescription
ageTAgeWhen the story was created.
commentsCount?numberThe number of comments on the story.
id?stringThe Hacker News identifier. Example 37371084
interactionsPick<TInteractions, "hide" | "voteDown" | "voteUp">User interactions.
linksPick<TLinks, "favorite" | "flag" | "from" | "item" | "past" | "unflag">Links to other pages. Example item?id=37371084
score?numberThe story item's score.
site?TSiteInformation about the linked site.
title?stringThe story's title.
type?TStoryTypeType of story.
user?TUserUser that created the story.
voted?TVoteDirectionWhether the current user has voted on the story and how.

Defined in

types/src/content/views/shared.ts:383


TStoryType

Ƭ TStoryType: "article" | "ask" | "internal" | "job" | "launch" | "poll" | "show" | "tell"

The inferred story type.

Remarks

There's no way to tell for sure the type of story but we can try to make an estimated guess by looking at either its title or surrounding elements.

Descriptions:

  • article - Links to an article outside of HN
  • ask - "Ask HN" posts
  • internal - Links to an internal HN item page that does not fit any other type
  • job - Job posts
  • launch - "Launch HN" posts
  • poll - HN polls
  • show - "Show HN" posts
  • tell - "Tell HN" posts

Defined in

types/src/content/views/shared.ts:369


TUser

Ƭ TUser: Object

User that submitted an item.

Type declaration

NameTypeDescription
id?stringThe user's Hacker News identifier. Example pg
link?stringLink to the user's profile page. Example user?id=pg

Defined in

types/src/content/views/shared.ts:428


TView

Ƭ TView: "commentItem" | "commentList" | "jobItem" | "jobList" | "pollItem" | "reply" | "storyItem" | "storyList" | "submit" | "unknown" | "user"

Page categories. Check out routeViewMap for more information about how these are determined.

Remarks

Pages fall into one of three categories in Hacker News Pro: List, Item and Other. A List page shows a list of items such as the homepage or /jobs page. Item pages show detailed information about a particular item such as the comments page for a given submission. Another example of an item page might be a comment's reply page. You can discern item pages by their URL; they always begin with /item followed by a query string containing the item's identifier (i.e. /item?id=123456). Page types in the Other category describe any page that is not a List or Item such as the submission page /submit.

If a view resolves to unknown, then Hacker News Pro does not currently support it. An example of an unsupported page would be a user's profile page: /user?id=pg. It is the goal of Hacker News Pro to eventually support all pages. If you need one supported right away, don't hesitate to let us know by opening a feature request.

Defined in

types/src/content/views/shared.ts:463


TViewRoute

Ƭ TViewRoute: Object

Maps a route to a particular view.

Type declaration

NameTypeDescription
pathstringThe pathname to the given route. Example /news
viewTViewThe route's associated view. Example storyList

Defined in

types/src/content/views/shared.ts:477


TVoteDirection

Ƭ TVoteDirection: typeof voteDirections[number]

How an item may be voted upon.

Remarks

If undefined, the user has not yet voted. If they have, will be either up or down.

Defined in

types/src/content/views/shared.ts:497

Variables

routeViewMap

Const routeViewMap: Record<string, TView>

Map of routes and their related view.

Remarks

Most views can be determined by the page's pathname. For example, we can easily look at the homepage pathname of / and know it is a storyList view and we know /newcomments is always of type commentList. One exception are item types since they all begin with the same path of /item. For those, custom logic is needed that parses the page scraper result to come to a conclusion. See the getView method in the scraper package for how Hacker News Pro does this.

Defined in

types/src/content/views/shared.ts:19


voteDirections

Const voteDirections: readonly ["down", "up"]

How an item may be voted upon.

Defined in

types/src/content/views/shared.ts:47