Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create troubleshooting-structure-adjustment.js #59

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Loading