feat: move page
This commit is contained in:
@@ -109,10 +109,10 @@ module.exports = {
|
||||
* @param {Object} page Page to rename
|
||||
*/
|
||||
async renamed(page) {
|
||||
await this.index.deleteObject(page.sourceHash)
|
||||
await this.index.deleteObject(page.hash)
|
||||
await this.index.addObject({
|
||||
objectID: page.destinationHash,
|
||||
locale: page.localeCode,
|
||||
locale: page.destinationLocaleCode,
|
||||
path: page.destinationPath,
|
||||
title: page.title,
|
||||
description: page.description,
|
||||
|
@@ -255,7 +255,7 @@ module.exports = {
|
||||
documents: JSON.stringify([
|
||||
{
|
||||
type: 'delete',
|
||||
id: page.sourceHash
|
||||
id: page.hash
|
||||
}
|
||||
])
|
||||
}).promise()
|
||||
@@ -266,7 +266,7 @@ module.exports = {
|
||||
type: 'add',
|
||||
id: page.destinationHash,
|
||||
fields: {
|
||||
locale: page.localeCode,
|
||||
locale: page.destinationLocaleCode,
|
||||
path: page.destinationPath,
|
||||
title: page.title,
|
||||
description: page.description,
|
||||
|
@@ -191,13 +191,13 @@ module.exports = {
|
||||
await this.client.indexes.use(this.config.indexName).index([
|
||||
{
|
||||
'@search.action': 'delete',
|
||||
id: page.sourceHash
|
||||
id: page.hash
|
||||
}
|
||||
])
|
||||
await this.client.indexes.use(this.config.indexName).index([
|
||||
{
|
||||
id: page.destinationHash,
|
||||
locale: page.localeCode,
|
||||
locale: page.destinationLocaleCode,
|
||||
path: page.destinationPath,
|
||||
title: page.title,
|
||||
description: page.description,
|
||||
|
@@ -210,7 +210,7 @@ module.exports = {
|
||||
await this.client.delete({
|
||||
index: this.config.indexName,
|
||||
type: '_doc',
|
||||
id: page.sourceHash,
|
||||
id: page.hash,
|
||||
refresh: true
|
||||
})
|
||||
await this.client.index({
|
||||
@@ -219,7 +219,7 @@ module.exports = {
|
||||
id: page.destinationHash,
|
||||
body: {
|
||||
suggest: this.buildSuggest(page),
|
||||
locale: page.localeCode,
|
||||
locale: page.destinationLocaleCode,
|
||||
path: page.destinationPath,
|
||||
title: page.title,
|
||||
description: page.description,
|
||||
|
@@ -129,7 +129,7 @@ module.exports = {
|
||||
locale: page.localeCode,
|
||||
path: page.sourcePath
|
||||
}).update({
|
||||
locale: page.localeCode,
|
||||
locale: page.destinationLocaleCode,
|
||||
path: page.destinationPath
|
||||
})
|
||||
},
|
||||
|
@@ -44,7 +44,7 @@ module.exports = {
|
||||
},
|
||||
async created(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Creating file ${page.path}...`)
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -53,7 +53,7 @@ module.exports = {
|
||||
},
|
||||
async updated(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Updating file ${page.path}...`)
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -62,7 +62,7 @@ module.exports = {
|
||||
},
|
||||
async deleted(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Deleting file ${page.path}...`)
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -70,14 +70,19 @@ module.exports = {
|
||||
await fs.unlink(filePath)
|
||||
},
|
||||
async renamed(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Renaming file ${page.sourcePath} to ${page.destinationPath}...`)
|
||||
let sourceFilePath = `${page.sourcePath}.${page.getFileExtension()}`
|
||||
let destinationFilePath = `${page.destinationPath}.${page.getFileExtension()}`
|
||||
WIKI.logger.info(`(STORAGE/DISK) Renaming file ${page.path} to ${page.destinationPath}...`)
|
||||
let sourceFilePath = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
let destinationFilePath = `${page.destinationPath}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
destinationFilePath = `${page.localeCode}/${destinationFilePath}`
|
||||
if (WIKI.config.lang.namespacing) {
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
}
|
||||
if (WIKI.config.lang.code !== page.destinationLocaleCode) {
|
||||
destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}`
|
||||
}
|
||||
}
|
||||
|
||||
await fs.move(path.join(this.config.path, sourceFilePath), path.join(this.config.path, destinationFilePath), { overwrite: true })
|
||||
},
|
||||
|
||||
@@ -93,7 +98,7 @@ module.exports = {
|
||||
new stream.Transform({
|
||||
objectMode: true,
|
||||
transform: async (page, enc, cb) => {
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
|
@@ -247,7 +247,7 @@ module.exports = {
|
||||
*/
|
||||
async created(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing new file ${page.path}...`)
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -266,7 +266,7 @@ module.exports = {
|
||||
*/
|
||||
async updated(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing updated file ${page.path}...`)
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -285,7 +285,7 @@ module.exports = {
|
||||
*/
|
||||
async deleted(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing removed file ${page.path}...`)
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -301,18 +301,22 @@ module.exports = {
|
||||
* @param {Object} page Page to rename
|
||||
*/
|
||||
async renamed(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing file move from ${page.sourcePath} to ${page.destinationPath}...`)
|
||||
let sourceFilePath = `${page.sourcePath}.${page.getFileExtension()}`
|
||||
let destinationFilePath = `${page.destinationPath}.${page.getFileExtension()}`
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing file move from ${page.path} to ${page.destinationPath}...`)
|
||||
let sourceFilePath = `${page.path}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
let destinationFilePath = `${page.destinationPath}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
destinationFilePath = `${page.localeCode}/${destinationFilePath}`
|
||||
if (WIKI.config.lang.namespacing) {
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
}
|
||||
if (WIKI.config.lang.code !== page.destinationLocaleCode) {
|
||||
destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}`
|
||||
}
|
||||
}
|
||||
|
||||
await this.git.mv(`./${sourceFilePath}`, `./${destinationFilePath}`)
|
||||
await this.git.commit(`docs: rename ${page.sourcePath} to ${destinationFilePath}`, destinationFilePath, {
|
||||
'--author': `"${page.authorName} <${page.authorEmail}>"`
|
||||
await this.git.commit(`docs: rename ${page.path} to ${page.destinationPath}`, destinationFilePath, {
|
||||
'--author': `"${page.moveAuthorName} <${page.moveAuthorEmail}>"`
|
||||
})
|
||||
},
|
||||
/**
|
||||
|
@@ -1,4 +1,5 @@
|
||||
const S3 = require('aws-sdk/clients/s3')
|
||||
const pageHelper = require('../../../helpers/page.js')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -6,7 +7,7 @@ const S3 = require('aws-sdk/clients/s3')
|
||||
* Deduce the file path given the `page` object and the object's key to the page's path.
|
||||
*/
|
||||
const getFilePath = (page, pathKey) => {
|
||||
const fileName = `${page[pathKey]}.${page.getFileExtension()}`
|
||||
const fileName = `${page[pathKey]}.${pageHelper.getFileExtension(page.contentType)}`
|
||||
const withLocaleCode = WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode
|
||||
return withLocaleCode ? `${page.localeCode}/${fileName}` : fileName
|
||||
}
|
||||
@@ -55,9 +56,17 @@ module.exports = class S3CompatibleStorage {
|
||||
await this.s3.deleteObject({ Key: filePath }).promise()
|
||||
}
|
||||
async renamed(page) {
|
||||
WIKI.logger.info(`(STORAGE/${this.storageName}) Renaming file ${page.sourcePath} to ${page.destinationPath}...`)
|
||||
const sourceFilePath = getFilePath(page, 'sourcePath')
|
||||
const destinationFilePath = getFilePath(page, 'destinationPath')
|
||||
WIKI.logger.info(`(STORAGE/${this.storageName}) Renaming file ${page.path} to ${page.destinationPath}...`)
|
||||
let sourceFilePath = `${page.path}.${page.getFileExtension()}`
|
||||
let destinationFilePath = `${page.destinationPath}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.namespacing) {
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
}
|
||||
if (WIKI.config.lang.code !== page.destinationLocaleCode) {
|
||||
destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}`
|
||||
}
|
||||
}
|
||||
await this.s3.copyObject({ CopySource: sourceFilePath, Key: destinationFilePath }).promise()
|
||||
await this.s3.deleteObject({ Key: sourceFilePath }).promise()
|
||||
}
|
||||
|
Reference in New Issue
Block a user