-
Notifications
You must be signed in to change notification settings - Fork 25.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimize JSON data #1449
Merged
Merged
Minimize JSON data #1449
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a51433a
Remove Lunr trimmer & bring back colons
nickgarlis 45914b2
Add Greek Stemmer
nickgarlis a66b729
Translate search_placeholder_text and results_found to Greek
nickgarlis 4d48c04
Merge from minimal-mistakes master
nickgarlis dbe8f15
Minimize JSON data
nickgarlis a9f72f7
Truncate Words
nickgarlis 6ee4710
Move store variable into a new file
nickgarlis feabd8f
Move Lunr files into a new folder
nickgarlis 6b31795
Add defer to lunr scripts
nickgarlis bf06657
Add search_full_content switch
nickgarlis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
layout: null | ||
--- | ||
|
||
var store = [ | ||
{% for c in site.collections %} | ||
{% if forloop.last %} | ||
{% assign l = true %} | ||
{% endif %} | ||
{% assign docs = c.docs | where_exp:'doc','doc.search != false' %} | ||
{% for doc in docs %} | ||
{% if doc.header.teaser %} | ||
{% capture teaser %}{{ doc.header.teaser }}{% endcapture %} | ||
{% else %} | ||
{% assign teaser = site.teaser %} | ||
{% endif %} | ||
{ | ||
"title": {{ doc.title | jsonify }}, | ||
"excerpt": {{ doc.content | strip_html | strip_newlines | jsonify }}, | ||
"categories": {{ doc.categories | jsonify }}, | ||
"tags": {{ doc.tags | jsonify }}, | ||
"url": {{ doc.url | absolute_url | jsonify }}, | ||
"teaser": | ||
{% if teaser contains "://" %} | ||
{{ teaser | jsonify }} | ||
{% else %} | ||
{{ teaser | absolute_url | jsonify }} | ||
{% endif %} | ||
}{% unless forloop.last and l %},{% endunless %} | ||
{% endfor %} | ||
{% endfor %}] |
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth adding
defer
to each of these three scripts to give priority to the other page content loading first.eg.
<script defer src="{{ '/assets/js/lunr/lunr-...js' | absolute_url }}"></script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm great idea! We could also use liquid to decide whether to truncate or not based on the number of posts there are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea of truncating based on the number of posts. Not sure what a good baseline should be. Guess it really depends on the the size of
{{ content }}
.In the case of the MM demo site, the documentation pages are pretty big and full of words.
Maybe we default to truncating (can probably up it to well over 50 words) and then have an override setting in
_config.yml
to index the full post. If the user wants to take the potential hit to page load perf they can.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like:
<!-- lunr-store.js --> {% if site.search_full_content == true %} {% assign excerpt = doc.content | strip_html | strip_newlines | jsonify %} {% else %} {% assign excerpt = doc.content | strip_html | truncatewords: 20 | jsonify %} {% endif %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is a safe zone parameter which gets activated when there are over a thousand posts and its default size is set to 50 but can also be modified to be lower or higher ? If that's too complicated then we could have some pre-set parameters like: safe which would be somewhere in the 50s and super-safe which would be 20.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not convinced post count is the way to go, way too unreliable. I could have 2,000 posts with a sentence of text each or have a couple hundred with epic word counts going over 10,000 and get a huge
lunar-store.js
because it falls below the threshold.I think truncating the content to around 50 words by default, with a config override to turn that off would be sensible. If someone wants to get more granular with the amount of words truncated they override the theme file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it really depends on the individual. The switch is great option too since it's more straight forward if the user has too much content they simply turn off the search_full_content parameter.