Skip to content

Commit

Permalink
add custom layouts for themes
Browse files Browse the repository at this point in the history
  • Loading branch information
rojenzaman committed Apr 9, 2021
1 parent a8c71f7 commit f51d1cf
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
69 changes: 69 additions & 0 deletions layouts/_default/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{ define "main" }} <!-- https://gist.github.com/eddiewebb/735feb48f50f0ddd65ae5606a1cb41ae -->

<div class="search" style="padding-left: 10px;padding-right: 10px;min-height:500px;">
<header>
<h1>{{ .Title }}</h1>
{{/* partial "debugprint.html" (site.GetPage "/search") */}}
</header>

<!--
<form action="{{ .Permalink }}">
<input id="search-query" name="q"/>
</form>
-->

<br>

<div id="loader" class="center"></div>
<div id="search-results"></div>
</div>

<script>
var deletes = document.getElementById('loader');
setInterval(() => {
let searchResults = document.getElementById('search-results')
if (searchResults.textContent != '') deletes.remove()
}, 1000)
</script>

</div>

<template id="search-result-template"><div class="search_summary">
<h2 class="post-title no-text-decoration"><a class="search_link search_title" href=""></a></h2>
<p><em class="search_snippet"></em></p>
<small>
<table>
<tr class="search_iftags"><td><strong>Tags&nbsp;</strong></td><td class="search_tags"></td></tr>
<tr class="search_ifcategories"><td><strong>Categories&nbsp;</strong></td><td class="search_categories"></td></tr>
</table>
</small>
<br>
</div></template>
<!-- If you don't need IE 11 support you can remove this next script block -->
<script type="text/javascript">
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
if (window.navigator.userAgent.indexOf('Trident/') > 0) {
let urls = [
{{ "js/libs/iecompat/promises.min.js" | absURL }},
{{ "js/libs/iecompat/fetch.min.js" | absURL }},
{{ "js/libs/iecompat/template.min.js" | absURL }},
{{ "js/libs/iecompat/remove.min.js" | absURL }}
];
let head = document.getElementsByTagName("head")[0];
urls.forEach(function(url) {
let script = document.createElement("script");
script.src = url;
head.appendChild(script);
});
}
// @license-end
</script>
<!-- These are the two libraries needed for current browsers. -->
<script src={{ "js/libs/fuse.js/3.2.1/fuse.min.js" | absURL }}></script>
<script src={{ "js/libs/mark.js/9.0.0/mark.min.js" | absURL }}></script>

<!-- Below works *only if* this theme component is named "hugo-search-fuse-js"
AND *if* the themesDir is left at the default value of "themes". -->
{{ $search_js_md5 := (readFile "themes/hugo-search-fuse-js/static/js/search.js" | md5) }}
<script src={{ printf "%s?%s" ("js/search.js" | absURL) $search_js_md5 }}></script>
{{ end }}
23 changes: 23 additions & 0 deletions layouts/partials/navigation-items.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- $nav := . -}}
{{- if or $nav.showCategories $nav.showTags $nav.custom -}}
<div class="nav wrap"><nav class="nav">
<!-- Search input-->
<form action="{{- `/search/` | relLangURL -}}" class="nav item">
<input id="search-query" placeholder="Search.." name="q"/></form>
{{- if $nav.showCategories -}}
<a class="nav item" href="{{- `/categories/` | relLangURL -}}">{{- T "Categories" -}}</a>
{{- end -}}
{{- if $nav.showTags -}}
<a class="nav item" href="{{- `/tags/` | relLangURL -}}">{{- T "Tags" -}}</a>
{{- end -}}
{{- range $nav.custom -}}
{{- $url := replace .url "#" "%23" -}}
{{- $url = replace $url "." "%2e" -}}
{{- $url = $url | safeURL -}}
{{- if strings.HasPrefix $url "/" -}}{{- $url = $url | relLangURL -}}{{- end -}}
<a class="nav item" href="{{- $url -}}"
{{- if strings.HasPrefix $url "http" -}}target="_blank" rel="noopener noreferrer"
{{- end -}}>{{- .title -}}</a>
{{- end -}}
</nav></div>
{{- end -}}

0 comments on commit f51d1cf

Please sign in to comment.