Display full path as basename, getAliasesFromMetadata(): return an array instead of a string
This commit is contained in:
@@ -3,21 +3,19 @@ import { getAliasesFromMetadata } from '../utils'
|
||||
|
||||
describe('Utils', () => {
|
||||
describe('getAliasesFromMetadata', () => {
|
||||
it('should return an empty string if no metadata is provided', () => {
|
||||
it('should return an empty array if no metadata is provided', () => {
|
||||
// Act
|
||||
const actual = getAliasesFromMetadata(null)
|
||||
// Assert
|
||||
expect(actual).toBe('')
|
||||
expect(actual).toEqual([])
|
||||
})
|
||||
it('should return an empty string if no aliases are provided', () => {
|
||||
// Arrange
|
||||
const metadata = {} as CachedMetadata
|
||||
it('should return an empty array if no aliases are provided', () => {
|
||||
// Act
|
||||
const actual = getAliasesFromMetadata(metadata)
|
||||
const actual = getAliasesFromMetadata({})
|
||||
// Assert
|
||||
expect(actual).toBe('')
|
||||
expect(actual).toEqual([])
|
||||
})
|
||||
it('should join aliases with a comma', () => {
|
||||
it('should return the aliases array as-is', () => {
|
||||
// Arrange
|
||||
const metadata = {
|
||||
frontmatter: { aliases: ['foo', 'bar'] },
|
||||
@@ -25,9 +23,9 @@ describe('Utils', () => {
|
||||
// Act
|
||||
const actual = getAliasesFromMetadata(metadata)
|
||||
// Assert
|
||||
expect(actual).toBe('foo, bar')
|
||||
expect(actual).toEqual(['foo', 'bar'])
|
||||
})
|
||||
it('should return a single alias if only one is provided', () => {
|
||||
it('should convert the aliases string into an array', () => {
|
||||
// Arrange
|
||||
const metadata = {
|
||||
frontmatter: { aliases: 'foo, bar' },
|
||||
@@ -35,7 +33,17 @@ describe('Utils', () => {
|
||||
// Act
|
||||
const actual = getAliasesFromMetadata(metadata)
|
||||
// Assert
|
||||
expect(actual).toBe('foo, bar')
|
||||
expect(actual).toEqual(['foo', 'bar'])
|
||||
})
|
||||
it('should return an empty array if the aliases field is an empty string', () => {
|
||||
// Arrange
|
||||
const metadata = {
|
||||
frontmatter: { aliases: '' },
|
||||
} as CachedMetadata
|
||||
// Act
|
||||
const actual = getAliasesFromMetadata(metadata)
|
||||
// Assert
|
||||
expect(actual).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -228,10 +228,10 @@ export async function addToIndex(file: TAbstractFile): Promise<void> {
|
||||
|
||||
// Make the document and index it
|
||||
const note: IndexedNote = {
|
||||
basename: file.basename,
|
||||
basename: file.path,
|
||||
content,
|
||||
path: file.path,
|
||||
aliases: getAliasesFromMetadata(metadata),
|
||||
aliases: getAliasesFromMetadata(metadata).join(''),
|
||||
headings1: metadata
|
||||
? extractHeadingsFromCache(metadata, 1).join(' ')
|
||||
: '',
|
||||
@@ -242,6 +242,7 @@ export async function addToIndex(file: TAbstractFile): Promise<void> {
|
||||
? extractHeadingsFromCache(metadata, 3).join(' ')
|
||||
: '',
|
||||
}
|
||||
|
||||
minisearchInstance.add(note)
|
||||
indexedNotes[note.path] = note
|
||||
}
|
||||
|
||||
@@ -150,7 +150,9 @@ export function stripMarkdownCharacters(text: string): string {
|
||||
|
||||
export function getAliasesFromMetadata(
|
||||
metadata: CachedMetadata | null,
|
||||
): string {
|
||||
): string[] {
|
||||
const arrOrString = metadata?.frontmatter?.aliases ?? []
|
||||
return Array.isArray(arrOrString) ? arrOrString.join(', ') : arrOrString
|
||||
return (Array.isArray(arrOrString) ? arrOrString : arrOrString.split(','))
|
||||
.map(s => s ? s.trim() : s)
|
||||
.filter(s => !!s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user