mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Truncate search results only for display
This commit is contained in:
parent
5e97b74471
commit
3222ec5a6e
File diff suppressed because one or more lines are too long
@ -36,7 +36,7 @@
|
|||||||
{% include "partials/fonts.html" %}
|
{% include "partials/fonts.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-39bc0c8cde.css">
|
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-90d5840206.css">
|
||||||
{% if config.extra.palette %}
|
{% if config.extra.palette %}
|
||||||
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-535e87ca3f.palette.css">
|
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-535e87ca3f.palette.css">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -110,7 +110,7 @@
|
|||||||
<script src="https://cdn.mathjax.org/{{ path }}"></script>
|
<script src="https://cdn.mathjax.org/{{ path }}"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<script src="{{ base_url }}/assets/javascripts/application-4e5ae02a0d.js"></script>
|
<script src="{{ base_url }}/assets/javascripts/application-7481d5412b.js"></script>
|
||||||
<script>
|
<script>
|
||||||
/* Configuration for application */
|
/* Configuration for application */
|
||||||
var config = {
|
var config = {
|
||||||
|
@ -81,19 +81,6 @@ export default class Application {
|
|||||||
: el.fireEvent(`on${event}`, document.createEventObject())
|
: el.fireEvent(`on${event}`, document.createEventObject())
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Truncate a string after the given number of characters - this is not
|
|
||||||
a reasonable approach, since the summaries kind of suck. It would be
|
|
||||||
better to create something more intelligent, highlighting the search
|
|
||||||
occurrences and making a better summary out of it */
|
|
||||||
const truncate = function(string, n) {
|
|
||||||
let i = n
|
|
||||||
if (string.length > i) {
|
|
||||||
while (string[i] !== " " && --i > 0);
|
|
||||||
return `${string.substring(0, i)}...`
|
|
||||||
}
|
|
||||||
return string
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Component: sidebar container */
|
/* Component: sidebar container */
|
||||||
if (!Modernizr.csscalc)
|
if (!Modernizr.csscalc)
|
||||||
new Material.Event.MatchMedia("(min-width: 960px)",
|
new Material.Event.MatchMedia("(min-width: 960px)",
|
||||||
@ -146,7 +133,6 @@ export default class Application {
|
|||||||
.then(data => {
|
.then(data => {
|
||||||
return data.docs.map(doc => {
|
return data.docs.map(doc => {
|
||||||
doc.location = this.config_.url.base + doc.location
|
doc.location = this.config_.url.base + doc.location
|
||||||
doc.text = truncate(doc.text, 140)
|
|
||||||
return doc
|
return doc
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -54,6 +54,19 @@ export default class Result {
|
|||||||
/* Inject created elements */
|
/* Inject created elements */
|
||||||
this.el_.appendChild(this.meta_)
|
this.el_.appendChild(this.meta_)
|
||||||
this.el_.appendChild(this.list_)
|
this.el_.appendChild(this.list_)
|
||||||
|
|
||||||
|
/* Truncate a string after the given number of characters - this is not
|
||||||
|
a reasonable approach, since the summaries kind of suck. It would be
|
||||||
|
better to create something more intelligent, highlighting the search
|
||||||
|
occurrences and making a better summary out of it */
|
||||||
|
this.truncate_ = function(string, n) {
|
||||||
|
let i = n
|
||||||
|
if (string.length > i) {
|
||||||
|
while (string[i] !== " " && --i > 0);
|
||||||
|
return `${string.substring(0, i)}...`
|
||||||
|
}
|
||||||
|
return string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,7 +122,7 @@ export default class Result {
|
|||||||
{doc.title}
|
{doc.title}
|
||||||
</h1>
|
</h1>
|
||||||
<p class="md-search-result__teaser">
|
<p class="md-search-result__teaser">
|
||||||
{doc.text}
|
{this.truncate_(doc.text, 140)}
|
||||||
</p>
|
</p>
|
||||||
</article>
|
</article>
|
||||||
</a>
|
</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user