Added string pre-processing step to indexing

This commit is contained in:
squidfunk 2017-01-24 23:25:49 +01:00
parent 23be61a803
commit aa8b3a6cf7
3 changed files with 39 additions and 9 deletions

View File

@ -31,7 +31,7 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block libs %} {% block libs %}
<script src="{{ base_url }}/assets/javascripts/modernizr-facb31f4a3.js"></script> <script src="{{ base_url }}/assets/javascripts/modernizr.js"></script>
{% endblock %} {% endblock %}
{% block fonts %} {% block fonts %}
{% include "partials/fonts.html" %} {% include "partials/fonts.html" %}
@ -105,7 +105,7 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% 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> <script>var config={url:{base:"{{ base_url }}"}},app=new Application(config);app.initialize()</script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>

View File

@ -150,6 +150,36 @@ export default class Application {
return doc 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() })).listen()
/* Listener: prevent touches on overlay if navigation is active */ /* Listener: prevent touches on overlay if navigation is active */