From 28fdf1400280bd666ad94cacb4688690a63bd6ae Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sun, 27 Oct 2019 15:56:39 -0400 Subject: [PATCH] fix: export + import tags in storage events --- server/helpers/page.js | 2 +- server/models/tags.js | 2 ++ server/modules/storage/disk/common.js | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/helpers/page.js b/server/helpers/page.js index 286f8438..835425cf 100644 --- a/server/helpers/page.js +++ b/server/helpers/page.js @@ -71,7 +71,7 @@ module.exports = { ['description', page.description], ['published', page.isPublished.toString()], ['date', page.updatedAt], - ['tags', ''] + ['tags', page.tags ? page.tags.map(t => t.tag).join(', ') : ''] ] const inject = { 'markdown': '---\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n---\n\n' + page.content, diff --git a/server/models/tags.js b/server/models/tags.js index 7acca6db..b2424a4a 100644 --- a/server/models/tags.js +++ b/server/models/tags.js @@ -95,5 +95,7 @@ module.exports = class Tag extends Model { if (tagsToUnrelate.length > 0) { await page.$relatedQuery('tags').unrelate().whereIn('tags.id', _.map(tagsToUnrelate, 'id')) } + + page.tags = targetTags } } diff --git a/server/modules/storage/disk/common.js b/server/modules/storage/disk/common.js index 5c1bc820..8b28f546 100644 --- a/server/modules/storage/disk/common.js +++ b/server/modules/storage/disk/common.js @@ -75,10 +75,11 @@ module.exports = { const contentPath = pageHelper.getPagePath(relPath) const itemContents = await fs.readFile(path.join(fullPath, relPath), 'utf8') const pageData = WIKI.models.pages.parseMetadata(itemContents, contentType) - const currentPage = await WIKI.models.pages.query().findOne({ + const currentPage = await WIKI.models.pages.getPageFromDb({ path: contentPath.path, - localeCode: contentPath.locale + locale: contentPath.locale }) + const newTags = !_.isNil(pageData.tags) ? _.get(pageData, 'tags', '').split(', ') : false if (currentPage) { // Already in the DB, can mark as modified WIKI.logger.info(`(STORAGE/${moduleName}) Page marked as modified: ${relPath}`) @@ -86,6 +87,7 @@ module.exports = { id: currentPage.id, title: _.get(pageData, 'title', currentPage.title), description: _.get(pageData, 'description', currentPage.description) || '', + tags: newTags || currentPage.tags.map(t => t.tag), isPublished: _.get(pageData, 'isPublished', currentPage.isPublished), isPrivate: false, content: pageData.content, @@ -101,6 +103,7 @@ module.exports = { locale: contentPath.locale, title: _.get(pageData, 'title', _.last(contentPath.path.split('/'))), description: _.get(pageData, 'description', '') || '', + tags: newTags || [], isPublished: _.get(pageData, 'isPublished', true), isPrivate: false, content: pageData.content,