Removed duplicated code
This commit is contained in:
15
src/utils.ts
15
src/utils.ts
@@ -1,5 +1,7 @@
|
||||
import type { CachedMetadata } from 'obsidian'
|
||||
import {
|
||||
excerptAfter,
|
||||
excerptBefore,
|
||||
highlightClass,
|
||||
isSearchMatch,
|
||||
regexLineSplit,
|
||||
@@ -82,3 +84,16 @@ export function extractHeadingsFromCache(
|
||||
export function loopIndex(index: number, nbItems: number): number {
|
||||
return (index + nbItems) % nbItems
|
||||
}
|
||||
|
||||
export function makeExcerpt(content: string, offset: number): string {
|
||||
const pos = offset ?? -1
|
||||
if (pos > -1) {
|
||||
const from = Math.max(0, pos - excerptBefore)
|
||||
const to = Math.min(content.length - 1, pos + excerptAfter)
|
||||
content =
|
||||
(from > 0 ? '…' : '') +
|
||||
content.slice(from, to).trim() +
|
||||
(to < content.length - 1 ? '…' : '')
|
||||
}
|
||||
return escapeHTML(content)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user