Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add README.md
git add .
git diff --quiet && git diff --staged --quiet || (git commit -m "Update README with table of contents" && git push)
working-directory: ${{ github.workspace }}
12 changes: 10 additions & 2 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import fetch from "node-fetch";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const toc = async () => {
// Fetch from the GitHubAPI
Expand Down Expand Up @@ -45,8 +50,11 @@ const toc = async () => {
}
solutionsTable += "<!-- SOLUTIONS TABLE END -->";

// Use path.join to create the correct path to README.md
const readmePath = path.join(__dirname, "..", "README.md");

// Read the existing README content
let readmeContent = fs.readFileSync("README.md", "utf8");
let readmeContent = fs.readFileSync(readmePath, "utf8");

// Checking whether the solutions table already exists
if (readmeContent.includes("<!-- SOLUTIONS TABLE BEGIN -->")) {
Expand All @@ -69,7 +77,7 @@ const toc = async () => {
}

// Write the updated content back to README.md
fs.writeFileSync("README.md", readmeContent);
fs.writeFileSync(readmePath, readmeContent);
console.log("README.md has been updated with the solutions table!");
};

Expand Down