mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Added string pre-processing step to indexing
This commit is contained in:
parent
23be61a803
commit
aa8b3a6cf7
File diff suppressed because one or more lines are too long
@ -31,7 +31,7 @@
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block libs %}
|
||||
<script src="{{ base_url }}/assets/javascripts/modernizr-facb31f4a3.js"></script>
|
||||
<script src="{{ base_url }}/assets/javascripts/modernizr.js"></script>
|
||||
{% endblock %}
|
||||
{% block fonts %}
|
||||
{% include "partials/fonts.html" %}
|
||||
@ -105,7 +105,7 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script src="{{ base_url }}/assets/javascripts/application-de6db8382f.js"></script>
|
||||
<script src="{{ base_url }}/assets/javascripts/application-35227ad8ac.js"></script>
|
||||
<script>var config={url:{base:"{{ base_url }}"}},app=new Application(config);app.initialize()</script>
|
||||
{% for path in extra_javascript %}
|
||||
<script src="{{ path }}"></script>
|
||||
|
@ -150,6 +150,36 @@ export default class Application {
|
||||
return doc
|
||||
})
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
/*
|
||||
* The MkDocs search index provides all pages as specified in the
|
||||
* mkdocs.yml in order with an entry for the content of the whole
|
||||
* page followed by separate entries for all subsections also in
|
||||
* order of appearance.
|
||||
*/
|
||||
|
||||
// 1. Reduce docs so that useless entries are not included, using a
|
||||
// quick spliting hack - only one test is necessary.
|
||||
const reduced = data.reduce((docs, doc) => {
|
||||
if (docs.length && doc.location.split(
|
||||
docs[docs.length - 1].location).length > 1)
|
||||
docs.pop()
|
||||
return docs.concat(doc)
|
||||
}, [])
|
||||
|
||||
// 2. Trim texts
|
||||
const trimmed = reduced.map(doc => {
|
||||
doc.text = doc.text
|
||||
.replace(/\n/g, " ") /* Remove newlines */
|
||||
.replace(/\s+/g, " ") /* Compact whitespace */
|
||||
.replace(/\s+([,.:;!?])/g, /* Correct punctuation */
|
||||
(_, char) => char)
|
||||
return doc
|
||||
})
|
||||
|
||||
return trimmed
|
||||
})
|
||||
})).listen()
|
||||
|
||||
/* Listener: prevent touches on overlay if navigation is active */
|
||||
|
Loading…
Reference in New Issue
Block a user