diff --git a/docs/blog/2021/excluding-content-from-search.md b/docs/blog/2021/excluding-content-from-search.md
index 3d784d9b0..2c355715d 100644
--- a/docs/blog/2021/excluding-content-from-search.md
+++ b/docs/blog/2021/excluding-content-from-search.md
@@ -3,7 +3,6 @@ template: overrides/main.html
description: >
Three new simple ways to exclude dedicated parts of a document from the search
index, allowing for more fine-grained control
-disqus: mkdocs-material
search:
exclude: true
---
@@ -15,7 +14,7 @@ dedicated parts of a document from the search index, allowing for more
fine-grained control.__
- [1]: https://avatars.githubusercontent.com/u/932156
+ [@squidfunk avatar]: https://avatars.githubusercontent.com/u/932156
---
Two weeks ago, Material for MkDocs Insiders shipped a [brand new search
-plugin][2], yielding [massive improvements in usability][3], but also in [speed
-and size][4] of the search index. Interestingly, as discussed in the previous
+plugin], yielding [massive improvements in usability], but also in [speed
+and size] of the search index. Interestingly, as discussed in the previous
blog article, we only scratched the surface of what's now possible. This
release brings some useful features that enhance the writing experience,
allowing for more fine-grained control of what pages, sections and blocks of a
@@ -39,18 +38,18 @@ Markdown file should be indexed by the built-in search functionality.
_The following section discusses existing solutions for excluding pages and
sections from the search index. If you immediately want to learn what's new,
-skip to the [section just after that][5]._
+skip to the [section just after that][what's new]._
- [2]: search-better-faster-smaller.md
- [3]: search-better-faster-smaller.md#whats-new
- [4]: search-better-faster-smaller.md#benchmarks
- [5]: #whats-new
+ [brand new search plugin]: search-better-faster-smaller.md
+ [massive improvements in usability]: search-better-faster-smaller.md#whats-new
+ [speed and size]: search-better-faster-smaller.md#benchmarks
+ [what's new]: #whats-new
## Prior art
-MkDocs has a rich and thriving ecosystem of [plugins][6], and it comes as no
+MkDocs has a rich and thriving ecosystem of [plugins], and it comes as no
surprise that there's already a fantastic plugin by @chrieke to exclude specific
-sections of a Markdown file – the [mkdocs-exclude-search][7] plugin. It can be
+sections of a Markdown file – the [mkdocs-exclude-search] plugin. It can be
installed with:
```
@@ -78,10 +77,10 @@ adds support for advanced filtering techniques like infix- and suffix-filtering
using wildcards. While this is a very powerful idea, it comes with some
downsides:
-1. __Exclusion patterns and content are not co-located__: exclusion patterns
- need to be defined in `mkdocs.yml`, and not as part of the respective
- document or section to be excluded. This might result in stale exclusion
- patterns, leading to unintended behavior:
+1. __Exclusion patterns and content are not co-located__: exclusion patterns
+ need to be defined in `mkdocs.yml`, and not as part of the respective
+ document or section to be excluded. This might result in stale exclusion
+ patterns, leading to unintended behavior:
- When a headline is changed, its slug (permalink) also changes, which might
suddenly match (or unmatch) a pattern, e.g., when an author fixes a typo
@@ -97,23 +96,23 @@ downsides:
pages and sections have been excluded from the search index, but MkDocs will
now flood the terminal with debug output from its core and other plugins.
-2. __Exclusion control might be too coarse__: The [mkdocs-exclude-search][7]
- plugin only allows for the exclusion of pages and sections. It's not possible
- to exclude parts of a section, e.g., content that is irrelevant to search but
- must be included as part of the documentation.
+2. __Exclusion control might be too coarse__: The [mkdocs-exclude-search]
+ plugin only allows for the exclusion of pages and sections. It's not
+ possible to exclude parts of a section, e.g., content that is irrelevant
+ to search but must be included as part of the documentation.
- [6]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins
- [7]: https://github.com/chrieke/mkdocs-exclude-search
+ [plugins]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins
+ [mkdocs-exclude-search]: https://github.com/chrieke/mkdocs-exclude-search
## What's new?
The latest Insiders release brings fine-grained control for [__excluding pages,
-sections, and blocks__][8] from the search index, implemented through front
-matter, as well as the [Attribute List][9] extension. Note that it doesn't
-replace the [mkdocs-exclude-search][7] plugin but _complements_ it.
+sections, and blocks__][search exclusion] from the search index, implemented
+through front matter, as well as the [Attribute Lists]. Note that it doesn't
+replace the [mkdocs-exclude-search] plugin but __complements__ it.
- [8]: ../../setup/setting-up-site-search.md#search-exclusion
- [9]: https://python-markdown.github.io/extensions/attr_list/
+ [search exclusion]: ../../setup/setting-up-site-search.md#search-exclusion
+ [Attribute Lists]: ../../setup/extensions/python-markdown.md#attribute-lists
### Excluding pages
@@ -134,12 +133,12 @@ search:
### Excluding sections
-If a section should be excluded, the author can use the [Attribute List][9]
+If a section should be excluded, the author can use the [Attribute Lists]
extension to add a __pragma__ called `{ data-search-exclude }` at the end of a
heading. The pragma is not included in the final HTML, as search pragmas are
filtered by the search plugin before the page is rendered:
-=== "`docs/page.md`"
+=== ":octicons-file-code-16: docs/page.md"
``` markdown
# Document title
@@ -153,7 +152,7 @@ filtered by the search plugin before the page is rendered:
The content of this section is excluded
```
-=== "`search_index.json`"
+=== ":octicons-codescan-16: search_index.json"
``` json
{
@@ -176,10 +175,10 @@ filtered by the search plugin before the page is rendered:
### Excluding blocks
If even more fine-grained control is desired, the __pragma__ can be added to
-any [block-level element][10] or [inline-level element][11] that is officially
-supported by the [Attribute List][9] extension:
+any [block-level element] or [inline-level element] that is officially
+supported by the [Attribute Lists] extension:
-=== "`docs/page.md`"
+=== ":octicons-file-code-16: docs/page.md"
``` markdown
# Document title
@@ -190,7 +189,7 @@ supported by the [Attribute List][9] extension:
{ data-search-exclude }
```
-=== "`search_index.json`"
+=== ":octicons-codescan-16: search_index.json"
``` json
{
@@ -205,12 +204,12 @@ supported by the [Attribute List][9] extension:
}
```
- [10]: https://python-markdown.github.io/extensions/attr_list/#block-level
- [11]: https://python-markdown.github.io/extensions/attr_list/#inline-level
+ [block-level element]: https://python-markdown.github.io/extensions/attr_list/#block-level
+ [inline-level element]: https://python-markdown.github.io/extensions/attr_list/#inline
## Conclusion
The latest release brings three simple ways to control more precisely what goes
into the search index and what doesn't. It complements the already very powerful
-[mkdocs-exclude-search][7] plugin, allowing for new methods of shaping the
+[mkdocs-exclude-search] plugin, allowing for new methods of shaping the
structure, size and content of the search index.
diff --git a/docs/blog/2021/search-better-faster-smaller.md b/docs/blog/2021/search-better-faster-smaller.md
index fa2c3099f..4984293e8 100644
--- a/docs/blog/2021/search-better-faster-smaller.md
+++ b/docs/blog/2021/search-better-faster-smaller.md
@@ -3,7 +3,6 @@ template: overrides/main.html
description: >
How we rebuilt client-side search, delivering a better user experience while
making it faster and smaller at the same time
-disqus: mkdocs-material
search:
exclude: true
---
@@ -15,7 +14,7 @@ delivering a significantly better user experience while making it faster and
smaller at the same time.__
- [1]: https://avatars.githubusercontent.com/u/932156
+ [@squidfunk avatar]: https://avatars.githubusercontent.com/u/932156
---
-The [search][2] of Material for MkDocs is by far one of its best and most-loved
-assets: [multilingual][3], [offline-capable][4], and most importantly: _all
+The [search] of Material for MkDocs is by far one of its best and most-loved
+assets: [multilingual], [offline-capable], and most importantly: _all
client-side_. It provides a solution to empower the users of your documentation
to find what they're searching for instantly without the headache of managing
additional servers. However, even though several iterations have been made,
@@ -41,19 +40,19 @@ version, and what's about to come.
_The next section discusses the architecture and issues of the current search
implementation. If you immediately want to learn what's new, skip to the
-[section just after that][5]._
+[section just after that][what's new]._
- [2]: ../../setup/setting-up-site-search.md
- [3]: ../../setup/setting-up-site-search.md#lang
- [4]: ../../setup/setting-up-site-search.md#offline-search
- [5]: #whats-new
+ [search]: ../../setup/setting-up-site-search.md
+ [multilingual]: ../../setup/setting-up-site-search.md#lang
+ [offline-capable]: ../../setup/setting-up-site-search.md#offline-search
+ [what's new]: #whats-new
## Architecture
-Material for MkDocs uses [lunr][6] together with [lunr-languages][7] to
-implement its client-side search capabilities. When a documentation page is
-loaded and JavaScript is available, the search index as generated by the
-[built-in search plugin][8] during the build process is requested from the
+Material for MkDocs uses [lunr] together with [lunr-languages] to implement
+its client-side search capabilities. When a documentation page is loaded and
+JavaScript is available, the search index as generated by the
+[built-in search plugin] during the build process is requested from the
server:
``` ts
@@ -64,9 +63,9 @@ const index$ = document.forms.namedItem("search")
: NEVER
```
- [6]: https://lunrjs.com
- [7]: https://github.com/MihaiValentin/lunr-languages
- [8]: ../../setup/setting-up-site-search.md#built-in-search
+ [lunr]: https://lunrjs.com
+ [lunr-languages]: https://github.com/MihaiValentin/lunr-languages
+ [built-in search plugin]: ../../setup/setting-up-site-search.md#built-in-search
### Search index
@@ -76,7 +75,7 @@ the original Markdown file:
??? example "Expand to inspect example"
- === "`docs/page.md`"
+ === ":octicons-file-code-16: docs/page.md"
```` markdown
# Example
@@ -106,7 +105,7 @@ the original Markdown file:
* Profit!
````
- === "`search_index.json`"
+ === ":octicons-codescan-16: search_index.json"
``` json
{
@@ -146,15 +145,15 @@ the original Markdown file:
If we inspect the search index, we immediately see several problems:
- 1. __All content is included twice__: the search index contains one entry
- with the entire contents of the page, and one entry for each section of
- the page, i.e., each block preceded by a headline or subheadline. This
- significantly contributes to the size of the search index.
+ 1. __All content is included twice__: the search index contains one entry
+ with the entire contents of the page, and one entry for each section of
+ the page, i.e., each block preceded by a headline or subheadline. This
+ significantly contributes to the size of the search index.
- 2. __All structure is lost__: when the search index is built, all structural
- information like HTML tags and attributes are stripped from the content.
- While this approach works well for paragraphs and inline formatting, it
- might be problematic for lists and code blocks. An excerpt:
+ 2. __All structure is lost__: when the search index is built, all structural
+ information like HTML tags and attributes are stripped from the content.
+ While this approach works well for paragraphs and inline formatting, it
+ might be problematic for lists and code blocks. An excerpt:
```
… links , or even code : if (isAwesome) { … } Lists Sometimes you want …
@@ -172,51 +171,52 @@ If we inspect the search index, we immediately see several problems:
It's not difficult to see that it can be quite challenging to implement a good
search experience for theme authors, which is why Material for MkDocs (up to
-now) did some [monkey patching][9] to be able to render slightly more
+now) did some [monkey patching] to be able to render slightly more
meaningful search previews.
+ [monkey patching]: https://github.com/squidfunk/mkdocs-material/blob/ec7ccd2b2d15dd033740f388912f7be7738feec2/src/assets/javascripts/integrations/search/document/index.ts#L68-L71
+
### Search worker
The actual search functionality is implemented as part of a web worker[^1],
-which creates and manages the [lunr][6] search index. When search is
-initialized, the following steps are taken:
+which creates and manages the [lunr] search index. When search is initialized,
+the following steps are taken:
[^1]:
- Prior to [version 5.0][10], search was carried out in the main thread which
- locked up the browser, rendering it unusable. This problem was first
+ Prior to :octicons-tag-24: 5.0.0, search was carried out in the main thread
+ which locked up the browser, rendering it unusable. This problem was first
reported in #904 and, after some back and forth, fixed and released in
- version 5.0.
+ :octicons-tag-24: 5.0.0.
-1. __Linking sections with pages__: The search index is parsed, and each section
- is linked to its parent page. The parent page itself is _not indexed_, as it
- would lead to duplicate results, so only the sections remain. Linking is
- necessary, as search results are grouped by page.
+1. __Linking sections with pages__: The search index is parsed, and each
+ section is linked to its parent page. The parent page itself is _not
+ indexed_, as it would lead to duplicate results, so only the sections
+ remain. Linking is necessary, as search results are grouped by page.
-2. __Tokenization__: The `title` and `text` values of each section are split
- into tokens by using the [separator][11] as configured in `mkdocs.yml`.
- Tokenization itself is carried out by [lunr's default tokenizer][12], which
- doesn't allow for lookahead or separators spanning multiple characters.
+2. __Tokenization__: The `title` and `text` values of each section are split
+ into tokens by using the [separator] as configured in `mkdocs.yml`.
+ Tokenization itself is carried out by
+ [lunr's default tokenizer][default tokenizer], which doesn't allow for
+ lookahead or separators spanning multiple characters.
> Why is this important and a big deal? We will see later how much more we
> can achieve with a tokenizer that is capable of separating strings with
> lookahead.
-3. __Indexing__: As a final step, each section is indexed. When querying the
- index, if a search query includes one of the tokens as returned by step 2.,
- the section is considered to be part of the search result and passed to the
- main thread.
+1. __Indexing__: As a final step, each section is indexed. When querying the
+ index, if a search query includes one of the tokens as returned by step 2.,
+ the section is considered to be part of the search result and passed to the
+ main thread.
Now, that's basically how the search worker operates. Sure, there's a little
-more magic involved, e.g., search results are [post-processed][13] and
-[rescored][14] to account for some shortcomings of [lunr][6], but in general,
-this is how data gets into and out of the index.
+more magic involved, e.g., search results are [post-processed] and [rescored] to
+account for some shortcomings of [lunr], but in general, this is how data gets
+into and out of the index.
- [9]: https://github.com/squidfunk/mkdocs-material/blob/ec7ccd2b2d15dd033740f388912f7be7738feec2/src/assets/javascripts/integrations/search/document/index.ts#L68-L71
- [10]: https://squidfunk.github.io/mkdocs-material/upgrading/#upgrading-from-4x-to-5x
- [11]: ../../setup/setting-up-site-search.md#separator
- [12]: https://github.com/olivernn/lunr.js/blob/aa5a878f62a6bba1e8e5b95714899e17e8150b38/lunr.js#L413-L456
- [13]: https://github.com/squidfunk/mkdocs-material/blob/ec7ccd2b2d15dd033740f388912f7be7738feec2/src/assets/javascripts/integrations/search/_/index.ts#L249-L272
- [14]: https://github.com/squidfunk/mkdocs-material/blob/ec7ccd2b2d15dd033740f388912f7be7738feec2/src/assets/javascripts/integrations/search/_/index.ts#L274-L275
+ [separator]: ../../setup/setting-up-site-search.md#separator
+ [default tokenizer]: https://github.com/olivernn/lunr.js/blob/aa5a878f62a6bba1e8e5b95714899e17e8150b38/lunr.js#L413-L456
+ [post-processed]: https://github.com/squidfunk/mkdocs-material/blob/ec7ccd2b2d15dd033740f388912f7be7738feec2/src/assets/javascripts/integrations/search/_/index.ts#L249-L272
+ [rescored]: https://github.com/squidfunk/mkdocs-material/blob/ec7ccd2b2d15dd033740f388912f7be7738feec2/src/assets/javascripts/integrations/search/_/index.ts#L274-L275
### Search previews
@@ -228,11 +228,11 @@ experience.
This is where the current search preview generation falls short, as some of the
search previews appear not to include any occurrence of any of the search
terms. This was due to the fact that search previews were [truncated after a
-maximum of 320 characters][15], as can be seen here:
+maximum of 320 characters][truncated], as can be seen here: