File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ window . addEventListener ( "DOMContentLoaded" , _ => {
2+ const MutationObserver = window . MutationObserver || window . WebKitMutationObserver ;
3+ const observer = new MutationObserver ( ( mutations , _ ) => {
4+ const nodesForRemoval = [ ] ;
5+ for ( const record of mutations ) {
6+ for ( const liNode of record . addedNodes ) {
7+ let removeNode = false ;
8+ for ( const anchor of liNode . querySelectorAll ( "a" ) ) {
9+ const searchResultLocale = getSearchResultLocaleFromAnchor ( anchor ) ;
10+ const isSearchResultFromCurrentPageLocale = searchResultLocale === document . querySelector ( 'html[lang]' ) . lang ;
11+ if ( ! isSearchResultFromCurrentPageLocale ) {
12+ removeNode = true ;
13+ continue ;
14+ }
15+ }
16+
17+ if ( removeNode ) {
18+ nodesForRemoval . push ( liNode ) ;
19+ }
20+ }
21+ }
22+
23+ for ( const node of nodesForRemoval ) {
24+ node . remove ( ) ;
25+ }
26+
27+ const amountDisplay = document . querySelector ( ".md-search-result__meta" ) ;
28+ const result = document . querySelector ( '.md-search-result__list' ) . childNodes . length
29+ amountDisplay . textContent = amountDisplay . textContent . replace ( / \d + / i, result . toString ( ) ) ;
30+ } ) ;
31+
32+ observer . observe ( document . querySelector ( ".md-search-result__list" ) , { childList : true } ) ;
33+ } ) ;
34+
35+ function getSearchResultLocaleFromAnchor ( anchor ) {
36+ const localeSegment = anchor . href . split ( "/" ) [ 3 ] ;
37+ // Note that we make an assumption here that the only length 2
38+ // link segments will be the locale immediately after the site's base URL.
39+ return ( localeSegment . length === 2 || localeSegment . length === 5 || localeSegment . length === 7 ) ? localeSegment : 'en' ;
40+ }
Original file line number Diff line number Diff line change 3838extra_css :
3939 - stylesheets/extra.css
4040
41+ extra_javascript :
42+ - scripts/extra.js
43+
4144markdown_extensions :
4245 - abbr
4346 - attr_list
You can’t perform that action at this time.
0 commit comments