From 5753195f2e066600ab3e7f0bb59df387f18f9de0 Mon Sep 17 00:00:00 2001 From: currenjin Date: Fri, 26 Jan 2024 00:26:40 +0900 Subject: [PATCH] Fix: workflows --- .github/workflows/convert-yml-to-md.js | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/convert-yml-to-md.js b/.github/workflows/convert-yml-to-md.js index 6beab68..e493d37 100644 --- a/.github/workflows/convert-yml-to-md.js +++ b/.github/workflows/convert-yml-to-md.js @@ -1,12 +1,6 @@ const fs = require('fs'); const yaml = require('js-yaml'); -const categoriesContent = fs.readFileSync('./categories.yml', 'utf-8'); -const categories = yaml.load(categoriesContent); - -const sitesContent = fs.readFileSync('./sites.yml', 'utf-8'); -const sites = yaml.load(sitesContent); - const initContent = ` ## 어떤 저장소인가요? - 개발자가 참고하면 좋은 대표적인 사이트를 모아놓은 북마크 저장소입니다. 한 분 한 분에게 도움이 되었으면 좋겠습니다. 🙏🏾 @@ -22,15 +16,32 @@ const initContent = ` function generateMarkdown(categories, sites) { let markdown = initContent; - categories.forEach(category => { - markdown += `## ${category.text}\n`; + + categories.forEach((category, index) => { + const categoryName = category.text; + const depth = index + 2; + + markdown += `${'#'.repeat(depth)} ${categoryName}\n`; + const categorySites = sites.filter(site => site.categories.includes(category.category)); categorySites.forEach(site => { - markdown += `- [${site.name}](${site.link}) - ${site.description}\n`; + const { name, link, description } = site; + markdown += `${'#'.repeat(depth + 1)} [${name}](${link}) - ${description}\n`; }); + + markdown += '\n'; }); + return markdown; } -const readmeContent = generateMarkdown(categories, sites); -fs.writeFileSync('./README.md', readmeContent); +const categoriesContent = fs.readFileSync('./categories.yml', 'utf-8'); +const categories = yaml.load(categoriesContent); + +const sitesContent = fs.readFileSync('./sites.yml', 'utf-8'); +const sites = yaml.load(sitesContent); + +const generatedMarkdown = generateMarkdown(categories, sites); + +fs.writeFileSync('./README.md', generatedMarkdown, 'utf8'); +