-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from vtexdocs/feat/troubleshooting-content-mig…
…ration-adjustment-2 Create troubleshooting-structure-adjustment.js
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |