Skip to content

Commit

Permalink
Merge pull request #59 from vtexdocs/feat/troubleshooting-content-mig…
Browse files Browse the repository at this point in the history
…ration-adjustment-2

Create troubleshooting-structure-adjustment.js
  • Loading branch information
PedroAntunesCosta authored Nov 19, 2024
2 parents 20992fd + ba6fe1a commit 3eb5bc7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions docs-utils/troubleshooting-structure-adjustment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// We couldn't get this to work by being called at index.js. This has to be run manually
const fs = require('fs');
const path = require('path');

const locales = ['en', 'pt', 'es']

function moveArticleTagsToFrontmatter(filePath) {

const fileContent = fs.readFileSync(filePath, 'utf-8')

if (fileContent.includes('**Tags:**')) {
const tags = fileContent.split('**Tags:**')[1].split('\n')[0]
const frontMatter = fileContent.split('---')[1]
const text = fileContent.split('---')[2].replace(/^.*Tags:.*$/m, '').trim()

// Assemble everything
const newContent = '---'+frontMatter+`tags: ${tags}\n---\n\n`+text

fs.writeFileSync(filePath, newContent)
}
}

function moveAllTags(folderPath) {

console.log('Adjusting tags')
const folderContent = fs.readdirSync(folderPath)
for (dir of folderContent) {
dir = `${folderPath}/${dir}`
console.log(dir)
if (fs.statSync(dir).isFile() && (dir.endsWith('.md') || dir.endsWith('.mdx'))) {
console.log('FILE')
moveArticleTagsToFrontmatter(dir)
} else {
console.log('FOLDER')
moveAllTags(dir)
}
}
}

async function adjustTroubleshootingContent() {
console.log('Adjusting troubleshooting content...')
for (locale of locales) {
const oldPath = path.resolve(`../help-center-content/docs/${locale}/tutorials/troubleshooting`)
const newPath = path.resolve(`../help-center-content/docs/${locale}/troubleshooting`)
fs.renameSync(oldPath, newPath)
moveAllTags(newPath)
}
}

adjustTroubleshootingContent()

module.exports = { adjustTroubleshootingContent }

0 comments on commit 3eb5bc7

Please sign in to comment.