|
|
|
@ -1,7 +1,13 @@ |
|
|
|
export function estimateReadingTime(content: string = ''): string { |
|
|
|
const noWhitespace = content.replace(/\s/g, '').length |
|
|
|
const minutes = Math.ceil(noWhitespace / 400) |
|
|
|
return `${minutes} 分钟` |
|
|
|
const plain = content |
|
|
|
.replace(/<[^>]*>/g, ' ') |
|
|
|
.replace(/&[a-zA-Z#0-9]+;/g, ' ') |
|
|
|
.replace(/\s+/g, ' ') |
|
|
|
.trim() |
|
|
|
const cjk = (plain.match(/[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/g) ?? []).length |
|
|
|
const words = plain.length === 0 ? 0 : plain.trim().split(/\s+/).length |
|
|
|
const minutes = Math.max(1, Math.ceil((cjk + words) / 400)) |
|
|
|
return `约 ${minutes} 分钟` |
|
|
|
} |
|
|
|
|
|
|
|
export function formatDay(iso: string): string { |
|
|
|
|