Skip to content

Commit

Permalink
Merge pull request #165 from techdivision/import-additions-15
Browse files Browse the repository at this point in the history
Import additions 15
  • Loading branch information
sippsolutions authored Oct 7, 2024
2 parents 289bda7 + b874bbf commit b5e68f8
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 39 deletions.
110 changes: 92 additions & 18 deletions tools/importer/import-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export const isEderGmbh = (params) => {
return originalDomain === 'www.eder-gmbh.de';
};

/**
* Returns whether the current import takes place for feedstar.com
* @param params
* @returns {boolean}
*/
export const isFeedstar = (params) => {
const originalUrl = new URL(params.originalURL);

const originalDomain = originalUrl.host;

return originalDomain === 'www.feedstar.com';
};

/**
* Returns whether the current import takes place for eder-stapler.de
* @param params
Expand All @@ -95,6 +108,19 @@ export const isEderStapler = (params) => {
return originalDomain === 'www.eder-stapler.de';
};

/**
* Returns whether the current import takes place for eder-stalltechnik.de
* @param params
* @returns {boolean}
*/
export const isEderStalltechnik = (params) => {
const originalUrl = new URL(params.originalURL);

const originalDomain = originalUrl.host;

return originalDomain === 'www.eder-stalltechnik.de';
};

/**
* Determines whether the given news or events entry should be imported for the given domain
* @param entry
Expand All @@ -113,6 +139,7 @@ export const shouldBeImported = (entry, originalUrl) => {
'https://www.eder-anhaenger.de': 'Anhängercenter',
'https://www.eder-stapler.de': 'Stapler',
'https://lelycenterinbayern.de': 'Lely Center',
'https://www.eder-kommunal.de': 'Kommunal',
};

const urlToCheck = `${originalUrl.protocol}//${originalUrl.host}`;
Expand All @@ -133,9 +160,20 @@ export const shouldBeImported = (entry, originalUrl) => {
}
});

// special handling for eder-kommunal and eder-golf, which will merged to eder-kommunal in EDS
let isOnlyEderKommunal = false;

// check if there are two entries: both "Kommunal" and "Golftechnik"
if (sectionList.length === 2 && sectionList.includes('Kommunal') && sectionList.includes('Golftechnik')) {
isOnlyEderKommunal = true;
}

if (isOnlyLelyCenter) {
// set Lely Center assigment
entry.section = 'Lely Center';
} else if (isOnlyEderKommunal) {
// set assignment to "Kommunal"
entry.section = 'Kommunal';
} else {
// set "Überall" in all other cases with multiple assignment
entry.section = 'Überall';
Expand Down Expand Up @@ -212,15 +250,8 @@ export const preprocessHrefLang = (document, params) => {

const xDefaultSections = xDefaultValue.split('/');

const lastEntry = xDefaultSections[xDefaultSections.length - 1];
const secondLastEntry = xDefaultSections[xDefaultSections.length - 2];

// last entry might be empty, due to a trailing slash
if (lastEntry !== '') {
params.hreflangKey = lastEntry;
} else {
params.hreflangKey = secondLastEntry;
}
// return the second-most entry
params.hreflangKey = xDefaultSections[xDefaultSections.length - 2];
}
};

Expand Down Expand Up @@ -765,6 +796,11 @@ export const handleIframes = (main, document) => {
// handle height of iframe
let height = iframe.getAttribute('height');

// set height to 1200px if there is none given and it's a technikboerse-iframe
if (!height && src.startsWith('https://dealersites.technikboerse.com/')) {
height = '1200px';
}

if (height && height.includes('px')) {
height = height.replace('px', '');

Expand Down Expand Up @@ -977,8 +1013,8 @@ export const handleFilterAndRows = (main, document, params) => {
// by default the second image should be used, if there is one (= the bigger mobile-image)
let originalImage = originalImages[originalImages.length - 1];

// custom handling for eder-stapler
if (isEderStapler(params)) {
// custom handling for eder-stapler and eder-stalltechnik
if (isEderStapler(params) || isEderStalltechnik(params)) {
// use the first image (= the Desktop-one) as the mobile-images are cut down
[originalImage] = originalImages;
}
Expand All @@ -1004,15 +1040,39 @@ export const handleFilterAndRows = (main, document, params) => {
contactButton.innerHTML = contactButtonParagraph.outerHTML;
}

// check for special structure at eder-stalltechnik
let productLogo;
if (isEderStalltechnik(params)) {
// remove collapse-div, as it is present, but not visible nor collapsable in Typo3
const collapse = content.querySelector('div.collapse');
if (collapse) {
collapse.remove();
}

// check for product-logo within content
productLogo = content.querySelector('div.product-logo');
}

// check for different types of rows
if (originalImageDiv && originalContentDiv && !originalRecommendDiv) {
// image and content are present, but no recommendations -> Rows with only two columns
if (originalImageDiv && originalContentDiv && !productLogo && !originalRecommendDiv) {
// image and content are present, but no logo nor recommendations
// -> Rows with only two columns

// store modified data
rowCells.push(
[resultImage, content],
);

// remove each of the single items, but not the last one
if (rowsCount < rows.length - 1) {
row.remove();
}
rowsCount += 1;
} else if (originalImageDiv && originalContentDiv && productLogo && !originalRecommendDiv) {
// image, logo and content are present, but no recommendations -> Rows with three columns
rowCells.push(
[resultImage, productLogo, content],
);

// remove each of the single items, but not the last one
if (rowsCount < rows.length - 1) {
row.remove();
Expand Down Expand Up @@ -1414,9 +1474,20 @@ export const handleTeaserRows = (main, document) => {
* Handle teaser-rows from Typo3 by converting them to an EDS Rows-Block
* @param main
* @param document
* @param params
*/
export const handleReferenceRows = (main, document) => {
const referenceList = main.querySelector('div.element-news_pi1');
export const handleReferenceRows = (main, document, params) => {
let referenceList = main.querySelector('div.element-news_pi1');

// handle special case at eder-stalltechnik
if (isEderStalltechnik(params)) {
const originalUrl = new URL(params.originalURL);

// identify page by its url, was there is no other way
if (originalUrl.pathname === '/faszination-eder/erleben/referenzberichte') {
referenceList = main.querySelector('div.news-list-view');
}
}

if (referenceList) {
const rows = referenceList.querySelectorAll('div.row');
Expand Down Expand Up @@ -1449,9 +1520,12 @@ export const handleReferenceRows = (main, document) => {
}
});

const resultTable = WebImporter.DOMUtils.createTable(cells, document);
// only replace if there is at least one entry (plus the headline)
if (cells.length > 1) {
const resultTable = WebImporter.DOMUtils.createTable(cells, document);

referenceList.replaceWith(resultTable);
referenceList.replaceWith(resultTable);
}
}
}
};
Expand Down
50 changes: 29 additions & 21 deletions tools/importer/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import {
handleSup,
handleReferenceRows,
formatTableData,
sanitizePathname, isEderStapler,
sanitizePathname,
isEderStapler,
isFeedstar,
} from './import-util.js';

const removeGenericContent = (main) => {
Expand Down Expand Up @@ -496,21 +498,15 @@ export const handleMetricsColumns = (main, document) => {
const metricBox = main.querySelector('div.metric-box');

if (metricBox) {
// create a custom table in order to allow formatting of entries
const resultTable = document.createElement('table');

// build headline-row
const headlineRow = document.createElement('tr');
const headlineCell = document.createElement('th');
headlineCell.setAttribute('colspan', 3);
headlineCell.append('Columns (metrics)');
headlineRow.append(headlineCell);

// build data-row
const dataRow = document.createElement('tr');
const cells = [
['Columns (metrics)'],
];

const columns = metricBox.querySelectorAll('div.col-sm-4');

// represents one line of entries in the result-table
let resultLine = [];

columns.forEach((column) => {
const metricHeader = column.querySelector('div.metric-header');
const metricDescription = column.querySelector('div.metric-description');
Expand All @@ -525,15 +521,24 @@ export const handleMetricsColumns = (main, document) => {
entry.append(metricHeader);
entry.append(metricDescription);

const tableCell = document.createElement('td');
tableCell.setAttribute('align', 'center');
tableCell.append(entry);
resultLine.push(entry);

dataRow.append(tableCell);
// if 3 entries are reached
if (resultLine.length > 2) {
// add line to cell-array
cells.push(resultLine);
// create a new empty line for the next entries
resultLine = [];
}
});

resultTable.append(headlineRow);
resultTable.append(dataRow);
// add possible, remaining entries to cell-array
if (resultLine.length > 0) {
cells.push(resultLine);
}

const resultTable = WebImporter.DOMUtils.createTable(cells, document);
formatTableData(resultTable, 'center');

metricBox.replaceWith(resultTable);
}
Expand Down Expand Up @@ -705,11 +710,13 @@ export const handleVariants = (main, document) => {
* Add userlike-Block if there was any in Typo3.
* @param main
* @param document
* @param params
*/
export const handleUserlike = (main, document, params) => {
const { userlikeKey } = params;

if (userlikeKey) {
// check for userlike-key, but avoid adding it to individual pages at feedstar
if (userlikeKey && !isFeedstar(params)) {
const cells = [
['Thirdparty'],
['Userlike', userlikeKey],
Expand All @@ -725,6 +732,7 @@ export const handleUserlike = (main, document, params) => {
* Replace centered text by Columns-Block with centered formatting
* @param main
* @param document
* @param params
*/
export const handleTextCentered = (main, document, params) => {
// execute conversion only for eder-stapler, as it might cause side effects on the other domains
Expand Down Expand Up @@ -853,7 +861,7 @@ export default {
handleContactBanner(main, document);
handleSup(main, document);
handleMetricsColumns(main, document);
handleReferenceRows(main, document);
handleReferenceRows(main, document, params);
handleSmallPrint(main, document);
handleVariants(main, document);
handleTextCentered(main, document, params);
Expand Down

0 comments on commit b5e68f8

Please sign in to comment.