← hugo-clarity

shortcodes

e6eca20e3e81e9a1cd62358f1e039fd710c71721 · ovidiucs · Jul 12, 2023 02:13

+65 −1 · 4 files changed

  • i18n/en.toml +9 −0
  • i18n/ro.toml +10 −1
  • layouts/partials/icons.html +11 −0
  • layouts/shortcodes/attachments.html +35 −0
diff --git a/i18n/en.toml b/i18n/en.toml
index a70d806..8ad2e12 100644
--- a/i18n/en.toml
+++ b/i18n/en.toml
@@ -55,6 +55,15 @@ other = "{{ .ReadingTime }} min read"
 [series_posts]
 other = "Posts in this series"
 
+[Byte-symbol]
+other = "B"
+
+[Kilobyte-symbol]
+other = "KB"
+
+[Megabyte-symbol]
+other = "MB"
+
 # search
 [quick_links]
   other = "Results"
diff --git a/i18n/ro.toml b/i18n/ro.toml
index 7c38d02..8e63aa5 100644
--- a/i18n/ro.toml
+++ b/i18n/ro.toml
@@ -8,7 +8,7 @@ other = "Mai mult"
 #other = "All Rights Reserved"
 
 [share_on]
-other = "Share pe"
+other = "Distribuie pe"
 
 [featured_posts]
 other = "Featured Posts"
@@ -55,6 +55,15 @@ other = "Timp de citire aprox. {{ .ReadingTime }} min"
 [series_posts]
 other = "Postări din această serie"
 
+[Byte-symbol]
+other = "B"
+
+[Kilobyte-symbol]
+other = "KB"
+
+[Megabyte-symbol]
+other = "MB"
+
 # search
 [quick_links]
   other = "Rezultate"
diff --git a/layouts/partials/icons.html b/layouts/partials/icons.html
index b5e3867..2527df9 100644
--- a/layouts/partials/icons.html
+++ b/layouts/partials/icons.html
@@ -72,4 +72,15 @@
     fill="#000000"
     d="m 12.616925,5.6916583 v 4.3315297 h -1.71607 V 5.8189683 c 0,-0.88624 -0.37289,-1.33607 -1.1187604,-1.33607 -0.82467,0 -1.23799,0.53361 -1.23799,1.58875 v 2.30122 h -1.70594 v -2.30122 c 0,-1.05514 -0.4134,-1.58875 -1.23808,-1.58875 -0.74587,0 -1.11876,0.44983 -1.11876,1.33607 v 4.2042197 h -1.71607 V 5.6916583 c 0,-0.88527 0.22541,-1.58876 0.67817,-2.10922 0.46689,-0.52047 1.07833,-0.78727 1.83735,-0.78727 0.87816,0 1.54317,0.33752 1.98288,1.01267 l 0.42744,0.71655 0.42753,-0.71655 c 0.43961,-0.67515 1.10463,-1.01267 1.9828704,-1.01267 0.75893,0 1.37037,0.2668 1.83735,0.78727 0.45268,0.52046 0.67808,1.22395 0.67808,2.10922"/>
   </symbol>
+    <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="attachment">
+	<path d="M302.258,37.32h-82.789c0-16.233-10.48-29.944-24.996-35.066C190.596,0.891,186.499,0,182.149,0
+	c-20.582,0-37.32,16.745-37.32,37.32v127.091c0,20.575,16.738,37.321,37.32,37.321c4.35,0,8.447-0.892,12.324-2.253
+	c14.516-5.123,24.996-18.834,24.996-35.068V112.97c0-8.156-6.131-14.617-13.996-15.705c-0.725-0.103-1.385-0.434-2.143-0.434
+	c-8.92,0-16.139,7.227-16.139,16.139v51.441c0,2.782-2.27,5.044-5.043,5.044c-2.773,0-5.043-2.262-5.043-5.044V66.705l114.137-0.078
+	v63.002c0,18.416,14.955,33.364,33.348,33.364l61.748-0.173l0.678,278.287c0,10.275-8.32,18.621-18.611,18.621H120.78
+	c-10.279,0-18.631-8.346-18.631-18.621V85.413c0-10.205,8.275-18.495,18.473-18.582V37.336
+	c-26.447,0.087-47.928,21.623-47.928,48.077v355.694c0,26.509,21.561,48.093,48.086,48.093h247.625
+	c26.508,0,48.102-21.584,48.102-48.093V151.15L302.258,37.32z M177.106,37.32c0-2.782,2.27-5.043,5.043-5.043
+	c2.773,0,5.043,2.261,5.043,5.043H177.106z"/>
+  </symbol>
 </svg>
diff --git a/layouts/shortcodes/attachments.html b/layouts/shortcodes/attachments.html
new file mode 100644
index 0000000..f9b9cc8
--- /dev/null
+++ b/layouts/shortcodes/attachments.html
@@ -0,0 +1,35 @@
+{{ $_hugo_config := `{ "version": 1 }` -}}
+<section class="attachments {{ with .Get "style"}}{{.}}{{ end }}">
+  <label>
+    <span>{{ partial "sprite" (dict "icon" "attachment") }}</span>
+    {{with .Get "title"}}{{.}}{{else}}{{T "Attachments-label"}}{{end}}
+  </label>
+  <div class="attachments-files">
+  {{- $filesName := "files" }}
+  {{- if ne .Page.File.BaseFileName "index" }}
+    {{- $filesName = printf "%s.files" .Page.File.BaseFileName }}
+  {{- end}}
+  {{- $fileDir := replace .Page.File.Dir "\\" "/" }}
+  {{- $pattern := .Get "pattern" | default "" }}
+  {{- range (readDir (printf "static/%s%s" .Page.File.Dir $filesName) ) }}
+    {{- if findRE $pattern .Name}}
+      {{- $size := .Size }}
+      {{- $unit := "Byte" }}
+      {{- if ge $size 1024 }}
+        {{- $size = div $size 1024 }}
+        {{- $unit = "Kilobyte" }}
+      {{- end}}
+      {{- if ge $size 1024 }}
+        {{- $size = div $size 1024 }}
+        {{- $unit = "Megabyte" }}
+      {{- end}}
+    <li>
+      <a href="{{ (printf "%s%s/%s" $fileDir $filesName .Name) | relLangURL }}">{{.Name}}</a>
+      ({{$size}} {{T (print $unit "-symbol" ) }})
+    </li>
+    {{- end}}
+  {{- end}}
+  </div>
+  {{- .Inner}}
+</section>
+