From cda1f1e8056db452019bf09eadbd25ea15c4490a Mon Sep 17 00:00:00 2001 From: jaljo Date: Mon, 31 Aug 2020 17:28:55 +0200 Subject: [PATCH] feat: export creation date in dumped content (#2345) * Export creation date in dumped content * date_creation -> dateCreated Co-authored-by: Joris Langlois --- server/helpers/page.js | 3 +- server/modules/storage/azure/storage.js | 2 +- server/modules/storage/disk/storage.js | 2 +- server/modules/storage/git/storage.js | 2 +- server/modules/storage/s3/common.js | 2 +- server/modules/storage/sftp/storage.js | 2 +- server/test/helpers/page.test.js | 59 ++++++++++++++++--------- 7 files changed, 46 insertions(+), 26 deletions(-) diff --git a/server/helpers/page.js b/server/helpers/page.js index 67d37663..5b3079a8 100644 --- a/server/helpers/page.js +++ b/server/helpers/page.js @@ -72,7 +72,8 @@ module.exports = { ['published', page.isPublished.toString()], ['date', page.updatedAt], ['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''], - ['editor', page.editorKey] + ['editor', page.editorKey], + ['dateCreated', page.createdAt], ] switch (page.contentType) { case 'markdown': diff --git a/server/modules/storage/azure/storage.js b/server/modules/storage/azure/storage.js index 69a453aa..f7320146 100644 --- a/server/modules/storage/azure/storage.js +++ b/server/modules/storage/azure/storage.js @@ -126,7 +126,7 @@ module.exports = { // -> Pages 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 }).stream(), new stream.Transform({ diff --git a/server/modules/storage/disk/storage.js b/server/modules/storage/disk/storage.js index 34117378..8f4edce6 100644 --- a/server/modules/storage/disk/storage.js +++ b/server/modules/storage/disk/storage.js @@ -127,7 +127,7 @@ module.exports = { // -> Pages 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 }).stream(), new stream.Transform({ diff --git a/server/modules/storage/git/storage.js b/server/modules/storage/git/storage.js index 4da51a01..e9cf0b46 100644 --- a/server/modules/storage/git/storage.js +++ b/server/modules/storage/git/storage.js @@ -411,7 +411,7 @@ module.exports = { // -> Pages 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 }).stream(), new stream.Transform({ diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index b11bce00..c34e2451 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -131,7 +131,7 @@ module.exports = class S3CompatibleStorage { // -> Pages 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 }).stream(), new stream.Transform({ diff --git a/server/modules/storage/sftp/storage.js b/server/modules/storage/sftp/storage.js index 0684f4cb..e1f99af4 100644 --- a/server/modules/storage/sftp/storage.js +++ b/server/modules/storage/sftp/storage.js @@ -115,7 +115,7 @@ module.exports = { // -> Pages 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 }).stream(), new stream.Transform({ diff --git a/server/test/helpers/page.test.js b/server/test/helpers/page.test.js index 83879163..1ff66e7d 100644 --- a/server/test/helpers/page.test.js +++ b/server/test/helpers/page.test.js @@ -1,43 +1,62 @@ const { injectPageMetadata } = require('../../helpers/page') -describe('injectPageMetadata tests', () => { - let page = { +describe('helpers/page/injectPageMetadata', () => { + const page = { title: 'PAGE TITLE', description: 'A PAGE', isPublished: true, 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 result = injectPageMetadata(page) 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 = `--- -title: ${page.title} -description: ${page.description} -published: ${page.isPublished.toString()} -date: ${page.updatedAt} -tags: \n--- +title: ${markdownPage.title} +description: ${markdownPage.description} +published: ${markdownPage.isPublished.toString()} +date: ${markdownPage.updatedAt} +tags:\x20 +editor: ${markdownPage.editorKey} +dateCreated: ${markdownPage.createdAt}\n--- TEST CONTENT` - const result = injectPageMetadata(page) + + const result = injectPageMetadata(markdownPage) expect(result).toEqual(expected) }) - test('injectPageMetadata: hmtl', () => { - page.contentType = 'html' + it('injects metadata for html contents', () => { + const htmlPage = { + ...page, + contentType: 'html', + editorKey: 'html', + } + const expected = ` +title: ${htmlPage.title} +description: ${htmlPage.description} +published: ${htmlPage.isPublished.toString()} +date: ${htmlPage.updatedAt} +tags:\x20 +editor: ${htmlPage.editorKey} +dateCreated: ${htmlPage.createdAt}\n--> TEST CONTENT` - const result = injectPageMetadata(page) + + const result = injectPageMetadata(htmlPage) expect(result).toEqual(expected) }) })