Indexing HTML & Markdown Files

Stork will parse HTML files using a browser-grade HTML parser, extracting content from tags, scripts, and styles.

However, your HTML likely has more content than you actually want indexed. The very page you're looking at has a header and a footer, and if Stork indexed the text in the header and footer as part of each document, you would be able to search for "questions or comments" and get every page in your results, since it's in the footer of every page.

When parsing a file, Stork will look for a container tag, identified by a CSS selector, that it should use to look for searchable contents. By default, this is the <main> tag.

If you don't want to use the <main> tag, you can change the default for all your HTML files in your Stork configuration. The html_selector configuration option controls the container tag Stork will look for. For example, in this configuration file:

base_directory = "html/"
html_selector = "article.main-contents"
files = [
{path = "federalist-1.html", url = "/federalist-1/", title = "Introduction"},
{path = "federalist-2.html", url = "/federalist-2/", title = "Concerning Dangers from Foreign Force and Influence"},
{path = "federalist-3.html", url = "/federalist-3/", title = "Concerning Dangers from Foreign Force and Influence 2"}

Stork will index only the body of the article in the following HTML document:

<!doctype html>
<header> <!-- header contents --> </header>
<aside> <!-- header contents --> </aside>
<h1>The First Federalist Paper</h1>
<div class="related-papers"> <!-- Links to other papers --> </div>
<article class="main-contents">
<p>This is the content that will get indexed by Stork.</p>
<p>Nothing in the header, the aside, the h1, or the
related papers div will get indexed.</p>

Stork works best if you give it plain prose. You might want to strip away certain tags like code blocks, SVGs, or other elements that will get dynamically replaced by Javascript before generating your index.

If you want to override the container tag for any individual file, pass in the html_selector_override configuration option in the file array:

base_directory = "html/"
html_selector = "article.main-contents"
path = "federalist-1.html"
url = "TheFederalistPapers-1"
title = "Introduction"
html_selector_override = "#inner-contents"
path = "federalist-2.txt"
url = "TheFederalistPapers-2"
title = "Concerning Dangers from Foreign Force and Influence"

Was this page helpful?

If you see an issue, please file a bug!

© 2019–2023. Stork is maintained by James Little, who's really excited that you're checking it out.

This site is open source. Please file a bug or open a PR if you see something confusing or incorrect.

Logo art by Bruno Monts, with special thanks to the team. Please contact James Little before using the logo for anything.