Add ability to use yaml-array for tags (#874)

This commit is contained in:
Erik Michelson 2021-01-04 13:01:34 +01:00 committed by GitHub
parent bf42b9c460
commit b2cf2f134e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 9 deletions

View file

@ -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

View file

@ -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>()
}
}