mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
update(LegacyLinkReplaceHelper.js):adds constants for the replacement strategies when the pattern has groups that should be added as path_segements or query_parameters
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
// collection of relative and absolute regex to replace legacy links
|
||||
//
|
||||
const GROUP_REPLACEMENT_STRATEGIES = {
|
||||
QUERY_PARAMETERS:'QUERY_PARAMETERS',
|
||||
PATH_SEGMENTS:'PATH_SEGMENTS',
|
||||
}
|
||||
|
||||
const regexList = {
|
||||
relative:[
|
||||
{
|
||||
priority: 1,
|
||||
regex: new RegExp(/^\.\.\/cms\/content\.php\?content_id=([0-9]+)/),
|
||||
replacement: FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/CisVue/Cms/content',
|
||||
group_replacement_strategy:GROUP_REPLACEMENT_STRATEGIES.PATH_SEGMENTS,
|
||||
},
|
||||
{
|
||||
priority: 2,
|
||||
@@ -37,6 +42,7 @@ const relative_regex = regexList.relative
|
||||
return {
|
||||
regex: regex.regex,
|
||||
replacement: regex.replacement,
|
||||
group_replacement_strategy: regex.group_replacement_strategy,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -49,19 +55,35 @@ const absolute_regex = regexList.absolute
|
||||
return {
|
||||
regex: regex.regex,
|
||||
replacement: regex.replacement,
|
||||
group_replacement_strategy: regex.group_replacement_strategy,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
export function replaceRelativeLegacyLink(relativeLegacyLink){
|
||||
for (let {regex,replacement} of relative_regex){
|
||||
for (let {regex,replacement,group_replacement_strategy} of relative_regex){
|
||||
// if any of the regex matches the relativeLegacyLink, replace the matched part with the new app_root path
|
||||
let match = relativeLegacyLink.match(regex);
|
||||
if (match) {
|
||||
let new_link = relativeLegacyLink.replace(regex, replacement);
|
||||
for(let query_parameter of match.slice(1)){
|
||||
new_link = new_link.concat(`/${query_parameter}`)
|
||||
}
|
||||
|
||||
switch (group_replacement_strategy){
|
||||
case 'QUERY_PARAMETERS':
|
||||
//TODO: this doesn't really work yet because the query parameter are key/value pairs
|
||||
new_link = new_link.concat(`?${match[1]}`);
|
||||
for (let query_parameter of match.slice(2)) {
|
||||
new_link = new_link.concat(`&${query_parameter}`);
|
||||
}
|
||||
break;
|
||||
case 'PATH_SEGMENTS':
|
||||
for (let query_parameter of match.slice(1)) {
|
||||
new_link = new_link.concat(`/${query_parameter}`);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return new_link;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user