mirror of
https://github.com/dergigi/boris.git
synced 2026-01-22 00:04:30 +01:00
feat: only track reading progress for articles above minimum length
- Add MIN_CONTENT_LENGTH constant (1000 chars ≈ 150 words) to config/kinds - Create shouldTrackReadingProgress helper to validate content length - Strip HTML tags when calculating character count - Only save reading progress for articles meeting the threshold - Log when content is too short to track This prevents noisy tracking of very short articles or excerpts.
This commit is contained in:
@@ -123,3 +123,15 @@ export function createParallelReqStreams(
|
||||
return { local$, remote$ }
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if content is long enough to track reading progress
|
||||
* Minimum 1000 characters (roughly 150 words)
|
||||
*/
|
||||
export const shouldTrackReadingProgress = (html: string | undefined, markdown: string | undefined): boolean => {
|
||||
const { READING_PROGRESS } = require('../config/kinds')
|
||||
const content = (html || markdown || '').trim()
|
||||
// Strip HTML tags to get character count
|
||||
const plainText = content.replace(/<[^>]*>/g, '').trim()
|
||||
return plainText.length >= READING_PROGRESS.MIN_CONTENT_LENGTH
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user