mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-07 18:04:56 -04:00
Add ability to use yaml-array for tags (#874)
This commit is contained in:
parent
bf42b9c460
commit
b2cf2f134e
8 changed files with 107 additions and 9 deletions
|
@ -69,7 +69,7 @@ describe('yaml tests', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('tags only', () => {
|
||||
it('tags only (old syntax)', () => {
|
||||
testMetadata(`---
|
||||
tags: test123, abc
|
||||
___
|
||||
|
@ -78,10 +78,41 @@ describe('yaml tests', () => {
|
|||
tags: 'test123, abc'
|
||||
},
|
||||
{
|
||||
tags: ['test123', 'abc']
|
||||
tags: ['test123', 'abc'],
|
||||
deprecatedTagsSyntax: true
|
||||
})
|
||||
})
|
||||
|
||||
it('tags only', () => {
|
||||
testMetadata(`---
|
||||
tags:
|
||||
- test123
|
||||
- abc
|
||||
___
|
||||
`,
|
||||
{
|
||||
tags: ['test123', 'abc']
|
||||
},
|
||||
{
|
||||
tags: ['test123', 'abc'],
|
||||
deprecatedTagsSyntax: false
|
||||
})
|
||||
})
|
||||
|
||||
it('tags only (alternative syntax)', () => {
|
||||
testMetadata(`---
|
||||
tags: ['test123', 'abc']
|
||||
___
|
||||
`,
|
||||
{
|
||||
tags: ['test123', 'abc']
|
||||
},
|
||||
{
|
||||
tags: ['test123', 'abc'],
|
||||
deprecatedTagsSyntax: false
|
||||
})
|
||||
})
|
||||
|
||||
it('breaks only', () => {
|
||||
testMetadata(`---
|
||||
breaks: false
|
||||
|
|
|
@ -11,7 +11,7 @@ type iso6391 = 'aa' | 'ab' | 'af' | 'am' | 'ar' | 'ar-ae' | 'ar-bh' | 'ar-dz' |
|
|||
export interface RawYAMLMetadata {
|
||||
title: string | undefined
|
||||
description: string | undefined
|
||||
tags: string | undefined
|
||||
tags: string | string[] | undefined
|
||||
robots: string | undefined
|
||||
lang: string | undefined
|
||||
dir: string | undefined
|
||||
|
@ -27,6 +27,7 @@ export class YAMLMetaData {
|
|||
title: string
|
||||
description: string
|
||||
tags: string[]
|
||||
deprecatedTagsSyntax: boolean
|
||||
robots: string
|
||||
lang: iso6391
|
||||
dir: 'ltr' | 'rtl'
|
||||
|
@ -53,7 +54,16 @@ export class YAMLMetaData {
|
|||
transition: 'none',
|
||||
theme: 'white'
|
||||
} */
|
||||
this.tags = rawData?.tags?.split(',').map(entry => entry.trim()) ?? []
|
||||
if (typeof rawData?.tags === 'string') {
|
||||
this.tags = rawData?.tags?.split(',').map(entry => entry.trim()) ?? []
|
||||
this.deprecatedTagsSyntax = true
|
||||
} else if (typeof rawData?.tags === 'object') {
|
||||
this.tags = rawData?.tags?.filter(tag => tag !== null) ?? []
|
||||
this.deprecatedTagsSyntax = false
|
||||
} else {
|
||||
this.tags = []
|
||||
this.deprecatedTagsSyntax = false
|
||||
}
|
||||
this.opengraph = rawData?.opengraph ? new Map<string, string>(Object.entries(rawData.opengraph)) : new Map<string, string>()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue