Excerpt Wyam.Html

Finds the first occurrence of a specified HTML comment or element and stores it's contents as metadata.
This module is useful for situations like displaying the first paragraph of your most recent blog posts or generating RSS and Atom feeds. This module looks for the first occurrence of an excerpt separator (default of more or excerpt) contained within an HTML comment (<!--more-->). If a separator comment isn't found, the module will fallback to looking for the first occurrence of a specific HTML element (p paragraph elements by default) and will use the outer HTML content. In both cases, the excerpt is placed in metadata with a key of Excerpt. The content of the original input document is left unchanged.

Package

This module exists in the Wyam.Html package which is not part of the core distribution. Add the following preprocessor directive to your configuration file to use it:
#n Wyam.Html

Usage

  • Excerpt()

    Creates the module with the default query selector of p.

  • Excerpt(string querySelector)

    Specifies an alternate query selector for the content.

    • querySelector

      The query selector to use.

  • Excerpt(string[] separators)

    Specifies alternate separators to be used in an HTML comment. Setting this to null will disable looking for separators and rely only on the query selector.

    • separators

      The excerpt separators.

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • WithMetadataKey(string metadataKey)

    Allows you to specify an alternate metadata key.

    • metadataKey

      The metadata key to store the excerpt in.

  • WithOuterHtml(bool outerHtml)

    Controls whether the inner HTML (not including the containing element's HTML) or outer HTML (including the containing element's HTML) of the first result from the query selector is added to metadata. The default is true, which gets the outer HTML content. This setting has no effect if a separator comment is found.

    • outerHtml

      If set to true, outer HTML will be stored.

  • WithQuerySelector(string querySelector)

    Allows you to specify an alternate query selector. If a separator comment was found then the query selector will be used to determine which elements prior to the separator the excerpt should be taken from.

    • querySelector

      The query selector to use.

  • WithSeparators(string[] separators)

    Specifies alternate separators to be used in an HTML comment. Setting this to null will disable looking for separators and rely only on the query selector.

    • separators

      The excerpt separators.

Output Metadata

The metadata values listed below apply to individual documents and are created and set by the module as indicated in their descriptions.

  • HtmlKeys.Excerpt: System.String

    Contains the content of the first result from the query selector (unless an alternate metadata key is specified).

GitHub