Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/yanlinlin82/simple-style.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinlin Yan (颜林林) <yanlinlin82@gmail.com>2020-07-01 03:07:11 +0300
committerGitHub <noreply@github.com>2020-07-01 03:07:11 +0300
commit77811cfabec357ba55c658f79cfb933e1f9d6cb4 (patch)
tree7d59bcccd40c4aaf180b0d82de8e8be1a57cc662
parent19bb01a6d805a05c9f8279c8d12d847e88129c85 (diff)
parent09bf9ee51d0d8a1d52955e1d06e34111371b0912 (diff)
Merge pull request #3 from xiaoledeng/master
add search and content
-rw-r--r--layouts/_default/single.html16
-rw-r--r--layouts/partials/search.html3
-rw-r--r--layouts/partials/toc.html44
3 files changed, 60 insertions, 3 deletions
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index fe6be00..d9425f9 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -5,14 +5,21 @@
<h2>{{ . }}</h2>
{{ end -}}
</div>
+<div style="position: fixed; right:-30px; max-width:300px; overflow:auto; top: 1px; width: 300px; bottom:100px">
+{{ partial "search.html" . }}
+</div>
<div class="meta">
{{ if .Date -}}
<div>{{ .Date.Format "2006-01-02 15:04" }}</div>
{{ end -}}
- {{ if .Params.tags -}}
+ {{ $taxo := "tags" -}}
+ {{ if .Param $taxo -}}
<div>
- {{ range .Params.tags -}}
- <span><a href="{{ "/tags/" | relURL }}{{ . | urlize }}">#{{ . }}</a></span>
+ {{ range .Param $taxo -}}
+ {{ $name := . -}}
+ {{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) -}}
+ <span><a href="{{ .Permalink }}">#{{ $name }}</a></span>
+ {{ end -}}
{{ end -}}
</div>
{{ end -}}
@@ -20,4 +27,7 @@
<div class="content">
{{ .Content -}}
</div>
+<div style="position: fixed; right:50px; max-width:255px; overflow:auto; top: 120px; width: 220px; bottom:90px">
+{{ partial "toc.html" . }}
+</div>
{{ end -}}
diff --git a/layouts/partials/search.html b/layouts/partials/search.html
new file mode 100644
index 0000000..53b7b9a
--- /dev/null
+++ b/layouts/partials/search.html
@@ -0,0 +1,3 @@
+<div class="container text-center mt-3">
+ <iframe src="https://duckduckgo.com/search.html?site={{.Site.BaseURL}}&prefill={{.Site.Params.search.placeholder}}" style="overflow:hidden;margin:0;padding:0;max-width:80%;height:40px;" frameborder="0"></iframe>
+</div> \ No newline at end of file
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
new file mode 100644
index 0000000..7b4ac78
--- /dev/null
+++ b/layouts/partials/toc.html
@@ -0,0 +1,44 @@
+<!-- toc.html -->
+<!-- ignore empty links with + -->
+{{ $headers := findRE "<h[1-4].*?>(.|\n])+?</h[1-4]>" .Content }}
+<!-- at least one header to link to -->
+{{ if ge (len $headers) 1 }}
+{{ $h1_n := len (findRE "(.|\n])+?" .Content) }}
+{{ $re := (cond (eq $h1_n 0) "<h[2-4]" "<h[1-4]") }}
+{{ $renum := (cond (eq $h1_n 0) "[2-4]" "[1-4]") }}
+
+<!--Scrollspy-->
+<div class="toc">
+
+ <div class="page-header"><strong>目录</strong></div>
+
+ <div id="page-scrollspy" class="toc-nav">
+
+ {{ range $headers }}
+ {{ $header := . }}
+ {{ range first 1 (findRE $re $header 1) }}
+ {{ range findRE $renum . 1 }}
+ {{ $next_heading := (cond (eq $h1_n 0) (sub (int .) 1 ) (int . ) ) }}
+ {{ range seq $next_heading }}
+ <ul class="nav">
+ {{end}}
+ {{ $anchorId := (replaceRE ".* id=\"(.*?)\".*" "$1" $header ) }}
+ <li class="nav-item">
+ <a class="nav-link text-left" href="#{{ $anchorId }}">
+ {{ $header | plainify | htmlUnescape }}
+ </a>
+ </li>
+ <!-- close list -->
+ {{ range seq $next_heading }}
+ </ul>
+ {{ end }}
+ {{ end }}
+ {{ end }}
+ {{ end }}
+
+ </div>
+
+</div>
+<!--Scrollspy-->
+
+{{ end }} \ No newline at end of file