Finding Content
Search, indexes, maps and switchable views that help a reader find a page on a large site, and the data each one needs.
Several ways in
Readers look for a page in different ways. One knows a word in it. One knows the subject. One knows who wrote it, or that it was new last week, or that they had it open yesterday. A site with many pages should offer more than one of these routes.
Each route is one component. They fall into three groups by where their data comes from, and that decides what you have to build.
The site index is one JSON file with a record per page. Page Metadata describes its shape. The library reads it and does not write it.
One list, several views
<content-lens> holds several of these components and shows one at a time, with a row of buttons to switch. Give it the address of the site index once in data-lens-src and it passes that to each child that has no source of its own.
<content-lens data-lens-default="topic" data-lens-src="/pages.json"> <topic-map data-lens-name="topic" data-lens-label="By topic" data-heading-level="0"></topic-map> <author-index data-lens-name="author" data-lens-label="By author"></author-index> <trust-filter data-lens-name="trust" data-lens-label="By review"></trust-filter> <recently-visited data-lens-name="recent" data-lens-label="Recently visited" data-heading-level="0"></recently-visited></content-lens>
- Each child needs
data-lens-name. data-lens-label sets the button text. Without it the name is used.
data-lens-default names the view shown first. The reader's last choice is kept for the browser session and wins on a return visit.
data-heading-level="0" removes a child's own heading where the button already names it. <topic-map>, <recently-visited> and <popularity-index> accept it.
- Every child also works alone, outside
<content-lens>, with its own data-lens-src.
Search
<site-search> is the dialog and the keyboard handling for Pagefind, a search that runs in the browser against an index of static files. The component does not create the index. Run Pagefind over your built site as the last build step.
<site-search> <button type="button" data-trigger> <icon-wc name="search"></icon-wc> Search </button></site-search>
The button opens a modal dialog. Ctrl + K (Command + K on a Mac) opens it from anywhere on the page. Arrow keys move through the results and Enter follows one.
The component loads /pagefind/pagefind.js. If your site is served from a sub-path, set data-pagefind-path to the folder that holds that file. When the index is missing, the dialog says that search is unavailable.
Indexes you write
Three components improve a list that is already in the page. The list is plain links, so it works without script and search engines can follow it. The component adds the controls.
| Component | You write | It adds |
<site-index> |
An alphabetical list of terms, each with links to the pages that cover it |
A filter box, a row of letters to jump by, and an optional limit per letter with a show more control |
<site-map> |
A nested list of the site's pages |
A mark on the current page (current takes its path), with its branch opened, and controls to expand or collapse every branch. A second mode, mode="ia-tree", turns the list into a tree or chart with page-type and status badges, for planning a site's structure. |
<time-index> |
A changelog: a list of dated entries |
Relative dates, a newest-first or oldest-first control, and with versions a filter by version |
<site-index> and <site-map> can also take their content from a JSON file through src, which replaces the list in the page. <time-index> can add a recently updated pages
list from a JSON file named in updates-src.
Views of the site index
These three fetch the site index and build their display from it.
<author-index> groups pages under each author, with a filter box. sort="count" puts the most prolific author first. If you write a list inside it, that list is shown when the fetch fails.
<topic-map> shows pages as a tree of subjects. It needs a second file, the vocabulary (/vocabulary.json unless you set data-vocabulary-src), which lists each concept's @id, its skos:prefLabel and its broader or narrower concepts. A page appears under every id in its concepts array.
<trust-filter> filters pages by how they were made, what review they had, their status and whether they carry a signature. Ticking two values in one group widens the list. Ticking values in two groups narrows it. Has signature
means a signature is declared in the index. Only <page-info>, on the page itself, checks one.
Views of reader activity
<recently-visited> lists pages this reader has opened. The history is kept in the browser's local storage and is never sent anywhere. A page is recorded only if it has <meta name="vb:track-history" content="on"> or contains the component. The panel gives the reader controls to pause recording and to clear the list. data-vb-no-track on <html> turns recording off for the site.
<popularity-index> lists the most visited pages. It fetches /api/analytics/popular, or the address in analytics-src, and expects { "pages": [{ "url", "title", "views" }] }. You run that endpoint. When it does not answer, the component sets data-state="unavailable" on itself, so one rule can hide the panel.
popularity-index[data-state="unavailable"] { display: none; }