refactor: move frontmatter parser into commons package

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-19 11:49:29 +02:00
parent 4d0a2cb79e
commit db43e1db3f
26 changed files with 462 additions and 321 deletions

View file

@ -3,9 +3,12 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import {
NoteFrontmatter,
NoteTextDirection,
NoteType
} from '../note-frontmatter/frontmatter.js'
import { generateNoteTitle } from './generate-note-title.js'
import { NoteFrontmatter, NoteTextDirection } from './types/frontmatter.js'
import { NoteType } from './types/frontmatter.js'
import { describe, expect, it } from '@jest/globals'
const testFrontmatter: NoteFrontmatter = {
@ -36,7 +39,7 @@ describe('generate note title', () => {
title: 'frontmatter',
opengraph: { title: 'opengraph' }
},
'first-heading'
() => 'first-heading'
)
expect(actual).toEqual('frontmatter')
})
@ -44,13 +47,16 @@ describe('generate note title', () => {
it('will choose the opengraph title second', () => {
const actual = generateNoteTitle(
{ ...testFrontmatter, opengraph: { title: 'opengraph' } },
'first-heading'
() => 'first-heading'
)
expect(actual).toEqual('opengraph')
})
it('will choose the first heading third', () => {
const actual = generateNoteTitle({ ...testFrontmatter }, 'first-heading')
const actual = generateNoteTitle(
{ ...testFrontmatter },
() => 'first-heading'
)
expect(actual).toEqual('first-heading')
})
})