feat: export creation date in dumped content (#2345)
* Export creation date in dumped content * date_creation -> dateCreated Co-authored-by: Joris Langlois <joris.langlois@knplabs.com>
This commit is contained in:
parent
ae733392f3
commit
cda1f1e805
@ -72,7 +72,8 @@ module.exports = {
|
|||||||
['published', page.isPublished.toString()],
|
['published', page.isPublished.toString()],
|
||||||
['date', page.updatedAt],
|
['date', page.updatedAt],
|
||||||
['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''],
|
['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''],
|
||||||
['editor', page.editorKey]
|
['editor', page.editorKey],
|
||||||
|
['dateCreated', page.createdAt],
|
||||||
]
|
]
|
||||||
switch (page.contentType) {
|
switch (page.contentType) {
|
||||||
case 'markdown':
|
case 'markdown':
|
||||||
|
@ -126,7 +126,7 @@ module.exports = {
|
|||||||
|
|
||||||
// -> Pages
|
// -> Pages
|
||||||
await pipeline(
|
await pipeline(
|
||||||
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt').select().from('pages').where({
|
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({
|
||||||
isPrivate: false
|
isPrivate: false
|
||||||
}).stream(),
|
}).stream(),
|
||||||
new stream.Transform({
|
new stream.Transform({
|
||||||
|
@ -127,7 +127,7 @@ module.exports = {
|
|||||||
|
|
||||||
// -> Pages
|
// -> Pages
|
||||||
await pipeline(
|
await pipeline(
|
||||||
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt').select().from('pages').where({
|
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({
|
||||||
isPrivate: false
|
isPrivate: false
|
||||||
}).stream(),
|
}).stream(),
|
||||||
new stream.Transform({
|
new stream.Transform({
|
||||||
|
@ -411,7 +411,7 @@ module.exports = {
|
|||||||
|
|
||||||
// -> Pages
|
// -> Pages
|
||||||
await pipeline(
|
await pipeline(
|
||||||
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt').select().from('pages').where({
|
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({
|
||||||
isPrivate: false
|
isPrivate: false
|
||||||
}).stream(),
|
}).stream(),
|
||||||
new stream.Transform({
|
new stream.Transform({
|
||||||
|
@ -131,7 +131,7 @@ module.exports = class S3CompatibleStorage {
|
|||||||
|
|
||||||
// -> Pages
|
// -> Pages
|
||||||
await pipeline(
|
await pipeline(
|
||||||
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt').select().from('pages').where({
|
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({
|
||||||
isPrivate: false
|
isPrivate: false
|
||||||
}).stream(),
|
}).stream(),
|
||||||
new stream.Transform({
|
new stream.Transform({
|
||||||
|
@ -115,7 +115,7 @@ module.exports = {
|
|||||||
|
|
||||||
// -> Pages
|
// -> Pages
|
||||||
await pipeline(
|
await pipeline(
|
||||||
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt').select().from('pages').where({
|
WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({
|
||||||
isPrivate: false
|
isPrivate: false
|
||||||
}).stream(),
|
}).stream(),
|
||||||
new stream.Transform({
|
new stream.Transform({
|
||||||
|
@ -1,43 +1,62 @@
|
|||||||
const { injectPageMetadata } = require('../../helpers/page')
|
const { injectPageMetadata } = require('../../helpers/page')
|
||||||
|
|
||||||
describe('injectPageMetadata tests', () => {
|
describe('helpers/page/injectPageMetadata', () => {
|
||||||
let page = {
|
const page = {
|
||||||
title: 'PAGE TITLE',
|
title: 'PAGE TITLE',
|
||||||
description: 'A PAGE',
|
description: 'A PAGE',
|
||||||
isPublished: true,
|
isPublished: true,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
content: 'TEST CONTENT'
|
content: 'TEST CONTENT',
|
||||||
|
createdAt: new Date('2019-01-01'),
|
||||||
}
|
}
|
||||||
test('injectPageMetadata: default', () => {
|
|
||||||
|
it('returns the page content by default when content type is unknown', () => {
|
||||||
const expected = 'TEST CONTENT'
|
const expected = 'TEST CONTENT'
|
||||||
const result = injectPageMetadata(page)
|
const result = injectPageMetadata(page)
|
||||||
expect(result).toEqual(expected)
|
expect(result).toEqual(expected)
|
||||||
})
|
})
|
||||||
test('injectPageMetadata: markdown', () => {
|
|
||||||
page.contentType = 'markdown'
|
it('injects metadata for markdown contents', () => {
|
||||||
|
const markdownPage = {
|
||||||
|
...page,
|
||||||
|
contentType: 'markdown',
|
||||||
|
editorKey: 'markdown',
|
||||||
|
}
|
||||||
|
|
||||||
const expected = `---
|
const expected = `---
|
||||||
title: ${page.title}
|
title: ${markdownPage.title}
|
||||||
description: ${page.description}
|
description: ${markdownPage.description}
|
||||||
published: ${page.isPublished.toString()}
|
published: ${markdownPage.isPublished.toString()}
|
||||||
date: ${page.updatedAt}
|
date: ${markdownPage.updatedAt}
|
||||||
tags: \n---
|
tags:\x20
|
||||||
|
editor: ${markdownPage.editorKey}
|
||||||
|
dateCreated: ${markdownPage.createdAt}\n---
|
||||||
|
|
||||||
TEST CONTENT`
|
TEST CONTENT`
|
||||||
const result = injectPageMetadata(page)
|
|
||||||
|
const result = injectPageMetadata(markdownPage)
|
||||||
expect(result).toEqual(expected)
|
expect(result).toEqual(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('injectPageMetadata: hmtl', () => {
|
it('injects metadata for html contents', () => {
|
||||||
page.contentType = 'html'
|
const htmlPage = {
|
||||||
|
...page,
|
||||||
|
contentType: 'html',
|
||||||
|
editorKey: 'html',
|
||||||
|
}
|
||||||
|
|
||||||
const expected = `<!--
|
const expected = `<!--
|
||||||
title: ${page.title}
|
title: ${htmlPage.title}
|
||||||
description: ${page.description}
|
description: ${htmlPage.description}
|
||||||
published: ${page.isPublished.toString()}
|
published: ${htmlPage.isPublished.toString()}
|
||||||
date: ${page.updatedAt}
|
date: ${htmlPage.updatedAt}
|
||||||
tags: \n-->
|
tags:\x20
|
||||||
|
editor: ${htmlPage.editorKey}
|
||||||
|
dateCreated: ${htmlPage.createdAt}\n-->
|
||||||
|
|
||||||
TEST CONTENT`
|
TEST CONTENT`
|
||||||
const result = injectPageMetadata(page)
|
|
||||||
|
const result = injectPageMetadata(htmlPage)
|
||||||
expect(result).toEqual(expected)
|
expect(result).toEqual(expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user