From 12a3abfa2c2e6c2b67a8c8a9ae33a2f4834d4800 Mon Sep 17 00:00:00 2001 From: Xiao-Le Deng Date: Fri, 5 Jun 2020 15:15:14 +0800 Subject: search and content add the search and content function --- layouts/partials/search.html | 3 +++ layouts/partials/toc.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 layouts/partials/search.html create mode 100644 layouts/partials/toc.html 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 @@ +
+ +
\ 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 @@ + + +{{ $headers := findRE "(.|\n])+?" .Content }} + +{{ if ge (len $headers) 1 }} +{{ $h1_n := len (findRE "(.|\n])+?" .Content) }} +{{ $re := (cond (eq $h1_n 0) " +
+ + + +
+ + {{ 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 }} + + {{ end }} + {{ end }} + {{ end }} + {{ end }} + +
+ +
+ + +{{ end }} \ No newline at end of file -- cgit v1.2.3 From 09bf9ee51d0d8a1d52955e1d06e34111371b0912 Mon Sep 17 00:00:00 2001 From: Xiao-Le Deng Date: Fri, 5 Jun 2020 15:17:50 +0800 Subject: add search and content add the function of search and content --- layouts/_default/single.html | 16 +++++++++++++--- 1 file changed, 13 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 @@

{{ . }}

{{ end -}} +
+{{ partial "search.html" . }} +
{{ if .Date -}}
{{ .Date.Format "2006-01-02 15:04" }}
{{ end -}} - {{ if .Params.tags -}} + {{ $taxo := "tags" -}} + {{ if .Param $taxo -}}
- {{ range .Params.tags -}} - #{{ . }} + {{ range .Param $taxo -}} + {{ $name := . -}} + {{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) -}} + #{{ $name }} + {{ end -}} {{ end -}}
{{ end -}} @@ -20,4 +27,7 @@
{{ .Content -}}
+
+{{ partial "toc.html" . }} +
{{ end -}} -- cgit v1.2.3