Skip to content

Commit

Permalink
Update troubleshooting-structure-adjustment.js
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroAntunesCosta committed Nov 8, 2024
1 parent 1b87e89 commit 071a1a9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions docs-utils/troubleshooting-structure-adjustment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ const locales = ['en', 'pt', 'es']
function moveArticleTagsToFrontmatter(filePath) {

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

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)

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) {
Expand All @@ -24,7 +26,6 @@ function moveAllTags(folderPath) {
dir = `${folderPath}/${dir}`
console.log(dir)
if (fs.statSync(dir).isFile() && (dir.endsWith('.md') || dir.endsWith('.mdx'))) {
console.log('if')
moveArticleTagsToFrontmatter(dir)
} else {
moveAllTags(dir)
Expand Down

0 comments on commit 071a1a9

Please sign in to comment.