silverbullet/plugs/federation/util.ts

15 lines
572 B
TypeScript
Raw Normal View History

export function wildcardPathToRegex(pattern: string): RegExp {
2024-08-02 23:14:40 +08:00
// Escape special characters in the pattern except for the wildcard "*"
const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
2024-08-02 23:14:40 +08:00
// Replace the wildcard "*" with ".*" to match any character sequence
const regexPattern = escapedPattern.replace(/\*/g, ".*");
2024-08-02 23:14:40 +08:00
// Create a new regular expression with the converted pattern
return new RegExp(`^${regexPattern}(\\.md)?$`);
}
export function federatedPathToLocalPath(path: string): string {
2024-08-02 23:14:40 +08:00
return path.split("/").slice(1).join("/");
}