mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-31 08:57:15 +00:00
feat: extract search out of header + use baseurl to search json index + add a step to explain how to use lunr-hugo + update perfect-scrollbar
This commit is contained in:
parent
102b4cea8d
commit
4218d1a27d
9 changed files with 27 additions and 23 deletions
|
@ -43,6 +43,11 @@ And set `search = true` in your config.toml
|
|||
|
||||
To generate your lunr index, you can see this project https://github.com/gwleclerc/lunr-hugo which parse your markdown files and extract toml and yaml headers to create index with corresponding format.
|
||||
|
||||
In order to generate the index of your static site launch the following comand after installing `lunr-hugo` using `npm`
|
||||
```
|
||||
lunr-hugo -i "<content directory>/**/*.md" -o static/json/search.json -l <header format (yaml or toml)>
|
||||
```
|
||||
|
||||
# TODO
|
||||
|
||||
- [Handling more than 2 levels in documentation](https://github.com/matcornic/hugo-theme-learn/issues/11)
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<div id="header-wrapper">
|
||||
<div id="header">
|
||||
{{ partial "logo.html" . }}
|
||||
</div>
|
||||
{{ if .Site.Params.search }}
|
||||
{{ partial "search.html" . }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="highlightable">
|
||||
|
|
|
@ -5,4 +5,7 @@
|
|||
</div>
|
||||
<script type="text/javascript" src="/js/lunr.min.js"></script>
|
||||
<script type="text/javascript" src="/js/horsey.js"></script>
|
||||
<script type="text/javascript">
|
||||
var baseurl = "{{ .Site.BaseURL }}";
|
||||
</script>
|
||||
<script type="text/javascript" src="/js/search.js"></script>
|
||||
|
|
|
@ -8,11 +8,8 @@
|
|||
background-color: #fff;
|
||||
color: #333;
|
||||
transition: left 0.1s ease-in-out;
|
||||
position: fixed;
|
||||
max-height: 70vh;
|
||||
overflow: auto;
|
||||
left: 17px !important;
|
||||
top: 135px !important;
|
||||
width: 265px;
|
||||
}
|
||||
.sey-show {
|
||||
|
|
4
static/css/perfect-scrollbar.min.css
vendored
4
static/css/perfect-scrollbar.min.css
vendored
|
@ -1,2 +1,2 @@
|
|||
/* perfect-scrollbar v0.6.10 */
|
||||
.ps-container{-ms-touch-action:none;touch-action:none;overflow:hidden !important;-ms-overflow-style:none}@supports (-ms-overflow-style: none){.ps-container{overflow:auto !important}}@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none){.ps-container{overflow:auto !important}}.ps-container.ps-active-x>.ps-scrollbar-x-rail,.ps-container.ps-active-y>.ps-scrollbar-y-rail{display:block;background-color:transparent}.ps-container.ps-in-scrolling{pointer-events:none}.ps-container.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail{background-color:#eee;opacity:0.9}.ps-container.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail>.ps-scrollbar-x{background-color:#999}.ps-container.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail{background-color:#eee;opacity:0.9}.ps-container.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail>.ps-scrollbar-y{background-color:#999}.ps-container>.ps-scrollbar-x-rail{display:none;position:absolute;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;opacity:0;-webkit-transition:background-color .2s linear, opacity .2s linear;-moz-transition:background-color .2s linear, opacity .2s linear;-o-transition:background-color .2s linear, opacity .2s linear;transition:background-color .2s linear, opacity .2s linear;bottom:3px;height:8px}.ps-container>.ps-scrollbar-x-rail>.ps-scrollbar-x{position:absolute;background-color:#aaa;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-transition:background-color .2s linear;-moz-transition:background-color .2s linear;-o-transition:background-color .2s linear;transition:background-color .2s linear;bottom:0;height:8px}.ps-container>.ps-scrollbar-y-rail{display:none;position:absolute;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;opacity:0;-webkit-transition:background-color .2s linear, opacity .2s linear;-moz-transition:background-color .2s linear, opacity .2s linear;-o-transition:background-color .2s linear, opacity .2s linear;transition:background-color .2s linear, opacity .2s linear;right:3px;width:8px}.ps-container>.ps-scrollbar-y-rail>.ps-scrollbar-y{position:absolute;background-color:#aaa;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;-webkit-transition:background-color .2s linear;-moz-transition:background-color .2s linear;-o-transition:background-color .2s linear;transition:background-color .2s linear;right:0;width:8px}.ps-container:hover.ps-in-scrolling{pointer-events:none}.ps-container:hover.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail{background-color:#eee;opacity:0.9}.ps-container:hover.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail>.ps-scrollbar-x{background-color:#999}.ps-container:hover.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail{background-color:#eee;opacity:0.9}.ps-container:hover.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail>.ps-scrollbar-y{background-color:#999}.ps-container:hover>.ps-scrollbar-x-rail,.ps-container:hover>.ps-scrollbar-y-rail{opacity:0.6}.ps-container:hover>.ps-scrollbar-x-rail:hover{background-color:#eee;opacity:0.9}.ps-container:hover>.ps-scrollbar-x-rail:hover>.ps-scrollbar-x{background-color:#999}.ps-container:hover>.ps-scrollbar-y-rail:hover{background-color:#eee;opacity:0.9}.ps-container:hover>.ps-scrollbar-y-rail:hover>.ps-scrollbar-y{background-color:#999}
|
||||
/* perfect-scrollbar v0.6.13 */
|
||||
.ps-container{-ms-touch-action:auto;touch-action:auto;overflow:hidden !important;-ms-overflow-style:none}@supports (-ms-overflow-style: none){.ps-container{overflow:auto !important}}@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none){.ps-container{overflow:auto !important}}.ps-container.ps-active-x>.ps-scrollbar-x-rail,.ps-container.ps-active-y>.ps-scrollbar-y-rail{display:block;background-color:transparent}.ps-container.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail{background-color:#eee;opacity:.9}.ps-container.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail>.ps-scrollbar-x{background-color:#999;height:11px}.ps-container.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail{background-color:#eee;opacity:.9}.ps-container.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail>.ps-scrollbar-y{background-color:#999;width:11px}.ps-container>.ps-scrollbar-x-rail{display:none;position:absolute;opacity:0;-webkit-transition:background-color .2s linear, opacity .2s linear;-o-transition:background-color .2s linear, opacity .2s linear;-moz-transition:background-color .2s linear, opacity .2s linear;transition:background-color .2s linear, opacity .2s linear;bottom:0px;height:15px}.ps-container>.ps-scrollbar-x-rail>.ps-scrollbar-x{position:absolute;background-color:#aaa;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, -webkit-border-radius .2s ease-in-out;transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, -webkit-border-radius .2s ease-in-out;-o-transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;-moz-transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out, -moz-border-radius .2s ease-in-out;transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out, -webkit-border-radius .2s ease-in-out, -moz-border-radius .2s ease-in-out;bottom:2px;height:6px}.ps-container>.ps-scrollbar-x-rail:hover>.ps-scrollbar-x,.ps-container>.ps-scrollbar-x-rail:active>.ps-scrollbar-x{height:11px}.ps-container>.ps-scrollbar-y-rail{display:none;position:absolute;opacity:0;-webkit-transition:background-color .2s linear, opacity .2s linear;-o-transition:background-color .2s linear, opacity .2s linear;-moz-transition:background-color .2s linear, opacity .2s linear;transition:background-color .2s linear, opacity .2s linear;right:0;width:15px}.ps-container>.ps-scrollbar-y-rail>.ps-scrollbar-y{position:absolute;background-color:#aaa;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;-webkit-transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, -webkit-border-radius .2s ease-in-out;transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, -webkit-border-radius .2s ease-in-out;-o-transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;-moz-transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out, -moz-border-radius .2s ease-in-out;transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out;transition:background-color .2s linear, height .2s linear, width .2s ease-in-out, border-radius .2s ease-in-out, -webkit-border-radius .2s ease-in-out, -moz-border-radius .2s ease-in-out;right:2px;width:6px}.ps-container>.ps-scrollbar-y-rail:hover>.ps-scrollbar-y,.ps-container>.ps-scrollbar-y-rail:active>.ps-scrollbar-y{width:11px}.ps-container:hover.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail{background-color:#eee;opacity:.9}.ps-container:hover.ps-in-scrolling.ps-x>.ps-scrollbar-x-rail>.ps-scrollbar-x{background-color:#999;height:11px}.ps-container:hover.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail{background-color:#eee;opacity:.9}.ps-container:hover.ps-in-scrolling.ps-y>.ps-scrollbar-y-rail>.ps-scrollbar-y{background-color:#999;width:11px}.ps-container:hover>.ps-scrollbar-x-rail,.ps-container:hover>.ps-scrollbar-y-rail{opacity:.6}.ps-container:hover>.ps-scrollbar-x-rail:hover{background-color:#eee;opacity:.9}.ps-container:hover>.ps-scrollbar-x-rail:hover>.ps-scrollbar-x{background-color:#999}.ps-container:hover>.ps-scrollbar-y-rail:hover{background-color:#eee;opacity:.9}.ps-container:hover>.ps-scrollbar-y-rail:hover>.ps-scrollbar-y{background-color:#999}
|
||||
|
|
|
@ -78,9 +78,6 @@ b, strong, label, th {
|
|||
#grav-logo path {
|
||||
fill: #fff !important;
|
||||
}
|
||||
#header {
|
||||
border-bottom: 4px solid #9c6fb6;
|
||||
}
|
||||
#sidebar {
|
||||
font-weight: 300 !important;
|
||||
}
|
||||
|
@ -99,10 +96,11 @@ textarea:focus, input[type="email"]:focus, input[type="number"]:focus, input[typ
|
|||
border-color: #00bdf3;
|
||||
box-shadow: inset 0 1px 3px rgba(0,0,0,.06),0 0 5px rgba(0,169,218,.7)
|
||||
}
|
||||
#header {
|
||||
#header-wrapper {
|
||||
background: #8451a1;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
border-bottom: 4px solid #9c6fb6;
|
||||
padding: 1rem;
|
||||
}
|
||||
#header a {
|
||||
|
@ -116,7 +114,7 @@ textarea:focus, input[type="email"]:focus, input[type="number"]:focus, input[typ
|
|||
fill: #fff;
|
||||
}
|
||||
.searchbox {
|
||||
margin-top: 0.5rem;
|
||||
margin-top: 1rem;
|
||||
position: relative;
|
||||
border: 1px solid #915eae;
|
||||
background: #764890;
|
||||
|
@ -805,7 +803,7 @@ td {
|
|||
border-right-color: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
.highlightable {
|
||||
padding: 25px 0 15px;
|
||||
padding: 1rem 0 1rem;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
}
|
||||
|
|
4
static/js/perfect-scrollbar.jquery.min.js
vendored
4
static/js/perfect-scrollbar.jquery.min.js
vendored
File diff suppressed because one or more lines are too long
4
static/js/perfect-scrollbar.min.js
vendored
4
static/js/perfect-scrollbar.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@ var lunrIndex, pagesIndex;
|
|||
// Initialize lunrjs using our generated index file
|
||||
function initLunr() {
|
||||
// First retrieve the index file
|
||||
$.getJSON("/json/search.json")
|
||||
$.getJSON(baseurl + "/json/search.json")
|
||||
.done(function(index) {
|
||||
pagesIndex = index;
|
||||
// Set up lunrjs by declaring the fields we use
|
||||
|
@ -50,7 +50,7 @@ function search(query) {
|
|||
// Let's get started
|
||||
initLunr();
|
||||
$( document ).ready(function() {
|
||||
horsey($("#search-by").get(0), {
|
||||
var horseyList = horsey($("#search-by").get(0), {
|
||||
suggestions: function (value, done) {
|
||||
var query = $("#search-by").val();
|
||||
var results = search(query);
|
||||
|
@ -81,4 +81,5 @@ $( document ).ready(function() {
|
|||
},
|
||||
limit: 10
|
||||
});
|
||||
horseyList.refreshPosition();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue