From 663e053b2b846618773aac44d5f87df2a05fead1 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Sat, 12 Oct 2024 16:58:05 +0530 Subject: [PATCH 01/17] add check-md script --- scripts/markdown/check-markdown.js | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/markdown/check-markdown.js diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js new file mode 100644 index 00000000000..3f78489417c --- /dev/null +++ b/scripts/markdown/check-markdown.js @@ -0,0 +1,89 @@ +const fs = require('fs'); +const matter = require('gray-matter'); +const path = require('path'); + +// Helper function to check if a string is a valid URL +function isValidURL(str) { + try { + new URL(str); + return true; + } catch (err) { + return false; + } +} + +// Function to validate frontmatter +function validateFrontmatter(frontmatter, filePath) { + const requiredAttributes = ['title', 'date', 'type', 'tags', 'cover', 'authors']; + const errors = []; + + // Check for required attributes + requiredAttributes.forEach(attr => { + if (!frontmatter.hasOwnProperty(attr)) { + errors.push(`${attr} is missing`); + } + }); + + // Validate date format + if (frontmatter.date && isNaN(Date.parse(frontmatter.date))) { + errors.push(`Invalid date format: ${frontmatter.date}`); + } + + // Validate tags format (must be an array) + if (frontmatter.tags && !Array.isArray(frontmatter.tags)) { + errors.push(`Tags should be an array`); + } + + // Validate cover is a string + if (frontmatter.cover && typeof frontmatter.cover !== 'string') { + errors.push(`Cover must be a string`); + } + + // Validate authors (must be an array with valid attributes) + if (frontmatter.authors) { + if (!Array.isArray(frontmatter.authors)) { + errors.push('Authors should be an array'); + } else { + frontmatter.authors.forEach((author, index) => { + if (!author.name) { + errors.push(`Author at index ${index} is missing a name`); + } + if (author.link && !isValidURL(author.link)) { + errors.push(`Invalid URL for author at index ${index}: ${author.link}`); + } + }); + } + } + + return errors.length ? errors : null; +} + +// Main function to check markdown files +function checkMarkdownFiles(folderPath) { + fs.readdir(folderPath, (err, files) => { + if (err) { + console.error('Error reading directory:', err); + return; + } + + files.forEach(file => { + const filePath = path.join(folderPath, file); + if (path.extname(file) === '.md') { + const fileContent = fs.readFileSync(filePath, 'utf-8'); + const { data: frontmatter } = matter(fileContent); + + const errors = validateFrontmatter(frontmatter, filePath); + if (errors) { + console.error(`Errors in file ${file}:`); + errors.forEach(error => console.error(` - ${error}`)); + } else { + console.log(`File ${file} is valid`); + } + } + }); + }); +} + +// Replace with the path to your folder containing markdown files +const folderPath = './../../markdown/blog'; +checkMarkdownFiles(folderPath); From 25eb795d97833c798285ad539f3a28fc95eff291 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Sat, 12 Oct 2024 12:07:54 +0000 Subject: [PATCH 02/17] fix check-md script --- scripts/markdown/check-markdown.js | 89 +++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 19 deletions(-) diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js index 3f78489417c..4d3e8e54243 100644 --- a/scripts/markdown/check-markdown.js +++ b/scripts/markdown/check-markdown.js @@ -2,7 +2,11 @@ const fs = require('fs'); const matter = require('gray-matter'); const path = require('path'); -// Helper function to check if a string is a valid URL +/** + * Checks if a given string is a valid URL. + * @param {string} str - The string to validate as a URL. + * @returns {boolean} True if the string is a valid URL, false otherwise. + */ function isValidURL(str) { try { new URL(str); @@ -12,8 +16,13 @@ function isValidURL(str) { } } -// Function to validate frontmatter -function validateFrontmatter(frontmatter, filePath) { +/** + * Validates the frontmatter of a blog post. + * @param {object} frontmatter - The frontmatter object to validate. + * @param {string} filePath - The path to the file being validated. + * @returns {string[]|null} An array of validation error messages, or null if no errors. + */ +function validateBlogs(frontmatter) { const requiredAttributes = ['title', 'date', 'type', 'tags', 'cover', 'authors']; const errors = []; @@ -51,6 +60,9 @@ function validateFrontmatter(frontmatter, filePath) { if (author.link && !isValidURL(author.link)) { errors.push(`Invalid URL for author at index ${index}: ${author.link}`); } + if (!author.photo) { + errors.push(`Author at index ${index} is missing a photo`); + } }); } } @@ -58,8 +70,35 @@ function validateFrontmatter(frontmatter, filePath) { return errors.length ? errors : null; } -// Main function to check markdown files -function checkMarkdownFiles(folderPath) { +/** + * Validates the frontmatter of a documentation file. + * @param {object} frontmatter - The frontmatter object to validate. + * @param {string} filePath - The path to the file being validated. + * @returns {string[]|null} An array of validation error messages, or null if no errors. + */ +function validateDocs(frontmatter) { + const errors = []; + + // Check if title exists and is a string + if (!frontmatter.title || typeof frontmatter.title !== 'string') { + errors.push('Title is missing or not a string'); + } + + // Check if weight exists and is a number + if (frontmatter.weight === undefined || typeof frontmatter.weight !== 'number') { + errors.push('Weight is missing or not a number'); + } + + return errors.length ? errors : null; +} + +/** + * Recursively checks markdown files in a folder and validates their frontmatter. + * @param {string} folderPath - The path to the folder to check. + * @param {Function} validateFunction - The function used to validate the frontmatter. + * @param {string} [relativePath=''] - The relative path of the folder for logging purposes. + */ +function checkMarkdownFiles(folderPath, validateFunction, relativePath = '') { fs.readdir(folderPath, (err, files) => { if (err) { console.error('Error reading directory:', err); @@ -68,22 +107,34 @@ function checkMarkdownFiles(folderPath) { files.forEach(file => { const filePath = path.join(folderPath, file); - if (path.extname(file) === '.md') { - const fileContent = fs.readFileSync(filePath, 'utf-8'); - const { data: frontmatter } = matter(fileContent); - - const errors = validateFrontmatter(frontmatter, filePath); - if (errors) { - console.error(`Errors in file ${file}:`); - errors.forEach(error => console.error(` - ${error}`)); - } else { - console.log(`File ${file} is valid`); + const relativeFilePath = path.join(relativePath, file); + + fs.stat(filePath, (err, stats) => { + if (err) { + console.error('Error reading file stats:', err); + return; + } + + // Recurse if directory, otherwise validate markdown file + if (stats.isDirectory()) { + checkMarkdownFiles(filePath, validateFunction, relativeFilePath); + } else if (path.extname(file) === '.md') { + const fileContent = fs.readFileSync(filePath, 'utf-8'); + const { data: frontmatter } = matter(fileContent); + + const errors = validateFunction(frontmatter); + if (errors) { + console.error(`Errors in file ${relativeFilePath}:`); + errors.forEach(error => console.error(` - ${error}`)); + } } - } + }); }); }); } -// Replace with the path to your folder containing markdown files -const folderPath = './../../markdown/blog'; -checkMarkdownFiles(folderPath); +const docsFolderPath = path.resolve(__dirname, '../../markdown/docs'); +const blogsFolderPath = path.resolve(__dirname, '../../markdown/blog'); + +checkMarkdownFiles(docsFolderPath, validateDocs); +checkMarkdownFiles(blogsFolderPath, validateBlogs); From 8f547bdd48dd43d0fbe5f0c50b71e9b38e6dcb08 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 15:36:28 +0000 Subject: [PATCH 03/17] add md test --- .github/workflows/if-nodejs-pr-testing.yml | 36 +++++++++++++++++++++- package.json | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 2154143339c..cb74406a688 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -59,7 +59,7 @@ jobs: name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "${{ steps.nodeversion.outputs.version }}" + node-version: '${{ steps.nodeversion.outputs.version }}' - name: Install dependencies run: npm ci - if: steps.packagejson.outputs.exists == 'true' @@ -72,3 +72,37 @@ jobs: name: Run release assets generation to make sure PR does not break it shell: bash run: npm run generate:assets --if-present + + # Run the test:md script and capture output + - if: steps.packagejson.outputs.exists == 'true' + name: Run markdown checks + id: markdown_check + run: | + OUTPUT=$(npm run test:md || true) + echo "$OUTPUT" | tee markdown_output.txt + echo "::set-output name=markdown_output::$OUTPUT" + shell: bash + + # Parse the output and post a comment on GitHub PR + - name: Post markdown check results + if: steps.packagejson.outputs.exists == 'true' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `steps.markdown_check.outputs.markdown_output`; + let body = "### Markdown Check Results\n\n"; + if (output.includes('Errors in file')) { + const errorLines = output.split('\\n').filter(line => line.startsWith('Errors in file')); + errorLines.forEach(errorLine => { + body += `- ${errorLine}\\n`; + }); + } else { + body += "✅ No markdown issues found."; + } + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: body + }) diff --git a/package.json b/package.json index 04ba37b586e..29269ed3e1d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "generate:videos": "node scripts/build-newsroom-videos.js", "generate:tools": "node scripts/build-tools.js", "test:netlify": "deno test --allow-env --trace-ops netlify/**/*.test.ts", + "test:md": "node scripts/markdown/check-markdown.js", "dev:storybook": "storybook dev -p 6006", "build:storybook": "storybook build" }, From a7d2172270e3cc86f614a44d8ef28e27e56b5d3f Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 15:44:19 +0000 Subject: [PATCH 04/17] change token name --- .github/workflows/if-nodejs-pr-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 402c7ea4879..9adced84db8 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -90,7 +90,7 @@ jobs: if: steps.packagejson.outputs.exists == 'true' uses: actions/github-script@v6 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.GH_TOKEN }} script: | const output = `steps.markdown_check.outputs.markdown_output`; let body = "### Markdown Check Results\n\n"; From 43a97b493b64a4d2678f142c2519ba944fdf7335 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 15:49:20 +0000 Subject: [PATCH 05/17] fix comment logic --- .github/workflows/if-nodejs-pr-testing.yml | 46 +++++++++++----------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 9adced84db8..325ce94bd63 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -85,29 +85,31 @@ jobs: echo "::set-output name=markdown_output::$OUTPUT" shell: bash - # Parse the output and post a comment on GitHub PR - - name: Post markdown check results - if: steps.packagejson.outputs.exists == 'true' - uses: actions/github-script@v6 + + # Post a comment using sticky-pull-request-comment + - name: Comment on PR with markdown issues + if: ${{ always() && steps.markdown_check.outputs.markdown_output != '' }} + uses: marocchino/sticky-pull-request-comment@v2.5.0 + with: + header: markdown-check-error + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + message: | + ### Markdown Check Results + + We found issues in the following markdown files: + + ``` + ${{ steps.markdown_check.outputs.markdown_output }} + ``` + + # Delete the comment if there are no issues + - if: ${{ steps.markdown_check.outputs.markdown_output == '' }} + name: Delete markdown check comment + uses: marocchino/sticky-pull-request-comment@v2.5.0 with: - github-token: ${{ secrets.GH_TOKEN }} - script: | - const output = `steps.markdown_check.outputs.markdown_output`; - let body = "### Markdown Check Results\n\n"; - if (output.includes('Errors in file')) { - const errorLines = output.split('\\n').filter(line => line.startsWith('Errors in file')); - errorLines.forEach(errorLine => { - body += `- ${errorLine}\\n`; - }); - } else { - body += "✅ No markdown issues found."; - } - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: body - }) + header: markdown-check-error + delete: true + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - if: steps.packagejson.outputs.exists == 'true' name: Upload Coverage to Codecov From 284fe3a43de192ebcb9c4dc582cd917917c50adb Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 15:53:14 +0000 Subject: [PATCH 06/17] fix comment logic --- .github/workflows/if-nodejs-pr-testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 325ce94bd63..000c5c099f8 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -89,7 +89,7 @@ jobs: # Post a comment using sticky-pull-request-comment - name: Comment on PR with markdown issues if: ${{ always() && steps.markdown_check.outputs.markdown_output != '' }} - uses: marocchino/sticky-pull-request-comment@v2.5.0 + uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd with: header: markdown-check-error GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} @@ -105,7 +105,7 @@ jobs: # Delete the comment if there are no issues - if: ${{ steps.markdown_check.outputs.markdown_output == '' }} name: Delete markdown check comment - uses: marocchino/sticky-pull-request-comment@v2.5.0 + uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd with: header: markdown-check-error delete: true From 85f5fabad2006857393960689fa3802f75b91751 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:15:18 +0000 Subject: [PATCH 07/17] fix comment logic --- .github/workflows/if-nodejs-pr-testing.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 000c5c099f8..8f120d38be9 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -83,12 +83,10 @@ jobs: OUTPUT=$(npm run test:md || true) echo "$OUTPUT" | tee markdown_output.txt echo "::set-output name=markdown_output::$OUTPUT" - shell: bash - # Post a comment using sticky-pull-request-comment - name: Comment on PR with markdown issues - if: ${{ always() && steps.markdown_check.outputs.markdown_output != '' }} + if: ${{ steps.markdown_check.outputs.markdown_output != '' }} uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd with: header: markdown-check-error From 72886378cc0cee61fb65856dbb68fd28d946af32 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:19:59 +0000 Subject: [PATCH 08/17] update output --- .github/workflows/if-nodejs-pr-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 8f120d38be9..3483321b846 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -82,7 +82,7 @@ jobs: run: | OUTPUT=$(npm run test:md || true) echo "$OUTPUT" | tee markdown_output.txt - echo "::set-output name=markdown_output::$OUTPUT" + echo "markdown_output=$OUTPUT" >> $GITHUB_OUTPUT # Post a comment using sticky-pull-request-comment - name: Comment on PR with markdown issues From 6a9904e67987f78c704a8fa7b306b77ef5d3da5a Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:27:54 +0000 Subject: [PATCH 09/17] update output --- .github/workflows/if-nodejs-pr-testing.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 3483321b846..199f2d3923c 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -81,7 +81,6 @@ jobs: id: markdown_check run: | OUTPUT=$(npm run test:md || true) - echo "$OUTPUT" | tee markdown_output.txt echo "markdown_output=$OUTPUT" >> $GITHUB_OUTPUT # Post a comment using sticky-pull-request-comment From bfa25f941f5472d68c2352a7590e74048bc71608 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:30:16 +0000 Subject: [PATCH 10/17] update output --- .github/workflows/if-nodejs-pr-testing.yml | 4 ++-- scripts/markdown/check-markdown.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 199f2d3923c..c7af64fda9a 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -80,8 +80,8 @@ jobs: name: Run markdown checks id: markdown_check run: | - OUTPUT=$(npm run test:md || true) - echo "markdown_output=$OUTPUT" >> $GITHUB_OUTPUT + ERRORS=$(npm run test:md) + echo "markdown_output=$ERRORS" >> $GITHUB_OUTPUT # Post a comment using sticky-pull-request-comment - name: Comment on PR with markdown issues diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js index 4d3e8e54243..ac4495cead8 100644 --- a/scripts/markdown/check-markdown.js +++ b/scripts/markdown/check-markdown.js @@ -125,7 +125,7 @@ function checkMarkdownFiles(folderPath, validateFunction, relativePath = '') { const errors = validateFunction(frontmatter); if (errors) { console.error(`Errors in file ${relativeFilePath}:`); - errors.forEach(error => console.error(` - ${error}`)); + errors.forEach(error => console.log(` - ${error}`)); } } }); From 56eda46f6b2b8014b0eb4df551d37fdf157451c2 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:43:15 +0000 Subject: [PATCH 11/17] update output --- scripts/markdown/check-markdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js index ac4495cead8..3491afc0b80 100644 --- a/scripts/markdown/check-markdown.js +++ b/scripts/markdown/check-markdown.js @@ -124,8 +124,8 @@ function checkMarkdownFiles(folderPath, validateFunction, relativePath = '') { const errors = validateFunction(frontmatter); if (errors) { - console.error(`Errors in file ${relativeFilePath}:`); - errors.forEach(error => console.log(` - ${error}`)); + console.log(`Errors in file ${relativeFilePath}:`); + errors.forEach(error => console.log(`${error}\n`)); } } }); From 3fad1fadb481338e3a6a584cdd31e568bb987de0 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:50:07 +0000 Subject: [PATCH 12/17] update output --- .github/workflows/if-nodejs-pr-testing.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index c7af64fda9a..6bdab601155 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -80,8 +80,11 @@ jobs: name: Run markdown checks id: markdown_check run: | - ERRORS=$(npm run test:md) - echo "markdown_output=$ERRORS" >> $GITHUB_OUTPUT + ERRORS="$(npm run test:md)" + echo "markdown_output<> "$GITHUB_OUTPUT" # Post a comment using sticky-pull-request-comment - name: Comment on PR with markdown issues From 6b881a853dc4f4c87dfbe8f9ac9967e608dede63 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:53:46 +0000 Subject: [PATCH 13/17] update output --- .github/workflows/if-nodejs-pr-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index 6bdab601155..bd341de397e 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -82,7 +82,7 @@ jobs: run: | ERRORS="$(npm run test:md)" echo "markdown_output<> "$GITHUB_OUTPUT" From c676e3d56425fa2b21d509507cfb7322e5d856e8 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 16:59:49 +0000 Subject: [PATCH 14/17] update output --- .github/workflows/if-nodejs-pr-testing.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml index bd341de397e..c8c3bec4d3c 100644 --- a/.github/workflows/if-nodejs-pr-testing.yml +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -80,11 +80,10 @@ jobs: name: Run markdown checks id: markdown_check run: | - ERRORS="$(npm run test:md)" - echo "markdown_output<> "$GITHUB_OUTPUT" + ERRORS=$(npm run test:md | sed -n '/Errors in file/,$p') + echo "markdown_output<> $GITHUB_OUTPUT + echo "$ERRORS" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT # Post a comment using sticky-pull-request-comment - name: Comment on PR with markdown issues From 1fb8b0ec272638d3f1bfb02a9df9b5413fdbce67 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 17:28:08 +0000 Subject: [PATCH 15/17] add coderabbit suggestion --- scripts/markdown/check-markdown.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js index 3491afc0b80..c2ff97d8255 100644 --- a/scripts/markdown/check-markdown.js +++ b/scripts/markdown/check-markdown.js @@ -34,7 +34,7 @@ function validateBlogs(frontmatter) { }); // Validate date format - if (frontmatter.date && isNaN(Date.parse(frontmatter.date))) { + if (frontmatter.date && Number.isNaN(Date.parse(frontmatter.date))) { errors.push(`Invalid date format: ${frontmatter.date}`); } @@ -126,6 +126,7 @@ function checkMarkdownFiles(folderPath, validateFunction, relativePath = '') { if (errors) { console.log(`Errors in file ${relativeFilePath}:`); errors.forEach(error => console.log(`${error}\n`)); + process.exitCode = 1; } } }); From 607c9e929af65a5c77160e4f1b88e43e476cb16c Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Fri, 18 Oct 2024 17:34:26 +0000 Subject: [PATCH 16/17] fix formatting --- scripts/markdown/check-markdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js index c2ff97d8255..77150477ab6 100644 --- a/scripts/markdown/check-markdown.js +++ b/scripts/markdown/check-markdown.js @@ -125,7 +125,7 @@ function checkMarkdownFiles(folderPath, validateFunction, relativePath = '') { const errors = validateFunction(frontmatter); if (errors) { console.log(`Errors in file ${relativeFilePath}:`); - errors.forEach(error => console.log(`${error}\n`)); + errors.forEach(error => console.log(` - ${error}`)); process.exitCode = 1; } } From 4cd9cfa4c18ad7599453123e64052b8886f2aa7e Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Sat, 19 Oct 2024 15:18:47 +0000 Subject: [PATCH 17/17] fix doc gray matter --- markdown/docs/migration/index.md | 1 + markdown/docs/migration/migrating-to-v3.md | 1 + scripts/markdown/check-markdown.js | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/markdown/docs/migration/index.md b/markdown/docs/migration/index.md index 195bcc35cf5..a8a57359ae2 100644 --- a/markdown/docs/migration/index.md +++ b/markdown/docs/migration/index.md @@ -1,5 +1,6 @@ --- title: "Overview" +weight: 1 --- Migration to a new major version is always difficult, and AsyncAPI is no exception, but we want to provide as smooth a transition as possible. diff --git a/markdown/docs/migration/migrating-to-v3.md b/markdown/docs/migration/migrating-to-v3.md index 85fa6bb47a7..00587645fee 100644 --- a/markdown/docs/migration/migrating-to-v3.md +++ b/markdown/docs/migration/migrating-to-v3.md @@ -1,5 +1,6 @@ --- title: "Migrating to v3" +weight: 2 --- diff --git a/scripts/markdown/check-markdown.js b/scripts/markdown/check-markdown.js index 77150477ab6..8979f7e0b4a 100644 --- a/scripts/markdown/check-markdown.js +++ b/scripts/markdown/check-markdown.js @@ -109,6 +109,11 @@ function checkMarkdownFiles(folderPath, validateFunction, relativePath = '') { const filePath = path.join(folderPath, file); const relativeFilePath = path.join(relativePath, file); + // Skip the folder 'docs/reference/specification' + if (relativeFilePath.includes('reference/specification')) { + return; + } + fs.stat(filePath, (err, stats) => { if (err) { console.error('Error reading file stats:', err);