@bartificer/linkify 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// import Linkify Lib
|
|
2
|
+
import { linkify, LinkTemplate, LinkData } from '../dist/index.js';
|
|
3
|
+
|
|
4
|
+
// import 3rd-party library for interacting with the clipboard
|
|
5
|
+
import clipboardy from 'clipboardy';
|
|
6
|
+
|
|
7
|
+
// register a custom Markdown link template and make it the default
|
|
8
|
+
linkify.registerTemplate('md-bartificer', new LinkTemplate(
|
|
9
|
+
'[{{{text}}} — {{{uri.hostname}}}{{#uri.hasPath}}/…{{/uri.hasPath}}]({{{url}}})',
|
|
10
|
+
[
|
|
11
|
+
['url', linkify.util.stripUTMParameters],
|
|
12
|
+
['text', linkify.util.regulariseWhitespace]
|
|
13
|
+
]
|
|
14
|
+
));
|
|
15
|
+
linkify.defaultTemplateName = 'md-bartificer';
|
|
16
|
+
|
|
17
|
+
// register a special Markdown template for Apple presss releases and make it the default for Apple's domain
|
|
18
|
+
linkify.registerTemplate('md-apr', new LinkTemplate(
|
|
19
|
+
'[{{{text}}} — 📣 Apple PR]({{{url}}})',
|
|
20
|
+
[
|
|
21
|
+
['url', linkify.util.stripUTMParameters],
|
|
22
|
+
['text', linkify.util.regulariseWhitespace]
|
|
23
|
+
]
|
|
24
|
+
));
|
|
25
|
+
linkify.registerDefaultTemplateMapping('apple.com', 'md-apr');
|
|
26
|
+
|
|
27
|
+
// define & register custom transformers for domains that need them
|
|
28
|
+
linkify.registerTransformer('9to5mac.com', function(pData){
|
|
29
|
+
return new LinkData(pData.url, pData.mainHeading);
|
|
30
|
+
});
|
|
31
|
+
linkify.registerTransformer('cultofmac.com', function(pData){
|
|
32
|
+
return new LinkData(pData.url, pData.mainHeading);
|
|
33
|
+
});
|
|
34
|
+
linkify.registerTransformer('daringfireball.net', function(pData){
|
|
35
|
+
return new LinkData(pData.url, pData.title.replace(/^Daring Fireball:[ ]/, ''));
|
|
36
|
+
});
|
|
37
|
+
linkify.registerTransformer('intego.com', function(pData){
|
|
38
|
+
return new LinkData(pData.url, pData.title.replace(' - The Mac Security Blog', ''));
|
|
39
|
+
});
|
|
40
|
+
linkify.registerTransformer('krebsonsecurity.com', function(pData){
|
|
41
|
+
return new LinkData(pData.url, pData.title.replace(' – Krebs on Security', ''));
|
|
42
|
+
});
|
|
43
|
+
linkify.registerTransformer('macstories.net', function(pData){
|
|
44
|
+
return new LinkData(pData.url, pData.title.replace(' - MacStories', ''));
|
|
45
|
+
});
|
|
46
|
+
linkify.registerTransformer('nakedsecurity.sophos.com', function(pData){
|
|
47
|
+
return new LinkData(pData.url, pData.title.replace(' – Naked Security', ''));
|
|
48
|
+
});
|
|
49
|
+
linkify.registerTransformer('overcast.fm', function(pData){
|
|
50
|
+
// strip Overcast append, split on em-dash to replace with n-dash and get podcast name
|
|
51
|
+
let textParts = pData.title.replace(' — Overcast', '').split('—');
|
|
52
|
+
let podcastName = textParts.pop();
|
|
53
|
+
|
|
54
|
+
// re-assemble the text
|
|
55
|
+
let linkText = podcastName.trim() + ': ' + textParts.join(' – ').replace(/[ ]+/g, ' ').replace(':', '-').trim();
|
|
56
|
+
return new LinkData(pData.url, linkText);
|
|
57
|
+
});
|
|
58
|
+
linkify.registerTransformer('sixcolors.com', function(pData){
|
|
59
|
+
return new LinkData(pData.url, pData.mainHeading);
|
|
60
|
+
});
|
|
61
|
+
linkify.registerTransformer('theverge.com', function(pData){
|
|
62
|
+
return new linkify.LinkData(pData.url, pData.title.replace(/[ ][-][ ]The[ ]Verge.*$/, ''));
|
|
63
|
+
});
|
|
64
|
+
linkify.registerTransformer('wired.com', function(pData){
|
|
65
|
+
return new linkify.LinkData(pData.url, pData.mainHeading);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// read the URL from the clipboard
|
|
69
|
+
let testURL = clipboardy.readSync();
|
|
70
|
+
|
|
71
|
+
// try generate the formatted link from the URL
|
|
72
|
+
linkify.generateLink(testURL).then(function(d){
|
|
73
|
+
console.log(d);
|
|
74
|
+
});
|