@@ -2,75 +2,166 @@ var requestHostnameEnv = context.getVariable("request_hostname_env");
22
33var searchAndReplaceStrings = [
44 {
5- searchFor : "www.nhs.uk/conditions/" ,
6- replaceWith : requestHostnameEnv + "/nhs-website-content/conditions/" ,
5+ comment1 : "=============================================================" ,
6+ comment2 : "Conditions " ,
7+ comment3 : "=============================================================" ,
8+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ c o n d i t i o n s \/ / gm,
9+ replaceWithStr :
10+ ':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/" ,
711 } ,
812 {
9- searchFor : "www.nhs.uk/live-well/" ,
10- replaceWith : requestHostnameEnv + "/nhs-website-content/live-well/" ,
13+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ c o n d i t i o n s \/ / gm,
14+ replaceWithStr :
15+ ':"https://' + requestHostnameEnv + "/nhs-website-content/conditions/" ,
1116 } ,
1217 {
13- searchFor : "www .nhs.uk/medicines/" ,
14- replaceWith : requestHostnameEnv + "/ nhs-website-content/medicines/" ,
18+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ c o n d i t i o n s \/ / gm ,
19+ replaceWithStr : 'href=\\"https://www. nhs.uk/conditions/' ,
1520 } ,
1621 {
17- searchFor : "www.nhs.uk/nhs-services/" ,
18- replaceWith : requestHostnameEnv + "/nhs-website-content/ nhs-services/" ,
22+ searchForRegex : / h r e f = \\ " \/ c o n d i t i o n s \/ / gm ,
23+ replaceWithStr : 'href=\\"https://www. nhs.uk/conditions/' ,
1924 } ,
2025 {
21- searchFor : "www.nhs.uk/pregnancy/" ,
22- replaceWith : requestHostnameEnv + "/nhs-website-content/pregnancy/" ,
26+ comment1 : "=============================================================" ,
27+ comment2 : "Live Well " ,
28+ comment3 : "=============================================================" ,
29+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ l i v e - w e l l \/ / gm,
30+ replaceWithStr :
31+ ':"https://' + requestHostnameEnv + "/nhs-website-content/live-well/" ,
2332 } ,
2433 {
25- searchFor : " www.nhs.uk/common-health-questions/" ,
26- replaceWith :
27- requestHostnameEnv + "/nhs-website-content/common-health-questions /" ,
34+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ l i v e - w e l l \/ / gm ,
35+ replaceWithStr :
36+ ':"https://' + requestHostnameEnv + "/nhs-website-content/live-well /" ,
2837 } ,
2938 {
30- searchFor : "www.nhs.uk/mental-health/" ,
31- replaceWith :
32- requestHostnameEnv +
33- "api.service.nhs.uk/nhs-website-content/mental-health/" ,
39+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ l i v e - w e l l \/ / gm,
40+ replaceWithStr : 'href=\\"https://www.nhs.uk/live-well/' ,
41+ } ,
42+ {
43+ searchForRegex : / h r e f = \\ " \/ l i v e - w e l l \/ / gm,
44+ replaceWithStr : 'href=\\"https://www.nhs.uk/live-well/' ,
45+ } ,
46+ {
47+ comment1 : "=============================================================" ,
48+ comment2 : "Mental health " ,
49+ comment3 : "=============================================================" ,
50+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ m e n t a l - h e a l t h \/ / gm,
51+ replaceWithStr :
52+ ':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/" ,
53+ } ,
54+ {
55+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ m e n t a l - h e a l t h \/ / gm,
56+ replaceWithStr :
57+ ':"https://' + requestHostnameEnv + "/nhs-website-content/mental-health/" ,
58+ } ,
59+ {
60+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ m e n t a l - h e a l t h \/ / gm,
61+ replaceWithStr : 'href=\\"https://www.nhs.uk/mental-health/' ,
62+ } ,
63+ {
64+ searchForRegex : / h r e f = \\ " \/ m e n t a l - h e a l t h \/ / gm,
65+ replaceWithStr : 'href=\\"https://www.nhs.uk/mental-health/' ,
66+ } ,
67+ {
68+ comment1 : "=============================================================" ,
69+ comment2 : "Medicines " ,
70+ comment3 : "=============================================================" ,
71+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ m e d i c i n e s \/ / gm,
72+ replaceWithStr :
73+ ':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/" ,
74+ } ,
75+ {
76+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ m e d i c i n e s \/ / gm,
77+ replaceWithStr :
78+ ':"https://' + requestHostnameEnv + "/nhs-website-content/medicines/" ,
3479 } ,
3580 {
36- searchFor : " api.nhs.uk/conditions/" ,
37- replaceWith : requestHostnameEnv + "/ nhs-website-content/conditions/" ,
81+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ m e d i c i n e s \/ / gm ,
82+ replaceWithStr : 'href=\\"https://www. nhs.uk/medicines/' ,
3883 } ,
3984 {
40- searchFor : "api.nhs.uk/live-well/" ,
41- replaceWith : requestHostnameEnv + "/ nhs-website-content/live-well/" ,
85+ searchForRegex : / h r e f = \\ " \/ m e d i c i n e s \/ / gm ,
86+ replaceWithStr : 'href=\\"https://www. nhs.uk/medicines/' ,
4287 } ,
4388 {
44- searchFor : "api.nhs.uk/medicines/" ,
45- replaceWith : requestHostnameEnv + "/nhs-website-content/medicines/" ,
89+ comment1 : "=============================================================" ,
90+ comment2 : "NHS services " ,
91+ comment3 : "=============================================================" ,
92+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ n h s - s e r v i c e s \/ / gm,
93+ replaceWithStr :
94+ ':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/" ,
4695 } ,
4796 {
48- searchFor : "api.nhs.uk/nhs-services/" ,
49- replaceWith : requestHostnameEnv + "/nhs-website-content/nhs-services/" ,
97+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ n h s - s e r v i c e s \/ / gm,
98+ replaceWithStr :
99+ ':"https://' + requestHostnameEnv + "/nhs-website-content/nhs-services/" ,
50100 } ,
51101 {
52- searchFor : " api.nhs.uk/pregnancy/" ,
53- replaceWith : requestHostnameEnv + "/ nhs-website-content/pregnancy/" ,
102+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ n h s - s e r v i c e s \/ / gm ,
103+ replaceWithStr : 'href=\\"https://www. nhs.uk/nhs-services/' ,
54104 } ,
55105 {
56- searchFor : "api.nhs.uk/common-health-questions/" ,
57- replaceWith :
58- requestHostnameEnv + "/nhs-website-content/common-health-questions/" ,
106+ searchForRegex : / h r e f = \\ " \/ n h s - s e r v i c e s \/ / gm,
107+ replaceWithStr : 'href=\\"https://www.nhs.uk/nhs-services/' ,
59108 } ,
60109 {
61- searchFor : "api.nhs.uk/mental-health/" ,
62- replaceWith :
110+ comment1 : "=============================================================" ,
111+ comment2 : "Pregnancy " ,
112+ comment3 : "=============================================================" ,
113+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ p r e g n a n c y \/ / gm,
114+ replaceWithStr :
115+ ':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/" ,
116+ } ,
117+ {
118+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ p r e g n a n c y \/ / gm,
119+ replaceWithStr :
120+ ':"https://' + requestHostnameEnv + "/nhs-website-content/pregnancy/" ,
121+ } ,
122+ {
123+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ p r e g n a n c y \/ / gm,
124+ replaceWithStr : 'href=\\"https://www.nhs.uk/pregnancy/' ,
125+ } ,
126+ {
127+ searchForRegex : / h r e f = \\ " \/ p r e g n a n c y \/ / gm,
128+ replaceWithStr : 'href=\\"https://www.nhs.uk/pregnancy/' ,
129+ } ,
130+ {
131+ comment1 : "=============================================================" ,
132+ comment2 : "Common health questions " ,
133+ comment3 : "=============================================================" ,
134+ searchForRegex : / : " h t t p s : \/ \/ a p i .n h s .u k \/ c o m m o n - h e a l t h - q u e s t i o n s \/ / gm,
135+ replaceWithStr :
136+ ':"https://' +
63137 requestHostnameEnv +
64- "api.service.nhs.uk/nhs-website-content/mental-health/" ,
138+ "/nhs-website-content/common-health-questions/" ,
139+ } ,
140+ {
141+ searchForRegex : / : " h t t p s : \/ \/ w w w .n h s .u k \/ c o m m o n - h e a l t h - q u e s t i o n s \/ / gm,
142+ replaceWithStr :
143+ ':"https://' +
144+ requestHostnameEnv +
145+ "/nhs-website-content/common-health-questions/" ,
146+ } ,
147+ {
148+ searchForRegex : / h r e f = \\ " h t t p s : \/ \/ a p i .n h s .u k \/ c o m m o n - h e a l t h - q u e s t i o n s \/ / gm,
149+ replaceWithStr : 'href=\\"https://www.nhs.uk/common-health-questions/' ,
150+ } ,
151+ {
152+ searchForRegex : / h r e f = \\ " \/ c o m m o n - h e a l t h - q u e s t i o n s \/ / gm,
153+ replaceWithStr : 'href=\\"https://www.nhs.uk/common-health-questions/' ,
65154 } ,
66155] ;
67156
68157var responseContent = context . getVariable ( "response.content" ) ;
69158var regex , item ;
70159for ( var i = 0 ; i < searchAndReplaceStrings . length ; i ++ ) {
71160 item = searchAndReplaceStrings [ i ] ;
72- regex = new RegExp ( item . searchFor , "g" ) ;
73- responseContent = responseContent . replace ( regex , item . replaceWith ) ;
161+ responseContent = responseContent . replace (
162+ item . searchForRegex ,
163+ item . replaceWithStr
164+ ) ;
74165}
75166
76167context . setVariable ( "response.content" , responseContent ) ;
0 commit comments