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

github.com/sudorook/capsule.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpseudorook <pseudorook@protonmail.com>2017-10-05 19:06:20 +0300
committerpseudorook <pseudorook@protonmail.com>2017-10-05 19:06:20 +0300
commit053f8f0a16ccaeb56ee788f1eef9c38154a17536 (patch)
treeaa42280ffda694f971847100ce337d835397450b /layouts
parenta2caea71272e9b94d2fb62f25109927aea27b493 (diff)
save the relative prefix calculating code as a shortcode
Diffstat (limited to 'layouts')
-rw-r--r--layouts/shortcodes/relprefix.html18
1 files changed, 18 insertions, 0 deletions
diff --git a/layouts/shortcodes/relprefix.html b/layouts/shortcodes/relprefix.html
new file mode 100644
index 0000000..0b5a791
--- /dev/null
+++ b/layouts/shortcodes/relprefix.html
@@ -0,0 +1,18 @@
+{{ $.Scratch.Set "url" ($.Page.Permalink | replaceRE "^//localhost:[0-9]*/" "" | replaceRE "^/" "" | replaceRE "/$" "") -}}
+{{ if eq (len ($.Scratch.Get "url")) 0 -}}
+ {{ $.Scratch.Set "prefix" "." -}}
+{{ else -}}
+ {{ $.Scratch.Set "length" ((split ($.Scratch.Get "url") "/") | len) -}}
+ {{ if eq ($.Scratch.Get "length") 0 -}}
+ {{ $.Scratch.Set "prefix" "." -}}
+ {{ else -}}
+ {{ $.Scratch.Set "prefix" "" -}}
+ {{ range $i, $e := (seq ($.Scratch.Get "length")) -}}
+ {{ if eq (add $i 1) ($.Scratch.Get "length") -}}
+ {{ $.Scratch.Set "prefix" (print ($.Scratch.Get "prefix") "..") -}}
+ {{ else -}}
+ {{ $.Scratch.Set "prefix" (print ($.Scratch.Get "prefix") "../") -}}
+ {{ end -}}
+ {{ end -}}
+ {{ end -}}
+{{ end -}}