Skip to main content

Module previews

Module previews 

Source
Expand description

What a web page says of itself, for showing under a note that links to it: its title, a few words about it, and a picture.

Pages say this in the meta tags of their head, most of them as Open Graph (og:title, og:description, og:image), which is what other clients and every chat program read. Only the head is fetched and read, with a tokenizer: nothing of the page is run, laid out or kept.

A link that answers as a video, where a page was asked for, is one the address did not give away: the answer is Linked::Video, and the row offers to play it (see crate::video).

A YouTube video is asked what it is called the short way (see Video::about): its page says so too, most of a megabyte in.

A view asks the PreviewStore for the preview of an address, as it asks for pictures (see Requests): the app hears of it as a Message::LoadPreview. A page is asked once in a run, whatever it answers. There is no disk cache.

Addresses come from whoever wrote a note. They are fetched as everything is (see crate::http): the page’s server sees the request, as the server of a note’s picture does.

StructsΒ§

LinkPreview
What a web page says of itself.
PreviewStore
What the pages asked about so far say of themselves, by address. See the module docs.
Said πŸ”’
What the head of a page says of the page, as it was found: each thing said the way most trusted to be meant for sharing. A lower rank is more trusted, and among equals the first one said stands.

EnumsΒ§

Linked
What a link a note took for a page turned out to be.
PreviewState
What the store has to say about the preview of a page.

ConstantsΒ§

DESCRIPTION_MAX_CHARS πŸ”’
MAX_ABOUT_BYTES πŸ”’
How much of what YouTube answers about a video is read: it is a few hundred bytes.
MAX_HEAD_BYTES πŸ”’
How much of a page is read looking for the end of its head. Most heads end within a few thousand bytes; some sites put a megabyte of script before what they say of themselves.
MAX_IN_FLIGHT πŸ”’
How many pages may be on their way at once, and how many requests may wait between a view asking and the app answering.
REQUEST_QUEUE πŸ”’
TITLE_MAX_CHARS πŸ”’
How many characters of a title and of a description are kept: more than a preview has room to show.

FunctionsΒ§

fetch
Fetch the head of the page at url and read what the page says of itself; or hear that it is a video, and fetch none of it.
one_line πŸ”’
text as one line: runs of blank space and line breaks made one space, none at either end, and max_chars characters at most. None if that leaves nothing, or if the text was not read as it was written: a page that is not in UTF-8 says nothing rather than something garbled.
parse
What the page at url says of itself in html, which is its head, or starts with it. None if it gives itself no title: there is nothing to call it by.