feat: Displays keyword's best position in email notification.

closes 202
This commit is contained in:
towfiqi 2024-11-09 21:24:27 +06:00
parent 040dab1517
commit 4c2f900d85
2 changed files with 15 additions and 0 deletions

View File

@ -442,6 +442,7 @@
<tr align="left">
<th>Keyword</th>
<th>Position</th>
<th>Best</th>
<th>Updated</th>
</tr>
{{keywordsTable}}

View File

@ -68,6 +68,19 @@ const getPositionChange = (history:KeywordHistory, position:number) : number =>
return status;
};
const getBestKeywordPosition = (history: KeywordHistory) => {
let bestPos;
if (Object.keys(history).length > 0) {
const historyArray = Object.keys(history).map((itemID) => ({ date: itemID, position: history[itemID] }))
.sort((a, b) => a.position - b.position).filter((el) => (el.position > 0));
if (historyArray[0]) {
bestPos = { ...historyArray[0] };
}
}
return bestPos?.position || '-';
};
/**
* Generate the Email HTML based on given domain name and its keywords
* @param {string} domainName - Keywords to scrape
@ -97,6 +110,7 @@ const generateEmail = async (domainName:string, keywords:KeywordType[], settings
keywordsTable += `<tr class="keyword">
<td>${countryFlag} ${deviceIcon} ${keyword.keyword}</td>
<td>${keyword.position}${posChangeIcon}</td>
<td>${getBestKeywordPosition(keyword.history)}</td>
<td>${timeSince(new Date(keyword.lastUpdated).getTime() / 1000)}</td>
</tr>`;
});