Skip to content

Commit 4c2f900

Browse files
committed
feat: Displays keyword's best position in email notification.
closes 202
1 parent 040dab1 commit 4c2f900

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

email/email.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
<tr align="left">
443443
<th>Keyword</th>
444444
<th>Position</th>
445+
<th>Best</th>
445446
<th>Updated</th>
446447
</tr>
447448
{{keywordsTable}}

utils/generateEmail.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ const getPositionChange = (history:KeywordHistory, position:number) : number =>
6868
return status;
6969
};
7070

71+
const getBestKeywordPosition = (history: KeywordHistory) => {
72+
let bestPos;
73+
if (Object.keys(history).length > 0) {
74+
const historyArray = Object.keys(history).map((itemID) => ({ date: itemID, position: history[itemID] }))
75+
.sort((a, b) => a.position - b.position).filter((el) => (el.position > 0));
76+
if (historyArray[0]) {
77+
bestPos = { ...historyArray[0] };
78+
}
79+
}
80+
81+
return bestPos?.position || '-';
82+
};
83+
7184
/**
7285
* Generate the Email HTML based on given domain name and its keywords
7386
* @param {string} domainName - Keywords to scrape
@@ -97,6 +110,7 @@ const generateEmail = async (domainName:string, keywords:KeywordType[], settings
97110
keywordsTable += `<tr class="keyword">
98111
<td>${countryFlag} ${deviceIcon} ${keyword.keyword}</td>
99112
<td>${keyword.position}${posChangeIcon}</td>
113+
<td>${getBestKeywordPosition(keyword.history)}</td>
100114
<td>${timeSince(new Date(keyword.lastUpdated).getTime() / 1000)}</td>
101115
</tr>`;
102116
});

0 commit comments

Comments
 (0)