Browse Source

Update 2 files

- /_layouts/default.html
- /search.html
mayx 1 year ago
parent
commit
550321e80a
2 changed files with 13 additions and 1 deletions
  1. 12 0
      _layouts/default.html
  2. 1 1
      search.html

+ 12 - 0
_layouts/default.html

@@ -27,6 +27,18 @@
 
   gtag('config', '{{ site.google_analytics }}');
   var lastUpdated = new Date("{{ site.time | date: "%FT%T%z" }}");
+  function getSearchJSON(callback) {
+    var searchData = JSON.parse(localStorage.getItem(lastUpdated));
+    if (!searchData) {
+      localStorage.clear();
+      $.getJSON("search.json", function (data) {
+          localStorage.setItem(lastUpdated, JSON.stringify(data));
+          callback(data);
+      });
+    } else {
+      callback(searchData);
+    }
+  }
   </script>
   {% endif %}
   <style>

+ 1 - 1
search.html

@@ -27,7 +27,7 @@ var status = false;
 if(mykeyword != null && mykeyword.toString().length>1){
      sbox.value = mykeyword;
 }
-$.getJSON("search.json", function(json){
+getSearchJSON(function(json){
   var sjs = SimpleJekyllSearch({
      searchInput: sbox,
      resultsContainer: document.getElementById('results-container'),