|
@@ -321,6 +321,27 @@ func IsFirstPathPart(currentPath, pathToCheck string) bool {
|
|
return "/"+parts[1] == pathToCheck
|
|
return "/"+parts[1] == pathToCheck
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// IsLastPathPart checks if the last part of the current path matches the given path
|
|
|
|
+func IsLastPathPart(currentPath, pathToCheck string) bool {
|
|
|
|
+ // Trim any trailing slashes from both paths
|
|
|
|
+ currentPath = strings.TrimRight(currentPath, "/")
|
|
|
|
+ pathToCheck = strings.TrimRight(pathToCheck, "/")
|
|
|
|
+
|
|
|
|
+ // Split the current path into parts
|
|
|
|
+ parts := strings.Split(currentPath, "/")
|
|
|
|
+
|
|
|
|
+ // Check if there is at least one part
|
|
|
|
+ if len(parts) < 1 {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Get the last part
|
|
|
|
+ lastPart := parts[len(parts)-1]
|
|
|
|
+
|
|
|
|
+ // Compare the last path part with the pathToCheck
|
|
|
|
+ return "/"+lastPart == pathToCheck
|
|
|
|
+}
|
|
|
|
+
|
|
var (
|
|
var (
|
|
furiganaPattern = regexp.MustCompile(`\[\[rb:\s*(.+?)\s*>\s*(.+?)\s*\]\]`)
|
|
furiganaPattern = regexp.MustCompile(`\[\[rb:\s*(.+?)\s*>\s*(.+?)\s*\]\]`)
|
|
chapterPattern = regexp.MustCompile(`\[chapter:\s*(.+?)\s*\]`)
|
|
chapterPattern = regexp.MustCompile(`\[chapter:\s*(.+?)\s*\]`)
|
|
@@ -431,6 +452,7 @@ func GetTemplateFunctions() map[string]any {
|
|
"unfinishedQuery": UnfinishedQuery,
|
|
"unfinishedQuery": UnfinishedQuery,
|
|
"replaceQuery": ReplaceQuery,
|
|
"replaceQuery": ReplaceQuery,
|
|
"isFirstPathPart": IsFirstPathPart,
|
|
"isFirstPathPart": IsFirstPathPart,
|
|
|
|
+ "isLastPathPart": IsLastPathPart,
|
|
// TODO: what is AttrGen for
|
|
// TODO: what is AttrGen for
|
|
// "AttrGen": SwitchButtonAttributes,
|
|
// "AttrGen": SwitchButtonAttributes,
|
|
}
|
|
}
|