-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (61 loc) · 1.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;(() => {
// Edit Story Bookmarklet - all logic must be in this IIFE
// Dialogs
const cancel = () => alert(`Sorry, this doesn't look like a story page`)
const approve = () => confirm('Unknown site - try to open editor anyway?')
// Host verification
const arcStaging = 'https://sandbox.dmn.arcpublishing.com/composer/#!'
const arcDmnDev = 'https://dmndev.dmn.arcpublishing.com/composer/#!'
const arcProduction = 'https://dmn.arcpublishing.com/composer/#!'
const hosts = [
// Local direct
{
domain: /localhost(:\d+)?$/, // hostname regex
editor: arcStaging, // editor base URL
},
// Local with TLS Proxy
{
domain: /local.*dallasnews.com(:\d+)?$/,
editor: arcStaging,
},
// Arc DMNdev
{
domain: /dmndev.dmn.arcpublishing.com$/,
editor: arcDmnDev,
},
// Arc Dev
{
domain: /dev.dmn.arcpublishing.com$/,
editor: arcStaging,
},
// Arc Sandbox
{
domain: /sandbox.dmn.arcpublishing.com$/,
editor: arcStaging,
},
// Arc Sandbox with CNAME
{
domain: /staging.dallasnews.com$/,
editor: arcStaging,
},
// Arc Production
{
domain: /^dmn.arcpublishing.com$/,
editor: arcProduction,
},
// Arc Production with CNAME
{
domain: /^(www\.)?dallasnews.com$/,
editor: arcProduction,
},
]
const knownHost = hosts.find(({ domain }) => location.hostname.match(domain))
const editorUrl = knownHost ? knownHost.editor : arcProduction
// Arc/Composer Handler
const { globalContent: content = {} } = window.Fusion || {}
const arcId = content.type === 'story' && content._id
const shouldOpenArc = arcId && (knownHost || approve())
if (shouldOpenArc) return open(`${editorUrl}/edit/${arcId}/`)
// No matches found
!arcId && cancel()
})()