Markdown -> Semble importer
1import {SembleUrlType} from "./citoid";
2
3export interface UrlPattern {
4 regex: RegExp;
5 type: SembleUrlType;
6 description?: string;
7}
8
9export class UrlClassifier {
10 private static readonly patterns: UrlPattern[] = [
11 {
12 regex: /^https:\/\/bsky\.app\/profile\/[^/]+\/post\/[^/]+$/,
13 type: SembleUrlType.SOCIAL,
14 description: "Bluesky post"
15 },
16 {
17 regex: /^https:\/\/blacksky\.community\/profile\/[^/]+\/post\/[^/]+$/,
18 type: SembleUrlType.SOCIAL,
19 description: "Blacksky community post"
20 },
21 {
22 regex: /^https:\/\/deer\.social\/profile\/[^/]+\/post\/[^/]+$/,
23 type: SembleUrlType.SOCIAL,
24 description: "Deer social post"
25 },
26 {
27 regex: /^https:\/\/smokesignal\.events\/[^/]+\/[^/]+$/,
28 type: SembleUrlType.LINK,
29 description: "Smokesignal event"
30 },
31 {
32 regex: /^https:\/\/tangled\.org\/[^/]+\/[^/]+/,
33 type: SembleUrlType.SOFTWARE,
34 description: "Tangled repo"
35 },
36 {
37 regex: /^https:\/\/[^./]+\.leaflet\.pub\/[^/]+$/,
38 type: SembleUrlType.ARTICLE,
39 description: "Leaflet article"
40 }
41 ];
42
43 public static classifyUrl(url: string): SembleUrlType | null {
44 for (const pattern of this.patterns) {
45 if (pattern.regex.test(url)) {
46 return pattern.type;
47 }
48 }
49 return null;
50 }
51}