From ecb0d964ad97fd9863cb920d17dcea5ab1b2e15e Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 2 Nov 2023 17:35:59 +0800 Subject: [PATCH] :zap: Perf: optimize function suffix-validation --- layouts/partials/function/suffix-validation.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/layouts/partials/function/suffix-validation.html b/layouts/partials/function/suffix-validation.html index b2a54f97..a3839bd7 100644 --- a/layouts/partials/function/suffix-validation.html +++ b/layouts/partials/function/suffix-validation.html @@ -1,6 +1,9 @@ -{{- $filteredPath := strings.TrimSuffix "/" (.Path | lower) -}} -{{- $suffixValid := false -}} -{{- range .Suffixes -}} - {{- $suffixValid = or (eq (path.Ext $filteredPath) .) $suffixValid -}} +{{- $url := urls.Parse .Path -}} +{{- $path := strings.TrimSuffix "/" ((printf "%v%v" $url.Host $url.Path) | lower) -}} +{{- with $url.Scheme -}} + {{- $path = printf "%v://%v" . $path -}} {{- end -}} +{{- $suffix := path.Ext $path -}} +{{- $suffixes := .Suffixes | default slice -}} +{{- $suffixValid := in $suffixes $suffix -}} {{- return $suffixValid -}}