From 7728943fbddcfa6da517f50f9faeded0a9b62ce4 Mon Sep 17 00:00:00 2001 From: Adam Dunn Date: Wed, 21 Feb 2024 10:19:50 -0700 Subject: [PATCH 1/3] updates to the link fixers --- .github/workflows/publish-site-sandbox.yml | 3 ++- scripts/api-broken-link-fixer.js | 6 +++++- scripts/meadow-foundation-broken-link-fixer.js | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-site-sandbox.yml b/.github/workflows/publish-site-sandbox.yml index 074ce17f8..c23d10150 100644 --- a/.github/workflows/publish-site-sandbox.yml +++ b/.github/workflows/publish-site-sandbox.yml @@ -180,7 +180,8 @@ jobs: - name: Fix Meadow.Foundation periphs broken links working-directory: ./src run: | - node ./scripts/meadow-foundation-broken-link-fixer.js + node ./scripts/meadow-foundation-broken-link-fixer.js && + ./scripts/meadow-foundation-broken-link-fixer.js ./docs/api/Meadow.Foundation.FeatherWings/ #docusaurus build - name: Use Node.js diff --git a/scripts/api-broken-link-fixer.js b/scripts/api-broken-link-fixer.js index 68d9ea508..e328330d2 100644 --- a/scripts/api-broken-link-fixer.js +++ b/scripts/api-broken-link-fixer.js @@ -45,7 +45,11 @@ const replacePatternInFile = async (dir, file) => { result = data.replace(pattern2, (match, p1, p2) => { if (!p1.includes(p2)) return match; //We are only interested in the broken ones const baseClass = p1.replace(`.${p2}`, ""); - if (slug?.includes(baseClass)) return match; //can't go around breaking working links now... + const slugBaseClass = ((ss) => { + let parts = slug.split("/"); + return parts[parts.length-2]; + })(); + if (slugBaseClass === baseClass) return match; //can't go around breaking working links now... const newString = `[${p1}](../../${baseClass}/${p2})`; // console.log(newString); return newString; diff --git a/scripts/meadow-foundation-broken-link-fixer.js b/scripts/meadow-foundation-broken-link-fixer.js index f7ef9856b..a37cda8a0 100644 --- a/scripts/meadow-foundation-broken-link-fixer.js +++ b/scripts/meadow-foundation-broken-link-fixer.js @@ -28,7 +28,7 @@ fs.readdir(directoryPath, (err, files) => { const baseClass = p1.replace(`.${p2}`, ""); // if(p1.includes('Meadow.Foundation.Sensors.Atmospheric.Ccs811.MeasurementMode')) // console.log(p1, p2, baseClass); - const newString = `[${p1}](../${baseClass}/${p2})`; + const newString = (p1.includes(p2)) ? `[${p1}](../${baseClass}/${p2})` : `[${p1}](../${baseClass}/)`; console.log(newString); return newString; }); From 4377ecf2a31221d4f4d8592cc352ab0da34f08e7 Mon Sep 17 00:00:00 2001 From: Adam Dunn Date: Wed, 21 Feb 2024 10:31:34 -0700 Subject: [PATCH 2/3] again --- .github/workflows/publish-site-sandbox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-site-sandbox.yml b/.github/workflows/publish-site-sandbox.yml index c23d10150..6d0482574 100644 --- a/.github/workflows/publish-site-sandbox.yml +++ b/.github/workflows/publish-site-sandbox.yml @@ -181,7 +181,7 @@ jobs: working-directory: ./src run: | node ./scripts/meadow-foundation-broken-link-fixer.js && - ./scripts/meadow-foundation-broken-link-fixer.js ./docs/api/Meadow.Foundation.FeatherWings/ + node ./scripts/meadow-foundation-broken-link-fixer.js ./docs/api/Meadow.Foundation.FeatherWings/ #docusaurus build - name: Use Node.js From 8b3e40051ed5de23e5aea1e20fa9c1112b957380 Mon Sep 17 00:00:00 2001 From: Adam Dunn Date: Wed, 21 Feb 2024 17:05:11 -0700 Subject: [PATCH 3/3] try --- .github/workflows/publish-site-beta.yml | 2 +- .github/workflows/publish-site-prod.yml | 10 ++--- .github/workflows/publish-site-sandbox.yml | 12 +++--- scripts/api-broken-link-fixer.js | 46 +++++++++++++++++----- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.github/workflows/publish-site-beta.yml b/.github/workflows/publish-site-beta.yml index a19176895..883d7b072 100644 --- a/.github/workflows/publish-site-beta.yml +++ b/.github/workflows/publish-site-beta.yml @@ -198,7 +198,7 @@ jobs: - name: Fix api broken links working-directory: ./src run: | - node ./scripts/api-broken-link-fixer.js + node ./scripts/api-broken-link-fixer.js ./docs/api/ #docusaurus build - name: Use Node.js diff --git a/.github/workflows/publish-site-prod.yml b/.github/workflows/publish-site-prod.yml index fa970c94f..7236247d6 100644 --- a/.github/workflows/publish-site-prod.yml +++ b/.github/workflows/publish-site-prod.yml @@ -175,12 +175,12 @@ jobs: - name: Fix api broken links working-directory: ./src run: | - node ./scripts/api-broken-link-fixer.js + node ./scripts/api-broken-link-fixer.js ./docs/api/ - - name: Fix Meadow.Foundation periphs broken links - working-directory: ./src - run: | - node ./scripts/meadow-foundation-broken-link-fixer.js + # - name: Fix Meadow.Foundation periphs broken links + # working-directory: ./src + # run: | + # node ./scripts/meadow-foundation-broken-link-fixer.js #docusaurus build - name: Use Node.js diff --git a/.github/workflows/publish-site-sandbox.yml b/.github/workflows/publish-site-sandbox.yml index 6d0482574..150ddcb81 100644 --- a/.github/workflows/publish-site-sandbox.yml +++ b/.github/workflows/publish-site-sandbox.yml @@ -175,13 +175,13 @@ jobs: - name: Fix api broken links working-directory: ./src run: | - node ./scripts/api-broken-link-fixer.js + node ./scripts/api-broken-link-fixer.js ./docs/api/ - - name: Fix Meadow.Foundation periphs broken links - working-directory: ./src - run: | - node ./scripts/meadow-foundation-broken-link-fixer.js && - node ./scripts/meadow-foundation-broken-link-fixer.js ./docs/api/Meadow.Foundation.FeatherWings/ + # - name: Fix Meadow.Foundation periphs broken links + # working-directory: ./src + # run: | + # node ./scripts/meadow-foundation-broken-link-fixer.js && + # node ./scripts/meadow-foundation-broken-link-fixer.js ./docs/api/Meadow.Foundation.FeatherWings/ #docusaurus build - name: Use Node.js diff --git a/scripts/api-broken-link-fixer.js b/scripts/api-broken-link-fixer.js index e328330d2..8fffcac8b 100644 --- a/scripts/api-broken-link-fixer.js +++ b/scripts/api-broken-link-fixer.js @@ -3,7 +3,7 @@ const { Dirent } = require("fs"); const path = require("path"); // Get the starting directory from command line arguments -const startDir = process.argv[2] ? process.argv[2] : "./docs/api/"; +const startDir = process.argv[2] ? process.argv[2] : "./api/"; // Function to replace the specified pattern in file content const replacePatternInFile = async (dir, file) => { @@ -40,18 +40,43 @@ const replacePatternInFile = async (dir, file) => { const pattern2 = /(?:\[(.*)\]\(..\/(.*)\))/g; const slugPattern = /slug: (.*)/; const slugMatches = data.match(slugPattern); - const slug = slugMatches ? slugMatches[0] : null; + const slug = slugMatches ? slugMatches[1] : null; // Replacement logic adjusted for the specific regex result = data.replace(pattern2, (match, p1, p2) => { - if (!p1.includes(p2)) return match; //We are only interested in the broken ones + let newString = match; const baseClass = p1.replace(`.${p2}`, ""); - const slugBaseClass = ((ss) => { + const { slugBaseClass, slugBasePath } = ((ss) => { let parts = slug.split("/"); - return parts[parts.length-2]; + const slugBaseClass = parts[parts.length - 2]; + let slugBasePath = parts.join("/").replace(parts[parts.length - 1], ""); + slugBasePath = slugBasePath.slice(0, -1); + return { + slugBaseClass, + slugBasePath, + }; })(); - if (slugBaseClass === baseClass) return match; //can't go around breaking working links now... - const newString = `[${p1}](../../${baseClass}/${p2})`; - // console.log(newString); + + filePath; + if (slugBaseClass === baseClass) { + newString = `[${p1}](${slugBasePath}/${p2})`; + } else { + if (!p1.includes(p2)) { + const linkBaseClassArr = baseClass.split("."); + linkBaseClassArr.pop(); + const linkBaseClass = linkBaseClassArr.join("."); + if (linkBaseClass === slugBaseClass) { + newString = `[${p1}](${slugBasePath}/${p2})`; + } else { + newString = `[${p1}](${slugBasePath}/${linkBaseClass}/${p2})`; + } + } else { + let libParts = baseClass.split("."); + libParts.pop(); + let lib = libParts.join("."); + newString = `[${p1}](/docs/api/${lib}/${baseClass}/${p2})`; + } + } + return newString; }); @@ -67,7 +92,10 @@ const replacePatternInFile = async (dir, file) => { let data = await fs.readFile(filePath, "utf8"); const pattern3 = /(?:\[View Source\]\((.* .*)\))/g; // Replacement logic adjusted for the specific regex - result = data.replace(pattern3, (match, p1) => `[View Source](${p1.replace(" ", "%20")})`); + result = data.replace( + pattern3, + (match, p1) => `[View Source](${p1.replace(" ", "%20")})` + ); await fs.writeFile(filePath, result, "utf8"); console.log(`File updated: ${filePath}`);