Documentation
¶
Overview ¶
Command summary extracts a page's summary and stops reading as soon as it has one.
A summary is the meta description if the page has one, and otherwise the first paragraph of its own content - not the cookie notice in the header and not the strapline in the nav. Both of those are ordinary work. The interesting part is stopping.
A streaming rewriter has no "that is enough". The only way to stop it is to fail: a handler that returns an error ends the rewrite, and the error surfaces from the Write that was running. So the program returns a sentinel from the handler that completes the summary and treats it as success, which is worth being explicit about because it means the Writer is left poisoned and the output is truncated. For an extractor that writes to io.Discard and wants the text rather than the document, that is exactly right.
What it buys is measurable, and it is not "reads only the summary". The rewriter is fed by a copy loop with a buffer, and it stops at the first write after the summary is complete - so the bytes read are one buffer more than the summary needed, not one byte. On a 200 KB page whose first paragraph ends at byte 400: 32 KB read with io.Copy's default buffer, 4 KB with a 4 KB one, and 200 KB if the abort is left out. The buffer size is the knob, and the program takes it as a parameter for that reason.