diff options
author | Rohan Verma <hello@rohanverma.net> | 2020-05-19 19:02:00 +0300 |
---|---|---|
committer | Rohan Verma <hello@rohanverma.net> | 2020-05-19 19:02:00 +0300 |
commit | 04502390cda6d3c2575587bfd2d6cb7c27e236c0 (patch) | |
tree | 68010ea0538432765fbfe0ca34f4f7ecdcfe0ee8 |
Initial commit
28 files changed, 839 insertions, 0 deletions
@@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2020 Rohan Verma + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/archetypes/default.md b/archetypes/default.md new file mode 100644 index 0000000..ac36e06 --- /dev/null +++ b/archetypes/default.md @@ -0,0 +1,2 @@ ++++ ++++ diff --git a/content/search.md b/content/search.md new file mode 100644 index 0000000..9f30562 --- /dev/null +++ b/content/search.md @@ -0,0 +1,51 @@ +--- +title: "Search Results" +sitemap: + priority : 0.1 +layout: "search" +--- + + +This file exists solely to respond to /search URL with the related `search` layout template. + +No content shown here is rendered, all content is based in the template layouts/page/search.html + +Setting a very low sitemap priority will tell search engines this is not important content. + +This implementation uses Fusejs, jquery and mark.js + + +## Initial setup + +Search depends on additional output content type of JSON in config.toml +\``` +[outputs] + home = ["HTML", "JSON"] +\``` + +## Searching additional fileds + +To search additional fields defined in front matter, you must add it in 2 places. + +### Edit layouts/_default/index.JSON +This exposes the values in /index.json +i.e. add `category` +\``` +... + "contents":{{ .Content | plainify | jsonify }} + {{ if .Params.tags }}, + "tags":{{ .Params.tags | jsonify }}{{end}}, + "categories" : {{ .Params.categories | jsonify }}, +... +\``` + +### Edit fuse.js options to Search +`static/js/search.js` +\``` +keys: [ + "title", + "contents", + "tags", + "categories" +] +\``` diff --git a/layouts/404.html b/layouts/404.html new file mode 100644 index 0000000..07595dc --- /dev/null +++ b/layouts/404.html @@ -0,0 +1,3 @@ +{{ define "main" }} +Page not found +{{ end }} diff --git a/layouts/_default/article.html b/layouts/_default/article.html new file mode 100644 index 0000000..5850f89 --- /dev/null +++ b/layouts/_default/article.html @@ -0,0 +1,27 @@ +{{ define "main" }} + <article> + <h1>{{ .Title }}</h1> + <div> + {{ .Content }} + </div> + {{ with .Params.tags }} + <div> + <ul id="tags"> + {{ range . }} + <li><a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a></li> + {{ end }} + </ul> + </div> + {{ end }} + {{ with .Site.DisqusShortname }} + <div> + {{ template "_internal/disqus.html" . }} + </div> + {{ end }} + {{ with .Site.Params.CommentoSrc }} + <div> + {{ partial "commento.html" . }} + </div> + {{ end }} + </article> +{{ end }} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html new file mode 100644 index 0000000..6e78e08 --- /dev/null +++ b/layouts/_default/baseof.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> + +<html> + + <head> + {{ partial "header.html" . }} + </head> + + <body> + {{ partial "head.html" . }} + {{ partial "menu.html" . }} + <div id="content"> + {{ partial "nav.html" . }} + <div id="main"> + {{- block "main" . }}{{- end }} + {{ partial "footer.html" . }} + </div> + {{- block "footerfiles" . }}{{- end }} + + {{ if and .Site.Params.fathomAnalytics .Site.Params.fathomAnalytics.siteID }} + {{- partial "fathom" . -}} + {{ end }} + </body> + +</html> diff --git a/layouts/_default/index.json b/layouts/_default/index.json new file mode 100644 index 0000000..c93f805 --- /dev/null +++ b/layouts/_default/index.json @@ -0,0 +1,5 @@ +{{- $.Scratch.Add "index" slice -}} +{{- range .Site.RegularPages -}} + {{- $.Scratch.Add "index" (dict "title" .Title "tags" .Params.tags "categories" .Params.categories "contents" .Plain "permalink" .Permalink) -}} +{{- end -}} +{{- $.Scratch.Get "index" | jsonify -}} diff --git a/layouts/_default/list.html b/layouts/_default/list.html new file mode 100644 index 0000000..efbc993 --- /dev/null +++ b/layouts/_default/list.html @@ -0,0 +1,24 @@ +{{ define "main" }} + {{ if or .Title .Content }} + <div> + {{ with .Title }}<h1>{{ . }}</h1>{{ end }} + {{ with .Content }}<div>{{ . }}</div>{{ end }} + </div> + {{ end }} + + {{ $pages := .RegularPages }} + + {{ if .Sections }} + {{ range $section := .Sections }} + {{ $pages = union $pages $section.Pages }} + {{ end }} + {{ end }} + + {{ range (.Paginate $pages).Pages }} + {{ partial "list_preview" . }} + {{ end }} + + {{ if len $pages }} + {{ partial "pagination.html" . }} + {{ end }} +{{ end }} diff --git a/layouts/_default/search.html b/layouts/_default/search.html new file mode 100644 index 0000000..318de3f --- /dev/null +++ b/layouts/_default/search.html @@ -0,0 +1,27 @@ +{{ define "footerfiles" }} +<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> +<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.2.0/fuse.min.js"></script> +<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js"></script> +<script src="{{ "js/search.js" | absURL }}"></script> +{{ end }} +{{ define "main" }} +<section class="resume-section p-3 p-lg-5 d-flex flex-column"> + <div class="my-auto" > + <form action="{{ "search" | absURL }}"> + <input id="search-query" name="s" placeholder="press enter to search"/> + </form> + <div id="search-results"> + <h3>Matching pages</h3> + </div> + </div> +</section> +<!-- this template is sucked in by search.js and appended to the search-results div above. So editing here will adjust style --> +<script id="search-result-template" type="text/x-js-template"> + <div id="summary-${key}"> + <h4><a href="${link}">${title}</a></h4> + <p>${snippet}</p> + ${ isset tags }<p>Tags: ${tags}</p>${ end } + ${ isset categories }<p>Categories: ${categories}</p>${ end } + </div> +</script> +{{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html new file mode 100644 index 0000000..01be996 --- /dev/null +++ b/layouts/_default/single.html @@ -0,0 +1,35 @@ +{{ define "main" }} + <article> + <h1>{{ .Title }}</h1> + <div class="small right"> + {{ partial "addtoany.html" . }} + </div> + {{ partial "display_meta.html" . }} + <hr> + + <div> + {{ .Content }} + </div> + </article> + {{ $related := .Site.RegularPages.Related . | first 5 }} + {{ with $related }} + <h3>See Also</h3> + <ul class="small"> + {{- range . }} + <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li> + {{ end }} + </ul> + {{ end }} + + {{ with .Site.DisqusShortname }} + <div> + {{ template "_internal/disqus.html" . }} + </div> + {{ end }} + {{ with .Site.Params.CommentoSrc }} + <div> + {{ partial "commento.html" . }} + </div> + {{ end }} + +{{ end }} diff --git a/layouts/_default/terms.html b/layouts/_default/terms.html new file mode 100644 index 0000000..ab87373 --- /dev/null +++ b/layouts/_default/terms.html @@ -0,0 +1,18 @@ +{{ define "main" }} + {{ if or .Title .Content }} + <div> + {{ with .Title }}<h1>{{ . }}</h1>{{ end }} + {{ with .Content }}<div>{{ . }}</div>{{ end }} + </div> + {{ end }} + + <div> + <ul> + {{ range $key, $value := .Data.Terms }} + <li> + <a href="{{ $key | urlize }}">{{ $key }}</a> ({{ len $value }}) + </li> + {{ end }} + </ul> + </div> +{{ end }} diff --git a/layouts/index.html b/layouts/index.html new file mode 100644 index 0000000..7a75399 --- /dev/null +++ b/layouts/index.html @@ -0,0 +1,11 @@ +{{ define "main" }} +{{ if .Content }} +{{ .Content }} +{{ else }} +{{ $paginator := .Paginate (where .Site.RegularPages "Type" "in" .Site.Params.mainSections) }} +{{ range $paginator.Pages }} +{{ partial "list_preview" . }} +{{ end }} +{{ partial "pagination.html" . }} +{{ end }} +{{ end }} diff --git a/layouts/partials/addtoany.html b/layouts/partials/addtoany.html new file mode 100644 index 0000000..a6e1f88 --- /dev/null +++ b/layouts/partials/addtoany.html @@ -0,0 +1,7 @@ +<a style="margin-right:2px;" class="u-url no-underline" + href="https://www.addtoany.com/share#url={{ .Permalink }}{{ with .Title }}&title={{ . }}{{ end }}"> + <svg style="margin-bottom: -3px" class="i-external" viewBox="0 0 32 32" width="16" height="16" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"> + <path d="M14 9 L3 9 3 29 23 29 23 18 M18 4 L28 4 28 14 M28 4 L14 18"></path> + </svg> + Share +</a> diff --git a/layouts/partials/commento.html b/layouts/partials/commento.html new file mode 100644 index 0000000..a690f3e --- /dev/null +++ b/layouts/partials/commento.html @@ -0,0 +1,3 @@ +<div id="commento"></div> +<script src="{{ . }}"></script> + diff --git a/layouts/partials/display_meta.html b/layouts/partials/display_meta.html new file mode 100644 index 0000000..1e8de6f --- /dev/null +++ b/layouts/partials/display_meta.html @@ -0,0 +1,18 @@ +<div class="light"> + <span>{{ dateFormat "02 Jan 2006" $.Date }}</span> - + <span>{{ .ReadingTime }} minute read</span> +</div> +<div class="small"> + {{ with .Params.categories }} + categories: + {{ range . }} + <a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> + {{ end }} + {{ end }} + {{ with .Params.tags }} + tags: + {{ range . }} + <a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> + {{ end }} + {{ end }} +</div> diff --git a/layouts/partials/fathom.html b/layouts/partials/fathom.html new file mode 100644 index 0000000..13e7cfc --- /dev/null +++ b/layouts/partials/fathom.html @@ -0,0 +1,13 @@ +<script> +(function(f, a, t, h, o, m){ + a[h]=a[h]||function(){ + (a[h].q=a[h].q||[]).push(arguments) + }; + o=f.createElement('script'), + m=f.getElementsByTagName('script')[0]; + o.async=1; o.src=t; o.id='fathom-script'; + m.parentNode.insertBefore(o,m) +})(document, window, '//{{ .Site.Params.fathomAnalytics.serverURL | default "cdn.usefathom.com" }}/tracker.js', 'fathom'); +fathom('set', 'siteId', '{{ .Site.Params.fathomAnalytics.siteID }}'); +fathom('trackPageview'); +</script> diff --git a/layouts/partials/favicon.html b/layouts/partials/favicon.html new file mode 100644 index 0000000..9804ef4 --- /dev/null +++ b/layouts/partials/favicon.html @@ -0,0 +1 @@ +<link rel="icon" sizes="any" href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAACnUlEQVRIx6XVzWtcVRjH8c/cebkJOq1gNDi1WJLWpC9YmqAUpVDRRQUXUruy1FURRP+AlLbYQB18W7vwD1BcqLjoQrSYbSHWRhiJxJQgdNTErDSTXNOZ62JeMve20zLxWVwuz/Oc7znneX7nHP6nZRAYkt/G2E1/aeQw5KzfEqHQkyoaXZ7AQfM2E1l7fGIZdjmTYu/wupzAiFNetUcg54wHUms/axe5e2zuJe8aR8WUmTvicXtpvWzYBYeFQhMueqRXWm/AqP2d/0NG+gds+LfzH1nvH/CLq60+NHzj115pvYv4j4v+9rzYdz60dm9AwY6Et2hQ0bILhvGHqOXJJrIKW4AxryRCgyZEKSFNikWJrL1bgIpPUyuIfKbe5cmKfaWmaExowYrYwBag4XYCUNdQT/ka6kZddlxexaV2iYM+Ds+g804astOzynbfr413WsmxTv4hT/UPiNv63zoJ/QGqZjqd+cmN+wnpbuIuC72gYM60W92AIAXKClKiycnKWvKWfQoWrQqaq28OPOi1RPqASVJCOirXOV6jYNyVNmDeF3hQSaRqU1HsS3WDSmJVG7JyvlZTUJJXtUbzhsq1rseaZ5wzYd0VH6iJ1Iw675jYjLIlkZqdppwQmlV2vXlDtvf+mI88J4MRt72PostOCvCEgrdRMOVNOez2kNPJNj5tUqZVrpcNY8zxVjTwon0oOdGaMOOoI0nAQFfVQ/nOt31wC8gLu/oUJgFzljoau+ZPLKh00ucsomq2o8DFdrQNWDBtXmTNt95Tw4pLZm1Yd820Vawp+15N5GfvuJlUYsPnfnDAuh8tKyJ21SmHxW641ZroutOOCFXcbKskg0e94ffUZbXXfEpI4xZST9vjPrbSfFwf3ubjupqYZHv2HylrtUljNvuGAAAAAElFTkSuQmCC"> diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html new file mode 100644 index 0000000..7127a9e --- /dev/null +++ b/layouts/partials/footer.html @@ -0,0 +1,9 @@ +<div id="footer" class="light small"> +© 2019 - {{ .Site.Params.Author }}. +{{ with .Site.Params.FooterMessage }} +<br> +{{ . }} +<br> +{{ end }} +This page was generated using the <a href="">Bodhi</a> theme for Hugo. +</div> diff --git a/layouts/partials/head.html b/layouts/partials/head.html new file mode 100644 index 0000000..8497dfe --- /dev/null +++ b/layouts/partials/head.html @@ -0,0 +1,14 @@ +<div id="header"> + {{ if .Site.Params.Avatar }} + <div class="avatar"> + <a href="{{ .Site.BaseURL }}"> + <img src="{{ .Site.Params.Avatar }}" alt="{{ .Site.Title }}" /> + </a> + </div> + {{ end }} + <a id="headerLink" href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a> + {{- if isset .Site.Params "subtitle" -}} + <span class="hidden"> - </span> + <span id="headerSubtitle">{{ .Site.Params.Subtitle | markdownify }}</span> + {{- end -}} +</div> diff --git a/layouts/partials/header.html b/layouts/partials/header.html new file mode 100644 index 0000000..519bffe --- /dev/null +++ b/layouts/partials/header.html @@ -0,0 +1,30 @@ +<meta charset="utf-8"/> + +{{- $title := ( .Title ) -}} +{{- $siteTitle := ( .Site.Title ) -}} +{{ if .IsHome -}} + <title>{{ $siteTitle }}{{ if isset .Site.Params "subtitle" }} - {{ .Site.Params.Subtitle }}{{ end }} </title> +{{ else -}} + <title>{{ $title }} - {{ $siteTitle }}</title> +{{ end -}} + +{{ if isset .Site.Params "favicon" -}} + <link rel="icon" type="image/png" href={{ .Site.Params.favicon }} /> +{{ end -}} + +{{ with .OutputFormats.Get "rss" -}} +{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{ end -}} + +{{- template "_internal/opengraph.html" . -}} +{{- template "_internal/twitter_cards.html" . -}} +{{- template "_internal/schema.html" . -}} + +<meta name="viewport" content="width=device-width, initial-scale=1"> + +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha256-l85OmPOjvil/SOvVt3HnSSjzF1TUMyT9eV0c2BzEGzU=" crossorigin="anonymous" /> +<link rel="stylesheet" type="text/css" href="/css/style.css"/> +<link href="https://fonts.googleapis.com/css?family=Inter" rel="stylesheet"> +<link href="https://fonts.googleapis.com/css?family=Source+Serif+Pro" rel="stylesheet" type="text/css"> + +{{ partial "favicon.html" . }} diff --git a/layouts/partials/list_preview.html b/layouts/partials/list_preview.html new file mode 100644 index 0000000..7adae6b --- /dev/null +++ b/layouts/partials/list_preview.html @@ -0,0 +1,15 @@ +<h2> + <a href="{{ .RelPermalink }}">{{.Title}}{{ if .Draft }}<sup class="draft-label">DRAFT</sup>{{ end }}</a> +</h2> + +{{ if in (slice "single" "") .Layout }} +{{ partial "display_meta.html" . }} +{{ end }} + +<div> +{{ if isset .Params "description" }} + {{ .Description }} +{{ else }} + {{ .Summary }} +{{ end }} +</div> diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html new file mode 100644 index 0000000..9d06d38 --- /dev/null +++ b/layouts/partials/menu.html @@ -0,0 +1,18 @@ +<div id="menu"> + {{ $currentPage := . }} + {{ range .Site.Menus.main_left }} + {{if eq $currentPage.URL .URL }}<b>{{end}} + <a href="{{ .URL }}">{{ .Name }}</a> + {{if eq $currentPage.URL .URL }}</b>{{end}} + {{ end }} + <span class="right"> + {{ range .Site.Menus.main_right }} + {{if eq $currentPage.URL .URL }}<b>{{end}} + <a href="{{ .URL }}">{{ .Name }}</a> + {{if eq $currentPage.URL .URL }}</b>{{end}} + {{ end }} + {{if eq $currentPage.URL "/search/" }}<b>{{end}} + <a href="/search">search <svg aria-hidden="true" class="i-search" viewBox="0 0 32 32" width="10" height="10" fill="none" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"><circle cx="14" cy="14" r="12"></circle><path d="M23 23l7 7"></path></svg></a> + {{if eq $currentPage.URL "/search/" }}</b>{{end}} + </span> +</div> diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html new file mode 100644 index 0000000..d227c0b --- /dev/null +++ b/layouts/partials/nav.html @@ -0,0 +1,39 @@ +<div id="nav"> + <ul> + {{ $currentPage := . }} + + {{ range .Site.Menus.nav }} + {{ $menuentry := . }} + {{ $menuPage := $.Site.GetPage $menuentry.URL }} + {{ if .HasChildren }} + <li> + {{ if eq $currentPage $menuPage }}<b>{{ end }} + <a href="{{.URL}}"> + <span>{{ .Name }} /</span> + </a> + {{ if eq $currentPage $menuPage }}</b>{{ end }} + <ul class="sub-menu"> + {{ range .Children }} + {{ $menuChildPage := $.Site.GetPage .URL }} + + <li> + {{ if eq $currentPage $menuChildPage }}<b>{{ end }} + <a href="{{ .URL }}">{{ .Name }}</a> + {{ if eq $currentPage $menuChildPage }}</b>{{ end }} + </li> + {{ end }} + </ul> + </li> + </ul> + {{ else }} + <li> + {{ if eq $currentPage $menuPage }}<b>{{ end }} + <a href="{{ .URL }}"> + <span>{{ .Name }}</span> + </a> + {{ if eq $currentPage $menuPage }}</b>{{ end }} + </li> + {{ end }} + {{ end }} + </ul> +</div> diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html new file mode 100644 index 0000000..cad506d --- /dev/null +++ b/layouts/partials/pagination.html @@ -0,0 +1,13 @@ +<div id="pagination"> +{{ if .Paginator.HasPrev }} +<a href="{{ .Paginator.Prev.URL }}"><</a> +{{ else }} +< +{{ end }} +{{ .Paginator.PageNumber }} of {{ .Paginator.TotalPages }} +{{ if .Paginator.HasNext }} + <a href="{{ .Paginator.Next.URL }}">></a> +{{ else }} +> +{{ end }} +</div> diff --git a/layouts/section/archive.html b/layouts/section/archive.html new file mode 100644 index 0000000..dc5a397 --- /dev/null +++ b/layouts/section/archive.html @@ -0,0 +1,34 @@ +{{ define "main" }} +{{ with .Title }} +<h1>{{.}}</h1> +{{ end }} +{{ $prev := 3000}} +{{range .Site.RegularPages}} +{{if .Date}} +{{if gt $prev (.Date.Format "2006")}} +{{ if ne $prev 3000}} +</tbody> +</table> +{{ end }} +<table class="all-posts"> + <col width="15%"> + <col width="85%"> + <thead> + <tr><th></th><th> + {{$dt := .Date.Format "2006" }} + <a href="/blog/{{$dt}}"> + {{ $dt }} + </a> + </th></tr> + </thead> + <tbody> + {{end}} + <tr> + <th>{{.Date.Format "02 Jan"}}</th> + <td><a href="{{.Permalink}}">{{.Title}}</a> {{if .Draft}}(draft){{end}}</td> + </tr> + {{ $prev = .Date.Format "2006"}} + {{end}} + {{end}} +</table> +{{ end }} diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..d79d52e --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,253 @@ +/**/ +/* Style Sheet for Bodhi*/ +/* Forked from: https://suckless.org/pub/style.css + */ + +html { + height: 100%; + margin: 0; +} + +body { + background-color: #fff; + color: #000; + font-family: "Inter", sans-serif; + padding: 0; + margin: 0; + height: 100%; + line-height: 1.6em; + font-size: 17px; +} + +.small { + font-size: 13px; +} + +pre, code { + margin: 0; +} + +a { + color: #005386; +} + +#header a, #nav a, #menu a { + text-decoration: none; +} + +#nav a:hover { + background-color: #ddd; +} + +#menu { + clear: both; + color: #1a9900; + overflow: hidden; + background-color: #557515; + padding: 0.7ex; + border-top: 1px solid #ccc; + border-bottom: 1px solid #1a9900; +} + +#menu a { + padding: 0.5ex 1ex; + color: #fff; +} + +#menu a:hover { + background-color: #1a9900; +} + +#header { + background-color: #eee; + clear: both; + color: #555; + font-size: 1.78em; + padding: 0.7ex 0.7ex 0.7ex 0.7em; +} + +#headerLink { + color: #109166; + margin-left: 5px; +} + +h1, h2, h3, h4, h5, h6 { + font-family: "Source Serif Pro", serif; +} + +h1 { + margin: 1em 1ex 0.5ex 0; + font-size: 1.4em; +} + +h2 { + margin: 1em 1ex 0.5ex 0; + font-size: 1.3em; +} + +h3 { + margin: 1em 1ex 0.5ex 0; + font-size: 1.0em; +} + +h4 { + margin: 1em 1ex 0.5ex 0; + font-size: 0.9em; +} + +#headerSubtitle { + font-size: 0.75em; + font-style: italic; +} + +#content { + clear: both; + margin: 0; + padding: 0; + height: 100%; + display: flex; + flex-direction: row; +} + +#nav { + float: left; + margin: 0 1px 0 0; + padding: 1em 0; + width: 200px; +} + +#nav ul { + margin: 0; + padding: 0; +} + +#nav li { + list-style: none; + padding: 0; + margin: 0; +} + +#nav li ul { + padding-left: 0.6em !important; +} + +#nav li a { + display: block; + margin: 0; + padding: 0.8ex 2em 0.8ex 1em; +} + +#main { + min-height: 100%; + margin: 0 0 0 10px; + max-width: 50em; + padding: 1.5em; + border-left: 1px solid rgba(0, 0, 0, 0.1); + display: flex; + flex-direction: column; +} + +.left { + float: left; + margin: 0; + padding: 0; +} + +.right { + float: right; + margin: 0; + padding: 0; +} + +.hidden { + display: none; +} + +div.avatar { + height: 32px; + float: left; +} + +.avatar img { + width: auto; + height: auto; + max-width: 100%; + max-height: 100%; +} + +table { + -ms-overflow-style: -ms-autohiding-scrollbar; + -webkit-overflow-scrolling: touch; + background-color: transparent; + margin-bottom: 1rem; + overflow-x: auto; + width: 100%; +} + + + +table { + width:100%; + border-collapse:collapse; + margin:1.75rem 0; + color:#778087 +} +table td, +table th { + vertical-align:top; + border:1px solid #ccc; + padding:10px +} +table thead th { + font-size:10px +} +table tbody td:first-child { + font-weight:700; + color:#333; +} + +pre { + margin-bottom: 0; + margin-top: 0; + padding: 20px; + overflow-x: auto; +} + +.light { + color: #646464; +} + +#pagination { + margin-top: 1em; +} + +#footer { + padding-top: 50px; + margin-top: auto; +} + +hr { + border: 0; + height: 0; + border-top: 1px solid rgba(0, 0, 0, 0.1); +} + +img { + max-width: 100%; +} + +@media only screen and (max-width:632px) { + #content { + flex-direction: column; + } + + #main { + border-left: 0px solid rgba(0, 0, 0, 0.1); + padding: 0.5em; + } + + #nav { + width: 100%; + border-bottom: 1px solid rgba(0,0,0,0.1); + } +} diff --git a/static/js/search.js b/static/js/search.js new file mode 100644 index 0000000..8ce5537 --- /dev/null +++ b/static/js/search.js @@ -0,0 +1,109 @@ +summaryInclude=60; +var fuseOptions = { + shouldSort: true, + includeMatches: true, + threshold: 0.0, + tokenize:true, + location: 0, + distance: 100, + maxPatternLength: 32, + minMatchCharLength: 1, + keys: [ + {name:"title",weight:0.8}, + {name:"contents",weight:0.5}, + {name:"tags",weight:0.3}, + {name:"categories",weight:0.3} + ] +}; + + +var searchQuery = param("s"); +if(searchQuery){ + $("#search-query").val(searchQuery); + executeSearch(searchQuery); +}else { + $('#search-results').append("<p>Please enter a word or phrase above</p>"); +} + + + +function executeSearch(searchQuery){ + $.getJSON( "/index.json", function( data ) { + var pages = data; + var fuse = new Fuse(pages, fuseOptions); + var result = fuse.search(searchQuery); + console.log({"matches":result}); + if(result.length > 0){ + populateResults(result); + }else{ + $('#search-results').append("<p>No matches found</p>"); + } + }); +} + +function populateResults(result){ + $.each(result,function(key,value){ + var contents= value.item.contents; + var snippet = ""; + var snippetHighlights=[]; + var tags =[]; + if( fuseOptions.tokenize ){ + snippetHighlights.push(searchQuery); + }else{ + $.each(value.matches,function(matchKey,mvalue){ + if(mvalue.key == "tags" || mvalue.key == "categories" ){ + snippetHighlights.push(mvalue.value); + }else if(mvalue.key == "contents"){ + start = mvalue.indices[0][0]-summaryInclude>0?mvalue.indices[0][0]-summaryInclude:0; + end = mvalue.indices[0][1]+summaryInclude<contents.length?mvalue.indices[0][1]+summaryInclude:contents.length; + snippet += contents.substring(start,end); + snippetHighlights.push(mvalue.value.substring(mvalue.indices[0][0],mvalue.indices[0][1]-mvalue.indices[0][0]+1)); + } + }); + } + + if(snippet.length<1){ + snippet += contents.substring(0,summaryInclude*2); + } + //pull template from hugo templarte definition + var templateDefinition = $('#search-result-template').html(); + //replace values + var output = render(templateDefinition,{key:key,title:value.item.title,link:value.item.permalink,tags:value.item.tags,categories:value.item.categories,snippet:snippet}); + $('#search-results').append(output); + + $.each(snippetHighlights,function(snipkey,snipvalue){ + $("#summary-"+key).mark(snipvalue); + }); + + }); +} + +function param(name) { + return decodeURIComponent((location.search.split(name + '=')[1] || '').split('&')[0]).replace(/\+/g, ' '); +} + +function render(templateString, data) { + var conditionalMatches,conditionalPattern,copy; + conditionalPattern = /\$\{\s*isset ([a-zA-Z]*) \s*\}(.*)\$\{\s*end\s*}/g; + //since loop below depends on re.lastInxdex, we use a copy to capture any manipulations whilst inside the loop + copy = templateString; + while ((conditionalMatches = conditionalPattern.exec(templateString)) !== null) { + if(data[conditionalMatches[1]]){ + //valid key, remove conditionals, leave contents. + copy = copy.replace(conditionalMatches[0],conditionalMatches[2]); + }else{ + //not valid, remove entire section + copy = copy.replace(conditionalMatches[0],''); + } + } + templateString = copy; + //now any conditionals removed we can do simple substitution + var key, find, re; + for (key in data) { + find = '\\$\\{\\s*' + key + '\\s*\\}'; + re = new RegExp(find, 'g'); + templateString = templateString.replace(re, data[key]); + } + return templateString; +} + diff --git a/theme.toml b/theme.toml new file mode 100644 index 0000000..4da484c --- /dev/null +++ b/theme.toml @@ -0,0 +1,15 @@ +# theme.toml template for a Hugo theme +# See https://github.com/gohugoio/hugoThemes#themetoml for an example + +name = "Bodhi Theme" +license = "MIT" +licenselink = "https://github.com/rhnvrm/bodhi-theme/blob/master/LICENSE" +description = "Minimal theme for Hugo" +homepage = "https://rohanverma.net/hugo/themes/bodhi" +tags = [] +features = [] +min_version = "0.41.0" + +[author] + name = "Rohan Verma" + homepage = "https://rohanverma.net" |