Skip to content

Detection rules landing page ignores frontmatter in index.md #4697

Open

Description

@nastasha-solomon

What happened?

The detection rules extension builds the landing page of a detection rules docset, its index.md, from generated Markdown. It never reads the file's own contents. Because frontmatter is only read from the parsed document, any frontmatter in index.md is silently dropped, including mapped_pages.

  • DetectionRuleOverviewFile overrides GetMinimalParseDocumentAsync and GetParseDocumentAsync to parse the string returned by GetMarkdown(). That string starts with # Prebuilt detection rules reference and has no frontmatter.
  • MarkdownFile.ProcessYamlFrontMatter only reads frontmatter when the parsed document's first block is a YamlFrontMatterBlock. For this page it never is, so mapped_pages, description, and the other keys have no effect.

Impact: the Prebuilt detection rules reference can't list its 8.x equivalents (/guide/en/security/<version>/prebuilt-rules.html) in the version menu. That was requested in elastic/docs-content-internal#750.

How can we reproduce it?

  1. Add frontmatter to docs/index.md in elastic/detection-rules:
    ---
    mapped_pages:
      - https://www.elastic.co/guide/en/security/current/prebuilt-rules.html
    ---
  2. Build the docset.
  3. The generated reference/security/prebuilt-rules page has no legacy versions, and none of the frontmatter is applied.

Possible fix: in DetectionRuleOverviewFile.GetMarkdown(), put the frontmatter block from SourceFile, if there is one, in front of the generated Markdown. Both parser pipelines already call UseYamlFrontMatter(), so ProcessYamlFrontMatter would then pick it up.

Version or commit

main at e7b055b

Related

elastic/detection-rules#7138 adds the mapped_pages frontmatter above. It takes effect once this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions