From 9640b5ed3caba3f6b3b00d57eac7dc8d84da25d9 Mon Sep 17 00:00:00 2001 From: Mark Dumay Date: Wed, 14 Feb 2024 06:32:45 +0100 Subject: [PATCH] feat: add helper method to convert absolute paths to mounted folders --- layouts/partials/utilities/GetTargetPath.html | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 layouts/partials/utilities/GetTargetPath.html diff --git a/layouts/partials/utilities/GetTargetPath.html b/layouts/partials/utilities/GetTargetPath.html new file mode 100644 index 0000000..46de2f3 --- /dev/null +++ b/layouts/partials/utilities/GetTargetPath.html @@ -0,0 +1,26 @@ + + +{{ $path := .path -}} +{{ $page := .page -}} +{{ if hasPrefix $path "/" }} + {{ $pageContext := (path.Join "/content" $page.File.Dir) -}} + {{ if hasPrefix $path $pageContext }} + {{ $path = strings.TrimPrefix $pageContext $path -}} + {{ $path = strings.TrimPrefix "/" $path -}} + {{ else if hasPrefix $path "/assets/" }} + {{ $path = strings.TrimPrefix "/assets" $path -}} + {{ else if hasPrefix $path "/static/" }} + {{ $path = strings.TrimPrefix "/static" $path -}} + {{ end }} +{{ end }} + +{{ return $path -}} \ No newline at end of file