mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
ImmoScout: Allow web paths with SEO optimization to be filtered to query params (#128)
This commit is contained in:
@@ -79,6 +79,7 @@ const PARAM_NAME_MAP = {
|
|||||||
geocoordinates: 'geocoordinates',
|
geocoordinates: 'geocoordinates',
|
||||||
shape: 'shape',
|
shape: 'shape',
|
||||||
sorting: 'sorting',
|
sorting: 'sorting',
|
||||||
|
newbuilding: 'newbuilding'
|
||||||
};
|
};
|
||||||
|
|
||||||
const EQUIPMENT_MAP = {
|
const EQUIPMENT_MAP = {
|
||||||
@@ -89,6 +90,7 @@ const EQUIPMENT_MAP = {
|
|||||||
garden: 'garden',
|
garden: 'garden',
|
||||||
guesttoilet: 'guestToilet',
|
guesttoilet: 'guestToilet',
|
||||||
balcony: 'balcony',
|
balcony: 'balcony',
|
||||||
|
handicappedaccessible: 'handicappedAccessible'
|
||||||
};
|
};
|
||||||
|
|
||||||
const REAL_ESTATE_TYPE = {
|
const REAL_ESTATE_TYPE = {
|
||||||
@@ -98,6 +100,29 @@ const REAL_ESTATE_TYPE = {
|
|||||||
'haus-kaufen': 'housebuy',
|
'haus-kaufen': 'housebuy',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const WEB_PATH_TO_APARTMENT_EQUIPMENT_MAP = {
|
||||||
|
// Category "Balkon/Terrasse"
|
||||||
|
'wohnung-mit-balkon-mieten': { equipment: ['balcony'] },
|
||||||
|
'wohnung-mit-garten-mieten': { equipment: ['garden'] },
|
||||||
|
// Category "Wohnungstyp"
|
||||||
|
'souterrainwohnung-mieten': { apartmenttypes: ['halfbasement'] },
|
||||||
|
'erdgeschosswohnung-mieten': { apartmenttypes: ['groundfloor'] },
|
||||||
|
'hochparterrewohnung-mieten': { apartmenttypes: ['raisedgroundfloor'] },
|
||||||
|
'etagenwohnung-mieten': { apartmenttypes: ['apartment'] },
|
||||||
|
'loft-mieten': { apartmenttypes: ['loft'] },
|
||||||
|
'maisonette-mieten': { apartmenttypes: ['maisonette'] },
|
||||||
|
'terrassenwohnung-mieten': { apartmenttypes: ['terracedflat'] },
|
||||||
|
'penthouse-mieten': { apartmenttypes: ['penthouse'] },
|
||||||
|
'dachgeschosswohnung-mieten': { apartmenttypes: ['roofstorey'] },
|
||||||
|
// Category "Ausstattung"
|
||||||
|
'wohnung-mit-garage-mieten': { equipment: ['parking'] },
|
||||||
|
'wohnung-mit-einbaukueche-mieten': { equipment: ['builtinkitchen'] },
|
||||||
|
'wohnung-mit-keller-mieten': { equipment: ['cellar'] },
|
||||||
|
// Category "Merkmale"
|
||||||
|
'neubauwohnung-mieten': { newbuilding: true },
|
||||||
|
'barrierefreie-wohnung-mieten': { equipment: ['handicappedaccessible'] }
|
||||||
|
};
|
||||||
|
|
||||||
export function convertWebToMobile(webUrl) {
|
export function convertWebToMobile(webUrl) {
|
||||||
let url;
|
let url;
|
||||||
try {
|
try {
|
||||||
@@ -112,9 +137,17 @@ export function convertWebToMobile(webUrl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const realTypeKey = segments.at(-1);
|
const realTypeKey = segments.at(-1);
|
||||||
const realType = REAL_ESTATE_TYPE[realTypeKey];
|
let realType = REAL_ESTATE_TYPE[realTypeKey];
|
||||||
|
let additionalParamsFromWebPath;
|
||||||
|
|
||||||
if (!realType) {
|
if (!realType) {
|
||||||
throw new Error(`Real estate type not found: ${realTypeKey}`);
|
// Test for seo optimized apartment path (only used on the ImmoScout web app)
|
||||||
|
if (WEB_PATH_TO_APARTMENT_EQUIPMENT_MAP[realTypeKey]) {
|
||||||
|
additionalParamsFromWebPath = WEB_PATH_TO_APARTMENT_EQUIPMENT_MAP[realTypeKey];
|
||||||
|
realType = REAL_ESTATE_TYPE['wohnung-mieten'];
|
||||||
|
} else {
|
||||||
|
throw new Error(`Real estate type not found: ${realTypeKey}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (segments.includes('shape')) {
|
if (segments.includes('shape')) {
|
||||||
@@ -132,6 +165,7 @@ export function convertWebToMobile(webUrl) {
|
|||||||
searchType: isRadius ? 'radius' : 'region',
|
searchType: isRadius ? 'radius' : 'region',
|
||||||
realestatetype: realType,
|
realestatetype: realType,
|
||||||
...(isRadius ? {} : { geocodes }),
|
...(isRadius ? {} : { geocodes }),
|
||||||
|
...additionalParamsFromWebPath
|
||||||
};
|
};
|
||||||
|
|
||||||
if (webParams.geocoordinates) {
|
if (webParams.geocoordinates) {
|
||||||
@@ -141,7 +175,8 @@ export function convertWebToMobile(webUrl) {
|
|||||||
for (const [key, val] of Object.entries(webParams)) {
|
for (const [key, val] of Object.entries(webParams)) {
|
||||||
if (key === 'equipment') {
|
if (key === 'equipment') {
|
||||||
const items = [].concat(val).flatMap((v) => `${v}`.split(','));
|
const items = [].concat(val).flatMap((v) => `${v}`.split(','));
|
||||||
mobileParams[PARAM_NAME_MAP[key]] = items.map((item) => EQUIPMENT_MAP[item.toLowerCase()]).filter(Boolean);
|
const currentEquipmentParams = mobileParams[PARAM_NAME_MAP[key]];
|
||||||
|
mobileParams[PARAM_NAME_MAP[key]] = [...currentEquipmentParams ?? [], ...items.map((item) => EQUIPMENT_MAP[item.toLowerCase()]).filter(Boolean)];
|
||||||
} else {
|
} else {
|
||||||
mobileParams[PARAM_NAME_MAP[key]] = val;
|
mobileParams[PARAM_NAME_MAP[key]] = val;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,16 @@ describe('#immoscout-mobile URL conversion', () => {
|
|||||||
expect(actualMobileUrl).to.equal(expectedMobileUrl);
|
expect(actualMobileUrl).to.equal(expectedMobileUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test URL conversion of web-only SEO path
|
||||||
|
it('should convert a SEO web path to the correct query params', () => {
|
||||||
|
const webUrl =
|
||||||
|
'https://www.immobilienscout24.de/Suche/de/berlin/berlin/wohnung-mit-balkon-mieten?equipment=garden';
|
||||||
|
|
||||||
|
const converted = convertWebToMobile(webUrl);
|
||||||
|
const queryParams = new URL(converted).searchParams;
|
||||||
|
expect(queryParams.get('equipment').split(',')).to.include.members(['garden', 'balcony']);
|
||||||
|
});
|
||||||
|
|
||||||
// Test URL conversion with unsupported query parameters
|
// Test URL conversion with unsupported query parameters
|
||||||
it('should remove unsupported query parameters', () => {
|
it('should remove unsupported query parameters', () => {
|
||||||
const webUrl = 'https://www.immobilienscout24.de/Suche/de/berlin/berlin/wohnung-mieten?minimuminternetspeed=100000';
|
const webUrl = 'https://www.immobilienscout24.de/Suche/de/berlin/berlin/wohnung-mieten?minimuminternetspeed=100000';
|
||||||
|
|||||||
Reference in New Issue
Block a user