diff --git a/.github/scripts/update-changelog.js b/.github/scripts/update-changelog.js index b0dd9ec0bf..a575df68ec 100644 --- a/.github/scripts/update-changelog.js +++ b/.github/scripts/update-changelog.js @@ -1,37 +1,6 @@ const fs = require("fs"); -const addedContent = fs - .readFileSync("added-content.txt") - .toString() - .split("\n"); - -if ( - addedContent.length === 0 || - (addedContent.length > 0 && addedContent[0] === "") -) { - return; -} - -const currentDate = new Date(); -const currentYear = currentDate.getFullYear(); -const monthNames = [ - "Январь", - "Февраль", - "Март", - "Апрель", - "Май", - "Июнь", - "Июль", - "Август", - "Сентябрь", - "Октябрь", - "Ноябрь", - "Декабрь", -]; -const currentMonth = monthNames[currentDate.getMonth()]; -const header = `## ${currentMonth} ${currentYear}`; - -const contentList = addedContent.map((fileName) => { +function extractInfo(fileName) { if (fs.existsSync(fileName)) { const url = `https://doka.guide/${fileName.replace("index.md", "")}`; const date = process.argv[2]; @@ -50,6 +19,7 @@ const contentList = addedContent.map((fileName) => { .split("\n") .slice(1, -1) .map((s) => s.replace(" - ", "")) + .filter((a) => a !== 'doka-dog') .map((a) => { const authorFileName = `./people/${a}/index.md`; if (fs.existsSync(authorFileName)) { @@ -65,23 +35,90 @@ const contentList = addedContent.map((fileName) => { return `- ${date}, [${title}](${url}), ${authors.join(", ")}`; } -}); + return null; +} + +const changelogFileName = "./CHANGELOG.md"; + +const currentDate = new Date(); +const currentYear = currentDate.getFullYear(); +const monthNames = [ + "Январь", + "Февраль", + "Март", + "Апрель", + "Май", + "Июнь", + "Июль", + "Август", + "Сентябрь", + "Октябрь", + "Ноябрь", + "Декабрь", +]; +const currentMonth = monthNames[currentDate.getMonth()]; +const header = `## ${currentMonth} ${currentYear}`; + +const addedContent = fs + .readFileSync("added-content.txt") + .toString() + .split("\n"); + +if ( + addedContent.length === 0 || + (addedContent.length > 0 && addedContent[0] === "") +) { + return; +} + +const addedContentList = addedContent.map((fileName) => extractInfo(fileName)); + +if (addedContentList.length > 0) { + if (fs.existsSync(changelogFileName)) { + const changelog = fs.readFileSync(changelogFileName).toString().split("\n"); + if (changelog.filter((s) => s.startsWith("## ")).includes(header)) { + const headerPosition = changelog.findIndex((s) => s === header); + changelog.splice(headerPosition + 2, 0, ...addedContentList); + } else { + const headerPosition = 4; + changelog.splice(headerPosition, 0, ...[header, "", ""]); + changelog.splice(headerPosition + 2, 0, ...addedContentList); + } + fs.writeFileSync(changelogFileName, changelog.join("\n")); + console.log("Новые материалы добавлены в CHANGELOG.md"); + } +} else { + console.log("Нечего добавлять из списка новых материалов в CHANGELOG.md"); +} + +const updatedContent = fs + .readFileSync("updated-content.txt") + .toString() + .split("\n"); + +if ( + updatedContent.length === 0 || + (updatedContent.length > 0 && updatedContent[0] === "") +) { + return; +} + +const updatedContentList = updatedContent.map((fileName) => extractInfo(fileName)); -if (contentList.length > 0) { - const changelogFileName = "./CHANGELOG.md"; +if (updatedContentList.length > 0) { if (fs.existsSync(changelogFileName)) { const changelog = fs.readFileSync(changelogFileName).toString().split("\n"); if (changelog.filter((s) => s.startsWith("## ")).includes(header)) { const headerPosition = changelog.findIndex((s) => s === header); - changelog.splice(headerPosition + 2, 0, ...contentList); + changelog.splice(headerPosition + 2, 0, ...updatedContentList); } else { const headerPosition = 4; changelog.splice(headerPosition, 0, ...[header, "", ""]); - changelog.splice(headerPosition + 2, 0, ...contentList); + changelog.splice(headerPosition + 2, 0, ...updatedContentList); } fs.writeFileSync(changelogFileName, changelog.join("\n")); - console.log("Записи добавлены в CHANGELOG.md"); + console.log("Бывшие плейсхолдеры добавлены в CHANGELOG.md"); } } else { - console.log("Нечего добавлять в CHANGELOG.md"); + console.log("Нечего добавлять из списка бывших плейсхолдеров в CHANGELOG.md"); } diff --git a/.github/scripts/update-changelog.sh b/.github/scripts/update-changelog.sh index 138483e254..188c6dc685 100644 --- a/.github/scripts/update-changelog.sh +++ b/.github/scripts/update-changelog.sh @@ -1,5 +1,6 @@ #!/bin/bash git diff --name-status HEAD^ HEAD | grep '^A' | grep -E '(html|css|js|tools|a11y|recipes)\/.*\/index\.md' | sed 's/^A\t//g' > added-content.txt +git diff -S"placeholder" --name-status HEAD^ HEAD | grep '^M' | grep -E '(html|css|js|tools|a11y|recipes)\/.*\/index\.md' | sed 's/^M\t//g' > updated-content.txt if [ -s added-content.txt ]; then MONTH_TO_RUS() { @@ -28,6 +29,7 @@ if [ -s added-content.txt ]; then node .github/scripts/update-changelog.js "$FORMATTED_DATE" rm -f added-content.txt + rm -f updated-content.txt if [[ -z $(git status -s) ]] then diff --git a/CHANGELOG.md b/CHANGELOG.md index 84fc46ec31..0c49cfe67c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,11 @@ ## Июль 2024 - 23 июля, [Слайдер](https://doka.guide/recipes/slider/), Анна Бараулина - - 22 июля, [Стилизация чекбоксов и радиокнопок](https://doka.guide/recipes/checkbox-radio-style/), Михаил Кривдин +- 19 июля, [`.isSubsetOf()`](https://doka.guide/js/set-is-subset-of/), Viktar Nezhbart - 19 июля, [`.intersection()`](https://doka.guide/js/set-intersection/), Viktar Nezhbart - 19 июля, [`.difference()`](https://doka.guide/js/set-difference/), Viktar Nezhbart +- 16 июля, [`Atomics`](https://doka.guide/js/atomics/), Всеволод Золотов - 12 июля, [`.union()`](https://doka.guide/js/set-union/), Viktar Nezhbart - 1 июля, [`.symmetricDifference()`](https://doka.guide/js/set-symmetric-difference/), Viktar Nezhbart