Skip to content

Commit 4c93831

Browse files
Merge pull request #2 from yashksaini-coder/jekyll-table
Fix README.md File read error
2 parents 241cda7 + 277b6a6 commit 4c93831

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.github/workflows/readme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
run: |
3333
git config --global user.email "actions@github.com"
3434
git config --global user.name "GitHub Actions"
35-
git add README.md
35+
git add .
3636
git diff --quiet && git diff --staged --quiet || (git commit -m "Update README with table of contents" && git push)
3737
working-directory: ${{ github.workspace }}

scripts/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import fetch from "node-fetch";
22
import fs from "fs";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
38

49
const toc = async () => {
510
// Fetch from the GitHubAPI
@@ -45,8 +50,11 @@ const toc = async () => {
4550
}
4651
solutionsTable += "<!-- SOLUTIONS TABLE END -->";
4752

53+
// Use path.join to create the correct path to README.md
54+
const readmePath = path.join(__dirname, "..", "README.md");
55+
4856
// Read the existing README content
49-
let readmeContent = fs.readFileSync("README.md", "utf8");
57+
let readmeContent = fs.readFileSync(readmePath, "utf8");
5058

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

7179
// Write the updated content back to README.md
72-
fs.writeFileSync("README.md", readmeContent);
80+
fs.writeFileSync(readmePath, readmeContent);
7381
console.log("README.md has been updated with the solutions table!");
7482
};
7583

0 commit comments

Comments
 (0)