From be382e516e9f0e4c46b7015c18e6d4e232ae6be4 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 28 Jun 2022 03:36:12 +0530 Subject: Modifying Readme before commit --- hooks/pre-commit.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'hooks/pre-commit.js') diff --git a/hooks/pre-commit.js b/hooks/pre-commit.js index c1b2cca0..c4d3ff7c 100644 --- a/hooks/pre-commit.js +++ b/hooks/pre-commit.js @@ -5,7 +5,12 @@ const readme = fs.readFileSync("README.md", "utf8"); // Find the line which starts with "![Screenshot]" const screenshotLine = readme.split("\n").find(line => line.startsWith("![Screenshot]")); -screenshotLine.replace("![Screenshot]", `![Screenshot](https://api.thatcomputerscientist.com/screenshot?random=${Math.random()})`); -// Write the new line to the readme file -fs.writeFileSync("README.md", readme); +// Replace the line with the new screenshot +const newScreenshotLine = `![Screenshot](https://api.thatcomputerscientist.com/screenshot?random=${Math.random()})`; +const newReadme = readme.replace(screenshotLine, newScreenshotLine); + +// Write the new readme file +fs.writeFileSync("README.md", newReadme); + + -- cgit v1.2.3