Skip to content
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

Search #18

Merged
merged 5 commits into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,28 @@ $ git clone https://github.com/matcornic/hugo-theme-learn.git
- Automatic table of contents
- Create buttons (typically used to provide a link to a demo)

# Search
To use the `search` functionality, you just have to put a `lunr` index which respects this format :
```json
[
{
"uri": "/docs/01-start/index",
"title": "Get started",
"content": "\n\nGet started\n\nAll you need to know...\n",
"tags": ["start", "intro"]
},
...
]
```

into a `static/json/search.json` file in your hugo project.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a full example step by step to use this lib here ?


# TODO

- [Handling more than 2 levels in documentation](https://github.com/matcornic/hugo-theme-learn/issues/11)
- [Search in site](https://github.com/matcornic/hugo-theme-learn/issues/12)
- [Handling videos](https://github.com/matcornic/hugo-theme-learn/issues/13)
- [Add optional button to create doc issue (like github)](https://github.com/matcornic/hugo-theme-learn/issues/14)
1 change: 0 additions & 1 deletion layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
</div>
<script src="/js/jquery-2.x.min.js"></script>
<script src="/js/clipboard.min.js"></script>
<script src="/js/perfect-scrollbar.min.js"></script>
<script src="/js/perfect-scrollbar.jquery.min.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
<link href="/css/hybrid.css" rel="stylesheet">
<link href="/css/featherlight.min.css" rel="stylesheet">
<link href="/css/perfect-scrollbar.min.css" rel="stylesheet">
<link href="/css/horsey.css" rel="stylesheet">
<link href="/css/theme.css" rel="stylesheet">
<link href="/css/hugo-theme.css" rel="stylesheet">
<script src="/js/jquery-2.x.min.js"></script>
<style type="text/css">:root #header + #content > #left > #rlblock_left
{display:none !important;}</style>
{{ partial "style.html" . }}
Expand Down
6 changes: 1 addition & 5 deletions layouts/partials/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
<div id="header">
{{ partial "logo.html" . }}
{{ if .Site.Params.search }}
<div class="searchbox">
<label for="search-by"><i class="fa fa-search"></i></label>
<input id="search-by" type="text" placeholder="Search Documentation" data-search-input="/lunr.json/query">
<span data-search-clear=""><i class="fa fa-close"></i></span>
</div>
{{ partial "search.html" . }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more flexible if {{ partial "search.html" . }} is not in header class, like :

<nav id="sidebar">
  <div id="header-wrapper">
    <div id="header">
      {{ partial "logo.html" . }}
    </div>
    {{ if .Site.Params.search }}
      {{ partial "search.html" . }}
    {{ end }}
</div>

{{ end }}
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions layouts/partials/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="searchbox">
<label for="search-by"><i class="fa fa-search"></i></label>
<input id="search-by" type="text" placeholder="Search">
<span data-search-clear=""><i class="fa fa-close"></i></span>
</div>
<script type="text/javascript" src="/js/lunr.min.js"></script>
<script type="text/javascript" src="/js/horsey.js"></script>
<script type="text/javascript" src="/js/search.js"></script>
38 changes: 38 additions & 0 deletions static/css/horsey.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.sey-list {
display: none;
position: absolute;
padding: 0;
margin: 0;
list-style-type: none;
box-shadow: 1px 2px 6px;
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 {
display: block;
}
.sey-hide {
display: none;
}
.sey-item {
cursor: pointer;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding: 7px;
}
.sey-item:hover {
background-color: #444;
color: #fff;
}
.sey-selected {
background-color: #333;
color: #fff;
}
12 changes: 10 additions & 2 deletions static/css/theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading